Skip to content
API Documentation
BastionGuard™
SettingsStore.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#pragma once
22#include <string>
23#include <vector>
24#include <mutex>
25#include <nlohmann/json.hpp>
26
28public:
29 static void init();
30 static void reload();
31 static bool flush();
32 static bool reset_to_defaults();
33 static bool get_secure_payments_enabled();
34 static void set_secure_payments_enabled(bool enabled);
35
36 // ── Lingua UI ─────────────────────────────────────────────────────────────
37 static std::string get_language();
38 static void set_language(const std::string& lang);
39 static void apply_language();
40
41 // Accesso generico alle impostazioni — usato anche da altri binari
42 static std::string get_string(const std::string& dotted_key, const std::string& fallback_default);
43 static void set_string(const std::string& dotted_key, const std::string& value);
44 static void ensure_payments_json_exists();
45 static std::vector<std::string> get_payment_domains();
46 static bool save_payment_domains_user(const std::vector<std::string>& domains);
48
49private:
50 static std::string settings_file_path();
51 static nlohmann::json defaults();
52
53 static void ensure_loaded_locked();
54 static bool load_from_disk_locked();
55 static bool write_to_disk_locked(const nlohmann::json& j);
56
57 static nlohmann::json* get_or_create_node_locked(nlohmann::json& root, const std::string& dotted_key);
58 static const nlohmann::json* get_node_locked(const nlohmann::json& root, const std::string& dotted_key);
59
60 static bool get_bool(const std::string& dotted_key, bool fallback_default);
61 static void set_bool(const std::string& dotted_key, bool value);
62
63 static int get_int(const std::string& dotted_key, int fallback_default);
64 static void set_int(const std::string& dotted_key, int value);
65
66 static std::string user_payments_path();
67 static std::string system_payments_path();
68 static nlohmann::json default_payments_seed();
69
70 static bool read_json_file(const std::string& path, nlohmann::json& out);
71 static bool write_json_atomic(const std::string& path, const nlohmann::json& j);
72
73private:
74 static std::mutex mtx_;
75 static bool loaded_;
76 static nlohmann::json cache_;
77};
static std::string user_payments_path()
static void ensure_loaded_locked()
static void init()
static std::string get_string(const std::string &dotted_key, const std::string &fallback_default)
static nlohmann::json cache_
static bool write_to_disk_locked(const nlohmann::json &j)
static void set_language(const std::string &lang)
static void set_secure_payments_enabled(bool enabled)
static nlohmann::json default_payments_seed()
static std::string settings_file_path()
static bool get_secure_payments_enabled()
static bool save_payment_domains_user(const std::vector< std::string > &domains)
static std::mutex mtx_
static nlohmann::json defaults()
static bool get_bool(const std::string &dotted_key, bool fallback_default)
static void ensure_payments_json_exists()
static bool flush()
static nlohmann::json * get_or_create_node_locked(nlohmann::json &root, const std::string &dotted_key)
static bool loaded_
static bool reset_to_defaults()
static const nlohmann::json * get_node_locked(const nlohmann::json &root, const std::string &dotted_key)
static std::vector< std::string > get_payment_domains()
static void apply_language()
static void reload()
static void set_int(const std::string &dotted_key, int value)
static std::string get_language()
static bool read_json_file(const std::string &path, nlohmann::json &out)
static void set_bool(const std::string &dotted_key, bool value)
static void set_string(const std::string &dotted_key, const std::string &value)
static std::string system_payments_path()
static int get_int(const std::string &dotted_key, int fallback_default)
static bool reset_payment_domains_from_system()
static bool write_json_atomic(const std::string &path, const nlohmann::json &j)
static bool load_from_disk_locked()