10#include "misc/Error.h"
13#include "toml11/single_include/toml.hpp"
19 enum class ConfigCategory {
107 [[nodiscard]]
static std::optional<Error>
108 removeFile(ConfigCategory category, std::string_view sFileName);
118 static void removeFile(std::filesystem::path pathToConfigFile);
136 [[nodiscard]] std::optional<Error>
loadFile(ConfigCategory category, std::string_view sFileName);
154 [[nodiscard]] std::optional<Error>
loadFile(std::filesystem::path pathToConfigFile);
195 template <
typename T>
196 T
getValue(std::string_view sSection, std::string_view sKey, T defaultValue)
const;
264 template <
typename T>
266 setValue(std::string_view sSection, std::string_view sKey, T value, std::string_view sComment =
"");
292 [[nodiscard]] std::optional<Error>
saveFile(ConfigCategory category, std::string_view sFileName);
309 [[nodiscard]] std::optional<Error>
310 saveFile(std::filesystem::path pathToConfigFile,
bool bEnableBackup);
332 static std::variant<std::filesystem::path, Error>
344 const std::set<std::string>& usedFileNames,
const std::string& sFileNamePrefix =
"");
356 template <
typename T>
358 if (sSection.empty()) {
359 return toml::find_or(
tomlData, sKey.data(), defaultValue);
361 return toml::find_or(
tomlData, sSection.data(), sKey.data(), defaultValue);
365 template <
typename T>
367 std::string_view sSection, std::string_view sKey, T value, std::string_view sComment) {
368 if (sSection.empty()) {
369 if (sComment.empty()) {
370 tomlData[sKey.data()] = toml::value(value);
372 tomlData[sKey.data()] = toml::value(value, {sComment.data()});
375 if (sComment.empty()) {
376 tomlData[sSection.data()][sKey.data()] = toml::value(value);
378 tomlData[sSection.data()][sKey.data()] = toml::value(value, {sComment.data()});
Definition: ConfigManager.h:27
static std::set< std::string > getAllFileNames(ConfigCategory category)
Definition: ConfigManager.cpp:15
static std::string getBackupFileExtension()
Definition: ConfigManager.cpp:13
static std::variant< std::filesystem::path, Error > constructFilePath(ConfigCategory category, std::string_view sFileName)
Definition: ConfigManager.cpp:283
std::filesystem::path getFilePath() const
Definition: ConfigManager.cpp:280
std::optional< Error > loadFile(ConfigCategory category, std::string_view sFileName)
Definition: ConfigManager.cpp:116
static std::filesystem::path getCategoryDirectory(ConfigCategory category)
Definition: ConfigManager.cpp:56
static std::string getFreeProgressProfileName()
Definition: ConfigManager.cpp:51
toml::value tomlData
Definition: ConfigManager.h:347
std::filesystem::path filePath
Definition: ConfigManager.h:350
static std::string getConfigFormatExtension()
Definition: ConfigManager.cpp:11
static const char * sBackupFileExtension
Definition: ConfigManager.h:353
void setValue(std::string_view sSection, std::string_view sKey, T value, std::string_view sComment="")
Definition: ConfigManager.h:366
std::vector< std::string > getAllSections()
Definition: ConfigManager.cpp:163
std::optional< Error > saveFile(ConfigCategory category, std::string_view sFileName)
Definition: ConfigManager.cpp:199
T getValue(std::string_view sSection, std::string_view sKey, T defaultValue) const
Definition: ConfigManager.h:357
static std::string generateFreeFileName(const std::set< std::string > &usedFileNames, const std::string &sFileNamePrefix="")
Definition: ConfigManager.cpp:318
static std::optional< Error > removeFile(ConfigCategory category, std::string_view sFileName)
Definition: ConfigManager.cpp:75
std::variant< std::vector< std::string >, Error > getAllKeysOfSection(std::string_view sSection) const
Definition: ConfigManager.cpp:177