INISettingsInterface: Fix saving/loading with Unicode paths

This commit is contained in:
Connor McLaughlin 2020-08-09 04:40:15 +10:00
parent 5b9db71b87
commit ac42510780
2 changed files with 21 additions and 2 deletions

View file

@ -1,11 +1,19 @@
#include "ini_settings_interface.h"
#include "common/file_system.h"
#include "common/log.h"
#include <algorithm>
Log_SetChannel(INISettingsInterface);
INISettingsInterface::INISettingsInterface(std::string filename) : m_filename(std::move(filename)), m_ini(true, true)
{
SI_Error err = m_ini.LoadFile(m_filename.c_str());
SI_Error err = SI_FAIL;
std::FILE* fp = FileSystem::OpenCFile(m_filename.c_str(), "rb");
if (fp)
{
err = m_ini.LoadFile(fp);
std::fclose(fp);
}
if (err != SI_OK)
Log_WarningPrintf("Settings could not be loaded from '%s', defaults will be used.", m_filename.c_str());
}
@ -18,7 +26,14 @@ INISettingsInterface::~INISettingsInterface()
bool INISettingsInterface::Save()
{
SI_Error err = m_ini.SaveFile(m_filename.c_str(), false);
SI_Error err = SI_FAIL;
std::FILE* fp = FileSystem::OpenCFile(m_filename.c_str(), "wb");
if (fp)
{
err = m_ini.SaveFile(fp, false);
std::fclose(fp);
}
if (err != SI_OK)
{
Log_WarningPrintf("Failed to save settings to '%s'.", m_filename.c_str());

View file

@ -1,6 +1,10 @@
#pragma once
#include "core/settings.h"
// being a pain here...
#ifdef WIN32
#include "common/windows_headers.h"
#endif
#include "SimpleIni.h"
class INISettingsInterface : public SettingsInterface