From 55db1811c7d75d45545bdb7a841ccddef0e17834 Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Mon, 22 Nov 2021 22:44:07 +0000 Subject: [PATCH] Chess: Port to LibMain Simplified two pledge() and five unveil() by using TRY(). --- Userland/Games/Chess/CMakeLists.txt | 2 +- Userland/Games/Chess/main.cpp | 46 +++++++---------------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/Userland/Games/Chess/CMakeLists.txt b/Userland/Games/Chess/CMakeLists.txt index 4d752a1a6df..218ebdd8bf9 100644 --- a/Userland/Games/Chess/CMakeLists.txt +++ b/Userland/Games/Chess/CMakeLists.txt @@ -13,4 +13,4 @@ set(SOURCES ) serenity_app(Chess ICON app-chess) -target_link_libraries(Chess LibChess LibConfig LibGUI LibCore) +target_link_libraries(Chess LibChess LibConfig LibGUI LibCore LibMain) diff --git a/Userland/Games/Chess/main.cpp b/Userland/Games/Chess/main.cpp index 4cce4cb6e70..4155679b232 100644 --- a/Userland/Games/Chess/main.cpp +++ b/Userland/Games/Chess/main.cpp @@ -16,53 +16,29 @@ #include #include #include -#include +#include +#include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec unix", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec unix", nullptr)); - auto app = GUI::Application::construct(argc, argv); + auto app = GUI::Application::construct(arguments.argc, arguments.argv); Config::pledge_domains("Chess"); - if (pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec", nullptr)); auto app_icon = GUI::Icon::default_icon("app-chess"); auto window = GUI::Window::construct(); auto& widget = window->set_main_widget(); - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil("/bin/ChessEngine", "x") < 0) { - perror("unveil"); - return 1; - } - - if (unveil("/etc/passwd", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(Core::StandardPaths::home_directory().characters(), "wcbr") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } + TRY(System::unveil("/res", "r")); + TRY(System::unveil("/bin/ChessEngine", "x")); + TRY(System::unveil("/etc/passwd", "r")); + TRY(System::unveil(Core::StandardPaths::home_directory().characters(), "wcbr")); + TRY(System::unveil(nullptr, nullptr)); auto size = Config::read_i32("Chess", "Display", "size", 512); window->set_title("Chess");