diff --git a/Core/Config.cpp b/Core/Config.cpp index a0d7e7107b..7f9c117eff 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1090,10 +1090,11 @@ void Config::Reload() { void Config::UpdateIniLocation(const char *iniFileName, const char *controllerIniFilename) { const bool useIniFilename = iniFileName != nullptr && strlen(iniFileName) > 0; const char *ppssppIniFilename = IsVREnabled() ? "ppssppvr.ini" : "ppsspp.ini"; - iniFilename_ = FindConfigFile(useIniFilename ? iniFileName : ppssppIniFilename); + bool exists; + iniFilename_ = FindConfigFile(useIniFilename ? iniFileName : ppssppIniFilename, &exists); const bool useControllerIniFilename = controllerIniFilename != nullptr && strlen(controllerIniFilename) > 0; const char *controlsIniFilename = IsVREnabled() ? "controlsvr.ini" : "controls.ini"; - controllerIniFilename_ = FindConfigFile(useControllerIniFilename ? controllerIniFilename : controlsIniFilename); + controllerIniFilename_ = FindConfigFile(useControllerIniFilename ? controllerIniFilename : controlsIniFilename, &exists); } bool Config::LoadAppendedConfig() { @@ -1660,22 +1661,27 @@ void Config::SetSearchPath(const Path &searchPath) { searchPath_ = searchPath; } -const Path Config::FindConfigFile(const std::string &baseFilename) { +const Path Config::FindConfigFile(const std::string &baseFilename, bool *exists) { // Don't search for an absolute path. if (baseFilename.size() > 1 && baseFilename[0] == '/') { - return Path(baseFilename); + Path path(baseFilename); + *exists = File::Exists(path); + return path; } #ifdef _WIN32 if (baseFilename.size() > 3 && baseFilename[1] == ':' && (baseFilename[2] == '/' || baseFilename[2] == '\\')) { - return Path(baseFilename); + Path path(baseFilename); + *exists = File::Exists(path); + return path; } #endif Path filename = searchPath_ / baseFilename; if (File::Exists(filename)) { + *exists = true; return filename; } - + *exists = false; // Make sure at least the directory it's supposed to be in exists. Path parent = filename.NavigateUp(); @@ -1711,8 +1717,9 @@ void Config::RestoreDefaults(RestoreSettingsBits whatToRestore) { } bool Config::hasGameConfig(const std::string &pGameId) { - Path fullIniFilePath = getGameConfigFile(pGameId); - return File::Exists(fullIniFilePath); + bool exists = false; + Path fullIniFilePath = getGameConfigFile(pGameId, &exists); + return exists; } void Config::changeGameSpecific(const std::string &pGameId, const std::string &title) { @@ -1724,9 +1731,11 @@ void Config::changeGameSpecific(const std::string &pGameId, const std::string &t } bool Config::createGameConfig(const std::string &pGameId) { - Path fullIniFilePath = getGameConfigFile(pGameId); + bool exists; + Path fullIniFilePath = getGameConfigFile(pGameId, &exists); - if (hasGameConfig(pGameId)) { + if (exists) { + INFO_LOG(Log::System, "Game config already exists"); return false; } @@ -1735,16 +1744,19 @@ bool Config::createGameConfig(const std::string &pGameId) { } bool Config::deleteGameConfig(const std::string& pGameId) { - Path fullIniFilePath = Path(getGameConfigFile(pGameId)); + bool exists; + Path fullIniFilePath = Path(getGameConfigFile(pGameId, &exists)); - File::Delete(fullIniFilePath); + if (exists) { + File::Delete(fullIniFilePath); + } return true; } -Path Config::getGameConfigFile(const std::string &pGameId) { +Path Config::getGameConfigFile(const std::string &pGameId, bool *exists) { const char *ppssppIniFilename = IsVREnabled() ? "_ppssppvr.ini" : "_ppsspp.ini"; std::string iniFileName = pGameId + ppssppIniFilename; - Path iniFileNameFull = FindConfigFile(iniFileName); + Path iniFileNameFull = FindConfigFile(iniFileName, exists); return iniFileNameFull; } @@ -1754,7 +1766,8 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title return false; } - Path fullIniFilePath = getGameConfigFile(pGameId); + bool exists; + Path fullIniFilePath = getGameConfigFile(pGameId, &exists); IniFile iniFile; @@ -1791,9 +1804,9 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title } bool Config::loadGameConfig(const std::string &pGameId, const std::string &title) { - Path iniFileNameFull = getGameConfigFile(pGameId); - - if (!hasGameConfig(pGameId)) { + bool exists; + Path iniFileNameFull = getGameConfigFile(pGameId, &exists); + if (!exists) { DEBUG_LOG(Log::Loader, "No game-specific settings found in %s. Using global defaults.", iniFileNameFull.c_str()); return false; } diff --git a/Core/Config.h b/Core/Config.h index 49612b2d83..8eff66237e 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -585,11 +585,11 @@ public: bool loadGameConfig(const std::string &game_id, const std::string &title); bool saveGameConfig(const std::string &pGameId, const std::string &title); void unloadGameConfig(); - Path getGameConfigFile(const std::string &gameId); + Path getGameConfigFile(const std::string &gameId, bool *exists); bool hasGameConfig(const std::string &game_id); void SetSearchPath(const Path &path); - const Path FindConfigFile(const std::string &baseFilename); + const Path FindConfigFile(const std::string &baseFilename, bool *exists); void UpdateIniLocation(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr);