diff --git a/Core/Config.cpp b/Core/Config.cpp index d3027f4984..0e6f7576e1 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1273,7 +1273,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { // sadly it won't benefit from all the "version conversion" going on up-above // but these configs shouldn't contain older versions anyhow if (gameSpecific_) { - LoadGameConfig(gameId_, gameIdTitle_); + LoadGameConfig(gameId_); } PostLoadCleanup(); @@ -1287,13 +1287,12 @@ bool Config::Save(const char *saveReason) { // TODO: Should we allow saving config if started from a different directory? // How do we tell? WARN_LOG(Log::Loader, "Not saving config - secondary instances don't."); - // Don't want to retry or something. return true; } if (!iniFilename_.empty() && g_Config.bSaveSettings) { - SaveGameConfig(gameId_, gameIdTitle_); + SaveGameConfig(gameId_, ""); // we don't pass a title, it was stored in the ini the first time. PreSaveCleanup(); @@ -1479,7 +1478,7 @@ void Config::SetSearchPath(const Path &searchPath) { searchPath_ = searchPath; } -const Path Config::FindConfigFile(const std::string &baseFilename, bool *exists) { +Path Config::FindConfigFile(std::string_view baseFilename, bool *exists) const { // Don't search for an absolute path. if (baseFilename.size() > 1 && baseFilename[0] == '/') { Path path(baseFilename); @@ -1487,6 +1486,7 @@ const Path Config::FindConfigFile(const std::string &baseFilename, bool *exists) return path; } #ifdef _WIN32 + // Handle paths starting with a drive letter. if (baseFilename.size() > 3 && baseFilename[1] == ':' && (baseFilename[2] == '/' || baseFilename[2] == '\\')) { Path path(baseFilename); *exists = File::Exists(path); @@ -1536,7 +1536,7 @@ void Config::RestoreDefaults(RestoreSettingsBits whatToRestore, bool log) { bool Config::HasGameConfig(std::string_view gameId) { bool exists = false; - Path fullIniFilePath = GetGameConfigFile(gameId, &exists); + Path fullIniFilePath = GetGameConfigFilePath(gameId, &exists); return exists; } @@ -1546,13 +1546,12 @@ void Config::ChangeGameSpecific(const std::string &pGameId, std::string_view tit } gameId_ = pGameId; - gameIdTitle_ = title; gameSpecific_ = !pGameId.empty(); } bool Config::CreateGameConfig(std::string_view gameId) { bool exists; - Path fullIniFilePath = GetGameConfigFile(gameId, &exists); + Path fullIniFilePath = GetGameConfigFilePath(gameId, &exists); if (exists) { INFO_LOG(Log::System, "Game config already exists"); @@ -1565,7 +1564,7 @@ bool Config::CreateGameConfig(std::string_view gameId) { bool Config::DeleteGameConfig(std::string_view gameId) { bool exists = false; - Path fullIniFilePath = Path(GetGameConfigFile(gameId, &exists)); + Path fullIniFilePath = Path(GetGameConfigFilePath(gameId, &exists)); if (exists) { if (System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN)) { @@ -1577,7 +1576,7 @@ bool Config::DeleteGameConfig(std::string_view gameId) { return true; } -Path Config::GetGameConfigFile(std::string_view gameId, bool *exists) { +Path Config::GetGameConfigFilePath(std::string_view gameId, bool *exists) { std::string_view ppssppIniFilename = IsVREnabled() ? "_ppssppvr.ini" : "_ppsspp.ini"; std::string iniFileName = join(gameId, ppssppIniFilename); Path iniFileNameFull = FindConfigFile(iniFileName, exists); @@ -1590,12 +1589,17 @@ bool Config::SaveGameConfig(const std::string &gameId, std::string_view titleFor } bool exists; - Path fullIniFilePath = GetGameConfigFile(gameId, &exists); + Path fullIniFilePath = GetGameConfigFilePath(gameId, &exists); IniFile iniFile; + // Just like regular configs, we should load and save, in order to preserve things like comments. + iniFile.Load(fullIniFilePath); + Section *top = iniFile.GetOrCreateSection(""); - top->AddComment(StringFromFormat("Game config for %s - %.*s", gameId.c_str(), STR_VIEW(titleForComment))); + if (top->Lines().empty() && !titleForComment.empty()) { + top->AddComment(StringFromFormat("Game config for %s - %.*s", gameId.c_str(), STR_VIEW(titleForComment))); + } PreSaveCleanup(); @@ -1628,15 +1632,17 @@ bool Config::SaveGameConfig(const std::string &gameId, std::string_view titleFor return true; } -bool Config::LoadGameConfig(const std::string &gameId, std::string_view title) { +bool Config::LoadGameConfig(const std::string &gameId) { bool exists; - Path iniFileNameFull = GetGameConfigFile(gameId, &exists); + Path iniFileNameFull = GetGameConfigFilePath(gameId, &exists); if (!exists) { DEBUG_LOG(Log::Loader, "No game-specific settings found in %s. Using global defaults.", iniFileNameFull.c_str()); return false; } - ChangeGameSpecific(gameId, title); + _dbg_assert_(!gameId.empty()); + + ChangeGameSpecific(gameId); IniFile iniFile; iniFile.Load(iniFileNameFull); @@ -1684,7 +1690,6 @@ void Config::UnloadGameConfig() { } gameId_.clear(); - gameIdTitle_.clear(); gameSpecific_ = false; // Reload all settings from the main ini file. diff --git a/Core/Config.h b/Core/Config.h index 6781bcd33d..3f7d565fcb 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -627,15 +627,16 @@ public: // Note: This doesn't switch to the config, just creates it. bool CreateGameConfig(std::string_view gameId); bool DeleteGameConfig(std::string_view gameId); - bool LoadGameConfig(const std::string &game_id, std::string_view title); - bool SaveGameConfig(const std::string &pGameId, std::string_view title); + bool LoadGameConfig(const std::string &gameId); + bool SaveGameConfig(const std::string &pGameId, std::string_view titleForComment); void UnloadGameConfig(); - Path GetGameConfigFile(std::string_view gameId, bool *exists); + + Path GetGameConfigFilePath(std::string_view gameId, bool *exists); bool HasGameConfig(std::string_view gameId); bool IsGameSpecific() const { return gameSpecific_; } void SetSearchPath(const Path &path); - const Path FindConfigFile(const std::string &baseFilename, bool *exists); + Path FindConfigFile(std::string_view baseFilename, bool *exists) const; void UpdateIniLocation(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr); @@ -674,7 +675,6 @@ private: bool gameSpecific_ = false; std::string gameId_; - std::string gameIdTitle_; PlayTimeTracker playTimeTracker_; Path iniFilename_; diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 6f21cf087c..4990fa9a8e 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -262,7 +262,7 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) { } // If there's a game-specific config, load it. - g_Config.LoadGameConfig(id, g_paramSFO.GetValueString("TITLE")); + g_Config.LoadGameConfig(id); System_PostUIMessage(UIMessage::CONFIG_LOADED); INFO_LOG(Log::Loader, "Loading %s...", bootpath.c_str()); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 1a0d87ac84..aa49f7957d 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -209,7 +209,7 @@ void GameSettingsScreen::PreCreateViews() { if (editThenRestore_) { std::shared_ptr info = g_gameInfoCache->GetInfo(nullptr, gamePath_, GameInfoFlags::PARAM_SFO); - g_Config.LoadGameConfig(gameID_, info->GetTitle()); + g_Config.LoadGameConfig(gameID_); } iAlternateSpeedPercent1_ = g_Config.iFpsLimit1 < 0 ? -1 : (g_Config.iFpsLimit1 * 100) / 60;