summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/frontend_common/config.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp
index b3f4a54a4..cf149ec26 100644
--- a/src/frontend_common/config.cpp
+++ b/src/frontend_common/config.cpp
@@ -16,6 +16,8 @@
16 16
17#include <boost/algorithm/string/replace.hpp> 17#include <boost/algorithm/string/replace.hpp>
18 18
19#include "common/string_util.h"
20
19namespace FS = Common::FS; 21namespace FS = Common::FS;
20 22
21Config::Config(const ConfigType config_type) 23Config::Config(const ConfigType config_type)
@@ -56,16 +58,43 @@ void Config::Initialize(const std::optional<std::string> config_path) {
56} 58}
57 59
58void Config::WriteToIni() const { 60void Config::WriteToIni() const {
59 if (const SI_Error rc = config->SaveFile(config_loc.c_str(), false); rc < 0) { 61 FILE* fp = nullptr;
62#ifdef _WIN32
63 fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb");
64#else
65 fp = fopen(config_loc.c_str(), "wb");
66#endif
67
68 CSimpleIniA::FileWriter writer(fp);
69 const SI_Error rc = config->Save(writer, false);
70 if (rc < 0) {
60 LOG_ERROR(Frontend, "Config file could not be saved!"); 71 LOG_ERROR(Frontend, "Config file could not be saved!");
61 } 72 }
73 fclose(fp);
62} 74}
63 75
64void Config::SetUpIni() { 76void Config::SetUpIni() {
65 config = std::make_unique<CSimpleIniA>(); 77 config = std::make_unique<CSimpleIniA>();
66 config->SetUnicode(true); 78 config->SetUnicode(true);
67 config->SetSpaces(false); 79 config->SetSpaces(false);
68 config->LoadFile(config_loc.c_str()); 80
81 FILE* fp = nullptr;
82#ifdef _WIN32
83 _wfopen_s(&fp, Common::UTF8ToUTF16W(config_loc).data(), L"rb, ccs=UTF-8");
84 if (fp == nullptr) {
85 fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb, ccs=UTF-8");
86 }
87#else
88 fp = fopen(config_loc.c_str(), "rb");
89 if (fp == nullptr) {
90 fp = fopen(config_loc.c_str(), "wb");
91 }
92#endif
93
94 if (SI_Error rc = config->LoadFile(fp); rc < 0) {
95 LOG_ERROR(Frontend, "Config file could not be loaded!");
96 }
97 fclose(fp);
69} 98}
70 99
71bool Config::IsCustomConfig() const { 100bool Config::IsCustomConfig() const {