10#include "misc/Error.h"
13#define TOML11_PRESERVE_COMMENTS_BY_DEFAULT
14#include "toml11/toml.hpp"
20 enum class ConfigCategory {
108 [[nodiscard]]
static std::optional<Error>
109 removeFile(ConfigCategory category, std::string_view sFileName);
119 static void removeFile(std::filesystem::path pathToConfigFile);
137 [[nodiscard]] std::optional<Error>
loadFile(ConfigCategory category, std::string_view sFileName);
155 [[nodiscard]] std::optional<Error>
loadFile(std::filesystem::path pathToConfigFile);
196 template <
typename T>
197 T
getValue(std::string_view sSection, std::string_view sKey, T defaultValue)
const;
265 template <
typename T>
267 setValue(std::string_view sSection, std::string_view sKey, T value, std::string_view sComment =
"");
293 [[nodiscard]] std::optional<Error>
saveFile(ConfigCategory category, std::string_view sFileName);
310 [[nodiscard]] std::optional<Error>
311 saveFile(std::filesystem::path pathToConfigFile,
bool bEnableBackup);
333 static std::variant<std::filesystem::path, Error>
345 const std::set<std::string>& usedFileNames,
const std::string& sFileNamePrefix =
"");
357 template <
typename T>
359 if (sSection.empty()) {
360 return toml::find_or(
tomlData, sKey.data(), defaultValue);
362 return toml::find_or(
tomlData, sSection.data(), sKey.data(), defaultValue);
366 template <
typename T>
368 std::string_view sSection, std::string_view sKey, T value, std::string_view sComment) {
369 if (sSection.empty()) {
370 if (sComment.empty()) {
371 tomlData[sKey.data()] = toml::value(value);
373 tomlData[sKey.data()] = toml::value(value, {sComment.data()});
376 if (sComment.empty()) {
377 tomlData[sSection.data()][sKey.data()] = toml::value(value);
379 tomlData[sSection.data()][sKey.data()] = toml::value(value, {sComment.data()});
Definition: ConfigManager.h:28
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:348
std::filesystem::path filePath
Definition: ConfigManager.h:351
static std::string getConfigFormatExtension()
Definition: ConfigManager.cpp:11
static const char * sBackupFileExtension
Definition: ConfigManager.h:354
void setValue(std::string_view sSection, std::string_view sKey, T value, std::string_view sComment="")
Definition: ConfigManager.h:367
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:358
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