1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:38:10 +00:00

LibCore: Add a CConfigFile class, a simple INI file parser.

You open the configuration for an app like so:

    auto config = CConfigFile::get_for_app("MyApp");

This will then open ~/MyApp.ini and parse it for you.
Immediately start using it in Minesweeper to load the field size and mine
count from a config file.
This commit is contained in:
Andreas Kling 2019-04-15 02:22:08 +02:00
parent 37c27e2e39
commit bc5148354f
5 changed files with 269 additions and 3 deletions

View file

@ -2,6 +2,7 @@
#include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h>
#include <AK/HashTable.h>
#include <LibCore/CConfigFile.h>
#include <unistd.h>
#include <time.h>
@ -30,6 +31,12 @@ Field::Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidg
, m_flag_label(flag_label)
, m_time_label(time_label)
{
auto config = CConfigFile::get_for_app("Minesweeper");
m_mine_count = config->read_num_entry("Game", "MineCount", 10);
m_rows = config->read_num_entry("Game", "Rows", 9);
m_columns = config->read_num_entry("Game", "Columns", 9);
m_timer.on_timeout = [this] {
m_time_label.set_text(String::format("%u", ++m_seconds_elapsed));
};