Save config

This commit is contained in:
camdenorrb 2024-12-14 20:14:43 -06:00
parent 6c19245ba7
commit 786f9e58be
2 changed files with 12 additions and 1 deletions

View file

@ -6,6 +6,7 @@
#include <algorithm>
#include <cstddef>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <string_view>
@ -317,12 +318,22 @@ bool IniFile::Load(const std::string& filename, bool keep_current_data)
bool IniFile::Save(const std::string& filename)
{
// Create parent directories if they don't exist
std::filesystem::path path(filename);
std::filesystem::path parentPath = path.parent_path();
if (!exists(parentPath) && !create_directory(parentPath)) {
std::cerr << "Failed to create directory: " << parentPath << std::endl;
}
std::ofstream out;
std::string temp = File::GetTempFilenameForAtomicWrite(filename);
File::OpenFStream(out, temp, std::ios::out);
if (out.fail())
{
std::cerr << "Failed to open temporary file for writing: " << temp << std::endl;
return false;
}

View file

@ -71,7 +71,7 @@ SConfig::SConfig()
// Check if config exists before saving
if (!File::Exists(File::GetUserPath(F_DOLPHINCONFIG_IDX))) {
Config::Save();
SaveSettings();
}
}