summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorThitat Auareesuksakul <thitat@fluxthitat.me>2021-08-26 19:44:51 +0700
committerAndreas Kling <kling@serenityos.org>2021-08-26 16:39:22 +0200
commitf119c5580a1d39f7c976090c73c5f8cb4cc0c2e4 (patch)
tree95685d0583d09163dcf5f97d10346ed918c0fb50 /Userland
parent573d14b7b57305d848e6d502ab92599d796e222a (diff)
downloadserenity-f119c5580a1d39f7c976090c73c5f8cb4cc0c2e4.zip
Solitaire: Use LibConfig instead of Core::ConfigFile
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/Solitaire/CMakeLists.txt2
-rw-r--r--Userland/Games/Solitaire/main.cpp25
2 files changed, 12 insertions, 15 deletions
diff --git a/Userland/Games/Solitaire/CMakeLists.txt b/Userland/Games/Solitaire/CMakeLists.txt
index 3727f7b80a..42eb2b3c7a 100644
--- a/Userland/Games/Solitaire/CMakeLists.txt
+++ b/Userland/Games/Solitaire/CMakeLists.txt
@@ -13,4 +13,4 @@ set(SOURCES
)
serenity_app(Solitaire ICON app-solitaire)
-target_link_libraries(Solitaire LibCards LibGUI LibGfx LibCore)
+target_link_libraries(Solitaire LibCards LibConfig LibGUI LibGfx LibCore)
diff --git a/Userland/Games/Solitaire/main.cpp b/Userland/Games/Solitaire/main.cpp
index 176c32cf87..af24991567 100644
--- a/Userland/Games/Solitaire/main.cpp
+++ b/Userland/Games/Solitaire/main.cpp
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2020, Till Mayer <till.mayer@web.de>
+ * Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Game.h"
#include <Games/Solitaire/SolitaireGML.h>
-#include <LibCore/ConfigFile.h>
+#include <LibConfig/Client.h>
#include <LibCore/Timer.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
@@ -24,7 +25,8 @@ int main(int argc, char** argv)
{
auto app = GUI::Application::construct(argc, argv);
auto app_icon = GUI::Icon::default_icon("app-solitaire");
- auto config = Core::ConfigFile::open_for_app("Solitaire", Core::ConfigFile::AllowWriting::Yes);
+
+ Config::pledge_domains("Solitaire");
if (pledge("stdio recvfd sendfd rpath wpath cpath", nullptr) < 0) {
perror("pledge");
@@ -36,7 +38,7 @@ int main(int argc, char** argv)
return 1;
}
- if (unveil(config->filename().characters(), "crw") < 0) {
+ if (unveil("/tmp/portal/config", "rw") < 0) {
perror("unveil");
return 1;
}
@@ -49,21 +51,19 @@ int main(int argc, char** argv)
auto window = GUI::Window::construct();
window->set_title("Solitaire");
- auto mode = static_cast<Solitaire::Mode>(config->read_num_entry("Settings", "Mode", static_cast<int>(Solitaire::Mode::SingleCardDraw)));
+ auto mode = static_cast<Solitaire::Mode>(Config::read_i32("Solitaire", "Settings", "Mode", static_cast<int>(Solitaire::Mode::SingleCardDraw)));
auto update_mode = [&](Solitaire::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("Solitaire", "Settings", "Mode", static_cast<int>(mode));
};
auto high_score = [&]() {
switch (mode) {
case Solitaire::Mode::SingleCardDraw:
- return static_cast<u32>(config->read_num_entry("HighScores", "SingleCardDraw", 0));
+ return static_cast<u32>(Config::read_i32("Solitaire", "HighScores", "SingleCardDraw", 0));
case Solitaire::Mode::ThreeCardDraw:
- return static_cast<u32>(config->read_num_entry("HighScores", "ThreeCardDraw", 0));
+ return static_cast<u32>(Config::read_i32("Solitaire", "HighScores", "ThreeCardDraw", 0));
default:
VERIFY_NOT_REACHED();
}
@@ -72,17 +72,14 @@ int main(int argc, char** argv)
auto update_high_score = [&](u32 new_high_score) {
switch (mode) {
case Solitaire::Mode::SingleCardDraw:
- config->write_num_entry("HighScores", "SingleCardDraw", static_cast<int>(new_high_score));
+ Config::write_i32("Solitaire", "HighScores", "SingleCardDraw", static_cast<int>(new_high_score));
break;
case Solitaire::Mode::ThreeCardDraw:
- config->write_num_entry("HighScores", "ThreeCardDraw", static_cast<int>(new_high_score));
+ Config::write_i32("Solitaire", "HighScores", "ThreeCardDraw", static_cast<int>(new_high_score));
break;
default:
VERIFY_NOT_REACHED();
}
-
- if (!config->sync())
- GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);
};
if (mode >= Solitaire::Mode::__Count)