config: create user directory if it doesn't exist

This commit is contained in:
Hyper 2024-10-21 22:24:33 +01:00
parent efaf8fb8c4
commit fae7591b53

View file

@ -1,6 +1,8 @@
void Config::Load() void Config::Load()
{ {
if (!std::filesystem::exists(GetConfigPath())) auto configPath = GetConfigPath();
if (!std::filesystem::exists(configPath))
{ {
Config::Save(); Config::Save();
return; return;
@ -8,7 +10,7 @@ void Config::Load()
try try
{ {
auto toml = toml::parse_file(GetConfigPath().string()); auto toml = toml::parse_file(configPath.string());
for (auto def : Definitions) for (auto def : Definitions)
def->ReadValue(toml); def->ReadValue(toml);
@ -21,6 +23,11 @@ void Config::Load()
void Config::Save() void Config::Save()
{ {
auto userPath = GetUserPath();
if (!std::filesystem::exists(userPath))
std::filesystem::create_directory(userPath);
std::string result; std::string result;
std::string section; std::string section;