From 85ae298b85c51aabf64782e3625edeeff5221997 Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Mon, 22 Nov 2021 23:46:18 +0000 Subject: [PATCH] FlappyBug: Port to LibMain Simplified two pledge() and two unveil() by using TRY(). --- Userland/Games/FlappyBug/CMakeLists.txt | 2 +- Userland/Games/FlappyBug/main.cpp | 28 +++++++------------------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/Userland/Games/FlappyBug/CMakeLists.txt b/Userland/Games/FlappyBug/CMakeLists.txt index 755e4dc3eb..596bb07fd1 100644 --- a/Userland/Games/FlappyBug/CMakeLists.txt +++ b/Userland/Games/FlappyBug/CMakeLists.txt @@ -10,4 +10,4 @@ set(SOURCES ) serenity_app(FlappyBug ICON app-flappybug) -target_link_libraries(FlappyBug LibGUI LibConfig) +target_link_libraries(FlappyBug LibGUI LibConfig LibMain) diff --git a/Userland/Games/FlappyBug/main.cpp b/Userland/Games/FlappyBug/main.cpp index 38bdeefc4f..55daae3185 100644 --- a/Userland/Games/FlappyBug/main.cpp +++ b/Userland/Games/FlappyBug/main.cpp @@ -12,33 +12,21 @@ #include #include #include -#include +#include +#include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio rpath recvfd sendfd unix", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(System::pledge("stdio rpath recvfd sendfd unix", nullptr)); - auto app = GUI::Application::construct(argc, argv); + auto app = GUI::Application::construct(arguments.argc, arguments.argv); Config::pledge_domains("FlappyBug"); - if (pledge("stdio rpath recvfd sendfd", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(System::pledge("stdio rpath recvfd sendfd", nullptr)); - if (unveil("/res", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } + TRY(System::unveil("/res", "r")); + TRY(System::unveil(nullptr, nullptr)); u32 high_score = Config::read_i32("FlappyBug", "Game", "HighScore", 0);