From 458471cc370fb13b52c2cd64e28d134dad691ef8 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Thu, 26 Aug 2021 20:19:41 -0400 Subject: [PATCH] Snake: Use LibConfig instead of Core::ConfigFile --- Userland/Games/Snake/CMakeLists.txt | 2 +- Userland/Games/Snake/SnakeGame.cpp | 9 ++++----- Userland/Games/Snake/main.cpp | 11 +++-------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Userland/Games/Snake/CMakeLists.txt b/Userland/Games/Snake/CMakeLists.txt index 6ccc58755b..6f343dc503 100644 --- a/Userland/Games/Snake/CMakeLists.txt +++ b/Userland/Games/Snake/CMakeLists.txt @@ -10,4 +10,4 @@ set(SOURCES ) serenity_app(Snake ICON app-snake) -target_link_libraries(Snake LibGUI) +target_link_libraries(Snake LibGUI LibConfig) diff --git a/Userland/Games/Snake/SnakeGame.cpp b/Userland/Games/Snake/SnakeGame.cpp index 3aec0c13d7..aa7c51b5c0 100644 --- a/Userland/Games/Snake/SnakeGame.cpp +++ b/Userland/Games/Snake/SnakeGame.cpp @@ -1,11 +1,12 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ #include "SnakeGame.h" -#include +#include #include #include #include @@ -23,8 +24,7 @@ SnakeGame::SnakeGame() srand(time(nullptr)); reset(); - auto config = Core::ConfigFile::open_for_app("Snake"); - m_high_score = config->read_num_entry("Snake", "HighScore", 0); + m_high_score = Config::read_i32("Snake", "Snake", "HighScore", 0); m_high_score_text = String::formatted("Best: {}", m_high_score); } @@ -131,8 +131,7 @@ void SnakeGame::timer_event(Core::TimerEvent&) m_high_score = m_score; m_high_score_text = String::formatted("Best: {}", m_high_score); update(high_score_rect()); - auto config = Core::ConfigFile::open_for_app("Snake", Core::ConfigFile::AllowWriting::Yes); - config->write_num_entry("Snake", "HighScore", m_high_score); + Config::write_i32("Snake", "Snake", "HighScore", m_high_score); } update(score_rect()); dirty_cells.append(m_fruit); diff --git a/Userland/Games/Snake/main.cpp b/Userland/Games/Snake/main.cpp index e4294cb261..fe6e2070c4 100644 --- a/Userland/Games/Snake/main.cpp +++ b/Userland/Games/Snake/main.cpp @@ -5,7 +5,7 @@ */ #include "SnakeGame.h" -#include +#include #include #include #include @@ -26,23 +26,18 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); + Config::pledge_domains("Snake"); + if (pledge("stdio rpath wpath cpath recvfd sendfd", nullptr) < 0) { perror("pledge"); return 1; } - auto config = Core::ConfigFile::open_for_app("Snake"); - if (unveil("/res", "r") < 0) { perror("unveil"); return 1; } - if (unveil(config->filename().characters(), "crw") < 0) { - perror("unveil"); - return 1; - } - if (unveil(nullptr, nullptr) < 0) { perror("unveil"); return 1;