diff options
author | Mustafa Quraish <mustafaq9@gmail.com> | 2021-08-26 20:28:21 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-27 12:45:50 +0200 |
commit | 998d3a98ecf2af77d42959b90c010496d4cd0627 (patch) | |
tree | f830337470dd0ec5d295a0c0524ef7c55e713dd0 | |
parent | 458471cc370fb13b52c2cd64e28d134dad691ef8 (diff) | |
download | serenity-998d3a98ecf2af77d42959b90c010496d4cd0627.zip |
Spider: Use LibConfig instead of Core::ConfigFile
There was a lot of error handling here previously when writing to
a config file failed, but this was removed since we have no way of
conveying a `Config::write` failure from the ConfigServer.
-rw-r--r-- | Userland/Games/Spider/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Games/Spider/main.cpp | 51 |
2 files changed, 17 insertions, 36 deletions
diff --git a/Userland/Games/Spider/CMakeLists.txt b/Userland/Games/Spider/CMakeLists.txt index 29a5fd9e81..d7fa9dfcce 100644 --- a/Userland/Games/Spider/CMakeLists.txt +++ b/Userland/Games/Spider/CMakeLists.txt @@ -13,4 +13,4 @@ set(SOURCES ) serenity_app(Spider ICON app-spider) -target_link_libraries(Spider LibCards LibGUI LibGfx LibCore) +target_link_libraries(Spider LibCards LibGUI LibGfx LibCore LibConfig) diff --git a/Userland/Games/Spider/main.cpp b/Userland/Games/Spider/main.cpp index 50e910af39..2cc37f4cac 100644 --- a/Userland/Games/Spider/main.cpp +++ b/Userland/Games/Spider/main.cpp @@ -1,12 +1,13 @@ /* * Copyright (c) 2021, Jamie Mansfield <jmansfield@cadixdev.org> + * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu> * * SPDX-License-Identifier: BSD-2-Clause */ #include "Game.h" #include <Games/Spider/SpiderGML.h> -#include <LibCore/ConfigFile.h> +#include <LibConfig/Client.h> #include <LibCore/Timer.h> #include <LibGUI/Action.h> #include <LibGUI/ActionGroup.h> @@ -39,7 +40,8 @@ int main(int argc, char** argv) { auto app = GUI::Application::construct(argc, argv); auto app_icon = GUI::Icon::default_icon("app-spider"); - auto config = Core::ConfigFile::open_for_app("Spider", Core::ConfigFile::AllowWriting::Yes); + + Config::pledge_domains("Spider"); if (pledge("stdio recvfd sendfd rpath wpath cpath", nullptr) < 0) { perror("pledge"); @@ -51,11 +53,6 @@ int main(int argc, char** argv) return 1; } - if (unveil(config->filename().characters(), "crw") < 0) { - perror("unveil"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { perror("unveil"); return 1; @@ -64,13 +61,11 @@ int main(int argc, char** argv) auto window = GUI::Window::construct(); window->set_title("Spider"); - auto mode = static_cast<Spider::Mode>(config->read_num_entry("Settings", "Mode", static_cast<int>(Spider::Mode::SingleSuit))); + auto mode = static_cast<Spider::Mode>(Config::read_i32("Spider", "Settings", "Mode", static_cast<int>(Spider::Mode::SingleSuit))); auto update_mode = [&](Spider::Mode new_mode) { mode = new_mode; - config->write_num_entry("Settings", "Mode", static_cast<int>(mode)); - if (!config->sync()) - GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); + Config::write_i32("Spider", "Settings", "Mode", static_cast<int>(mode)); }; auto mode_id = [&]() { @@ -84,54 +79,40 @@ int main(int argc, char** argv) } }; - auto statistic_display = static_cast<StatisticDisplay>(config->read_num_entry("Settings", "StatisticDisplay", static_cast<int>(StatisticDisplay::HighScore))); + auto statistic_display = static_cast<StatisticDisplay>(Config::read_i32("Spider", "Settings", "StatisticDisplay", static_cast<int>(StatisticDisplay::HighScore))); auto update_statistic_display = [&](StatisticDisplay new_statistic_display) { statistic_display = new_statistic_display; - config->write_num_entry("Settings", "StatisticDisplay", static_cast<int>(statistic_display)); - if (!config->sync()) - GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); + Config::write_i32("Spider", "Settings", "StatisticDisplay", static_cast<int>(statistic_display)); }; auto high_score = [&]() { - return static_cast<u32>(config->read_num_entry("HighScores", mode_id(), 0)); + return static_cast<u32>(Config::read_i32("Spider", "HighScores", mode_id(), 0)); }; auto update_high_score = [&](u32 new_high_score) { - config->write_num_entry("HighScores", mode_id(), static_cast<int>(new_high_score)); - - if (!config->sync()) - GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); + Config::write_i32("Spider", "HighScores", mode_id(), static_cast<int>(new_high_score)); }; auto best_time = [&]() { - return static_cast<u32>(config->read_num_entry("BestTimes", mode_id(), 0)); + return static_cast<u32>(Config::read_i32("Spider", "BestTimes", mode_id(), 0)); }; auto update_best_time = [&](u32 new_best_time) { - config->write_num_entry("BestTimes", mode_id(), static_cast<int>(new_best_time)); - - if (!config->sync()) - GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); + Config::write_i32("Spider", "BestTimes", mode_id(), static_cast<int>(new_best_time)); }; auto total_wins = [&]() { - return static_cast<u32>(config->read_num_entry("TotalWins", mode_id(), 0)); + return static_cast<u32>(Config::read_i32("Spider", "TotalWins", mode_id(), 0)); }; auto increment_total_wins = [&]() { - config->write_num_entry("TotalWins", mode_id(), static_cast<int>(total_wins() + 1)); - - if (!config->sync()) - GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); + Config::write_i32("Spider", "TotalWins", mode_id(), static_cast<int>(total_wins() + 1)); }; auto total_losses = [&]() { - return static_cast<u32>(config->read_num_entry("TotalLosses", mode_id(), 0)); + return static_cast<u32>(Config::read_i32("Spider", "TotalLosses", mode_id(), 0)); }; auto increment_total_losses = [&]() { - config->write_num_entry("TotalLosses", mode_id(), static_cast<int>(total_losses() + 1)); - - if (!config->sync()) - GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); + Config::write_i32("Spider", "TotalLosses", mode_id(), static_cast<int>(total_losses() + 1)); }; if (mode >= Spider::Mode::__Count) |