diff --git a/Common/Data/Text/I18n.cpp b/Common/Data/Text/I18n.cpp index 00771fe1196e..9c222da8b86c 100644 --- a/Common/Data/Text/I18n.cpp +++ b/Common/Data/Text/I18n.cpp @@ -67,13 +67,13 @@ std::shared_ptr I18NRepo::GetCategory(const char *category) { } } -std::string I18NRepo::GetIniPath(const std::string &languageID) const { - return "lang/" + languageID + ".ini"; +Path I18NRepo::GetIniPath(const std::string &languageID) const { + return Path("lang") / (languageID + ".ini"); } bool I18NRepo::IniExists(const std::string &languageID) const { File::FileInfo info; - if (!VFSGetFileInfo(GetIniPath(languageID).c_str(), &info)) + if (!VFSGetFileInfo(GetIniPath(languageID).ToString().c_str(), &info)) return false; if (!info.exists) return false; @@ -88,7 +88,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const Path &overridePath) if (!overridePath.empty()) { iniPath = overridePath / (languageID + ".ini"); } else { - iniPath = Path(GetIniPath(languageID)); + iniPath = GetIniPath(languageID); } if (!ini.LoadFromVFS(iniPath.ToString())) diff --git a/Common/Data/Text/I18n.h b/Common/Data/Text/I18n.h index 785bd2e53513..9939a1a7adc5 100644 --- a/Common/Data/Text/I18n.h +++ b/Common/Data/Text/I18n.h @@ -92,7 +92,7 @@ class I18NRepo { std::map> GetMissingKeys() const; private: - std::string GetIniPath(const std::string &languageID) const; + Path GetIniPath(const std::string &languageID) const; void Clear(); I18NCategory *LoadSection(const Section *section, const char *name); void SaveSection(IniFile &ini, Section *section, std::shared_ptr cat); diff --git a/Core/Compatibility.cpp b/Core/Compatibility.cpp index c4b287387d13..e7987caf92f2 100644 --- a/Core/Compatibility.cpp +++ b/Core/Compatibility.cpp @@ -47,7 +47,7 @@ void Compatibility::Load(const std::string &gameID) { IniFile compat2; // This one is user-editable. Need to load it after the system one. Path path = GetSysDirectory(DIRECTORY_SYSTEM) / "compat.ini"; - if (compat2.Load(path.ToString())) { + if (compat2.Load(path)) { CheckSettings(compat2, gameID); } } @@ -64,7 +64,7 @@ void Compatibility::Load(const std::string &gameID) { IniFile compat2; // This one is user-editable. Need to load it after the system one. Path path = GetSysDirectory(DIRECTORY_SYSTEM) / "compatvr.ini"; - if (compat2.Load(path.ToString())) { + if (compat2.Load(path)) { CheckVRSettings(compat2, gameID); } } diff --git a/Core/Config.cpp b/Core/Config.cpp index 820ab1d9290d..4971f9a8d628 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1351,7 +1351,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { bShowFrameProfiler = true; IniFile iniFile; - if (!iniFile.Load(iniFilename_.ToString())) { + if (!iniFile.Load(iniFilename_)) { ERROR_LOG(LOADER, "Failed to read '%s'. Setting config to default.", iniFilename_.c_str()); // Continue anyway to initialize the config. } @@ -1433,11 +1433,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { vPostShaderNames.push_back(it.second); } - // This caps the exponent 4 (so 16x.) - if (iAnisotropyLevel > 4) { - iAnisotropyLevel = 4; - } - // Check for an old dpad setting Section *control = iniFile.GetOrCreateSection("Control"); float f; @@ -1483,35 +1478,13 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { CleanRecent(); - // Set a default MAC, and correct if it's an old format. - if (sMACAddress.length() != 17) - sMACAddress = CreateRandMAC(); - - if (g_Config.bAutoFrameSkip && g_Config.bSkipBufferEffects) { - g_Config.bSkipBufferEffects = false; - } - - // Override ppsspp.ini JIT value to prevent crashing - if (DefaultCpuCore() != (int)CPUCore::JIT && g_Config.iCpuCore == (int)CPUCore::JIT) { - jitForcedOff = true; - g_Config.iCpuCore = (int)CPUCore::IR_JIT; - } - - // Automatically silence secondary instances. Could be an option I guess, but meh. - if (PPSSPP_ID > 1) { - g_Config.iGlobalVolume = 0; - } - - // Automatically switch away from deprecated setting value. - if (iTexScalingLevel <= 0) { - iTexScalingLevel = 1; - } - #if PPSSPP_PLATFORM(ANDROID) // The on path here is untested, since we don't expose it. g_Config.bVSync = false; #endif + PostLoadCleanup(false); + INFO_LOG(LOADER, "Config loaded: '%s'", iniFilename_.c_str()); } @@ -1525,13 +1498,11 @@ bool Config::Save(const char *saveReason) { return true; } - if (jitForcedOff) { - // if JIT has been forced off, we don't want to screw up the user's ppsspp.ini - g_Config.iCpuCore = (int)CPUCore::JIT; - } if (!iniFilename_.empty() && g_Config.bSaveSettings) { saveGameConfig(gameId_, gameIdTitle_); + PreSaveCleanup(false); + CleanRecent(); IniFile iniFile; if (!iniFile.Load(iniFilename_)) { @@ -1611,15 +1582,59 @@ bool Config::Save(const char *saveReason) { } INFO_LOG(LOADER, "Controller config saved: %s", controllerIniFilename_.c_str()); } + + PostSaveCleanup(false); } else { INFO_LOG(LOADER, "Not saving config"); } + + return true; +} + +void Config::PostLoadCleanup(bool gameSpecific) { + // Override ppsspp.ini JIT value to prevent crashing + if (DefaultCpuCore() != (int)CPUCore::JIT && g_Config.iCpuCore == (int)CPUCore::JIT) { + jitForcedOff = true; + g_Config.iCpuCore = (int)CPUCore::IR_JIT; + } + + // This caps the exponent 4 (so 16x.) + if (iAnisotropyLevel > 4) { + iAnisotropyLevel = 4; + } + + // Set a default MAC, and correct if it's an old format. + if (sMACAddress.length() != 17) + sMACAddress = CreateRandMAC(); + + if (g_Config.bAutoFrameSkip && g_Config.bSkipBufferEffects) { + g_Config.bSkipBufferEffects = false; + } + + // Automatically silence secondary instances. Could be an option I guess, but meh. + if (PPSSPP_ID > 1) { + g_Config.iGlobalVolume = 0; + } + + // Automatically switch away from deprecated setting value. + if (iTexScalingLevel <= 0) { + iTexScalingLevel = 1; + } +} + +void Config::PreSaveCleanup(bool gameSpecific) { + if (jitForcedOff) { + // if JIT has been forced off, we don't want to screw up the user's ppsspp.ini + g_Config.iCpuCore = (int)CPUCore::JIT; + } +} + +void Config::PostSaveCleanup(bool gameSpecific) { if (jitForcedOff) { // force JIT off again just in case Config::Save() is called without exiting PPSSPP if (g_Config.iCpuCore != (int)CPUCore::INTERPRETER) g_Config.iCpuCore = (int)CPUCore::IR_JIT; } - return true; } // Use for debugging the version check without messing with the server @@ -1858,6 +1873,8 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title Section *top = iniFile.GetOrCreateSection(""); top->AddComment(StringFromFormat("Game config for %s - %s", pGameId.c_str(), title.c_str())); + PreSaveCleanup(true); + IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { if (setting->perGame_) { setting->Set(section); @@ -1879,8 +1896,9 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title } KeyMap::SaveToIni(iniFile); - iniFile.Save(fullIniFilePath.ToString()); + iniFile.Save(fullIniFilePath); + PostSaveCleanup(true); return true; } @@ -1894,7 +1912,7 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title changeGameSpecific(pGameId, title); IniFile iniFile; - iniFile.Load(iniFileNameFull.ToString()); + iniFile.Load(iniFileNameFull); auto postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting")->ToMap(); mPostShaderSetting.clear(); @@ -1921,6 +1939,7 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title }); KeyMap::LoadFromIni(iniFile); + PostLoadCleanup(true); return true; } @@ -1929,7 +1948,7 @@ void Config::unloadGameConfig() { changeGameSpecific(); IniFile iniFile; - iniFile.Load(iniFilename_.ToString()); + iniFile.Load(iniFilename_); // Reload game specific settings back to standard. IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { @@ -1952,12 +1971,13 @@ void Config::unloadGameConfig() { } LoadStandardControllerIni(); + PostLoadCleanup(true); } } void Config::LoadStandardControllerIni() { IniFile controllerIniFile; - if (!controllerIniFile.Load(controllerIniFilename_.ToString())) { + if (!controllerIniFile.Load(controllerIniFilename_)) { ERROR_LOG(LOADER, "Failed to read %s. Setting controller config to default.", controllerIniFilename_.c_str()); KeyMap::RestoreDefault(); } else { diff --git a/Core/Config.h b/Core/Config.h index 60a148d4e34a..8f10a50893ac 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -575,6 +575,10 @@ struct Config { void LoadStandardControllerIni(); void LoadLangValuesMapping(); + void PostLoadCleanup(bool gameSpecific); + void PreSaveCleanup(bool gameSpecific); + void PostSaveCleanup(bool gameSpecific); + private: bool reload_ = false; std::string gameId_;