From 2a27dd5f8c21872079720269c3fe70f092a2fbc1 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Tue, 21 Nov 2023 23:34:31 +0100 Subject: [PATCH] early-access version 3986 --- README.md | 2 +- src/frontend_common/config.cpp | 45 +++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 43c124acf..2fd472ca1 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3985. +This is the source code for early-access 3986. ## Legal Notice diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp index b3f4a54a4..40a44ae12 100755 --- a/src/frontend_common/config.cpp +++ b/src/frontend_common/config.cpp @@ -16,6 +16,8 @@ #include +#include "common/string_util.h" + namespace FS = Common::FS; Config::Config(const ConfigType config_type) @@ -56,16 +58,43 @@ void Config::Initialize(const std::optional config_path) { } void Config::WriteToIni() const { - if (const SI_Error rc = config->SaveFile(config_loc.c_str(), false); rc < 0) { + FILE* fp = nullptr; +#ifdef _WIN32 + fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb"); +#else + fp = fopen(config_loc.c_str(), "wb"); +#endif + + CSimpleIniA::FileWriter writer(fp); + const SI_Error rc = config->Save(writer, false); + if (rc < 0) { LOG_ERROR(Frontend, "Config file could not be saved!"); } + fclose(fp); } void Config::SetUpIni() { config = std::make_unique(); config->SetUnicode(true); config->SetSpaces(false); - config->LoadFile(config_loc.c_str()); + + FILE* fp = nullptr; +#ifdef _WIN32 + _wfopen_s(&fp, Common::UTF8ToUTF16W(config_loc).data(), L"rb, ccs=UTF-8"); + if (fp == nullptr) { + fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb, ccs=UTF-8"); + } +#else + fp = fopen(config_loc.c_str(), "rb"); + if (fp == nullptr) { + fp = fopen(config_loc.c_str(), "wb"); + } +#endif + + if (SI_Error rc = config->LoadFile(fp); rc < 0) { + LOG_ERROR(Frontend, "Config file could not be loaded!"); + } + fclose(fp); } bool Config::IsCustomConfig() const { @@ -908,15 +937,19 @@ void Config::EndArray() { // You can't end a config array before starting one ASSERT(!array_stack.empty()); + // Set the array size to 0 if the array is ended without changing the index + int size = 0; + if (array_stack.back().index != 0) { + size = array_stack.back().size; + } + // Write out the size to config if (key_stack.size() == 1 && array_stack.back().name.empty()) { // Edge-case where the first array created doesn't have a name - config->SetValue(GetSection().c_str(), std::string("size").c_str(), - ToString(array_stack.back().size).c_str()); + config->SetValue(GetSection().c_str(), std::string("size").c_str(), ToString(size).c_str()); } else { const auto key = GetFullKey(std::string("size"), true); - config->SetValue(GetSection().c_str(), key.c_str(), - ToString(array_stack.back().size).c_str()); + config->SetValue(GetSection().c_str(), key.c_str(), ToString(size).c_str()); } array_stack.pop_back();