diff --git a/Source/Core/Core/CoreParameter.cpp b/Source/Core/Core/CoreParameter.cpp index 7f418cbd3a..5b4937657f 100644 --- a/Source/Core/Core/CoreParameter.cpp +++ b/Source/Core/Core/CoreParameter.cpp @@ -375,58 +375,59 @@ void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::stri IniFile SCoreStartupParameter::LoadDefaultGameIni() const { - IniFile game_ini; - LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP, GetUniqueID(), m_revision); - return game_ini; + return LoadDefaultGameIni(GetUniqueID(), m_revision); } IniFile SCoreStartupParameter::LoadLocalGameIni() const { - IniFile game_ini; - LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX), GetUniqueID(), m_revision); - return game_ini; + return LoadLocalGameIni(GetUniqueID(), m_revision); } IniFile SCoreStartupParameter::LoadGameIni() const { - IniFile game_ini; - LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP, GetUniqueID(), m_revision); - LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX), GetUniqueID(), m_revision); - return game_ini; + return LoadGameIni(GetUniqueID(), m_revision); } IniFile SCoreStartupParameter::LoadDefaultGameIni(const std::string& id, int revision) { IniFile game_ini; - LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP, id, revision); + for (const std::string& filename : GetGameIniFilenames(id, revision)) + game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true); return game_ini; } IniFile SCoreStartupParameter::LoadLocalGameIni(const std::string& id, int revision) { IniFile game_ini; - LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX), id, revision); + for (const std::string& filename : GetGameIniFilenames(id, revision)) + game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + filename, true); return game_ini; } IniFile SCoreStartupParameter::LoadGameIni(const std::string& id, int revision) { IniFile game_ini; - LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP, id, revision); - LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX), id, revision); + for (const std::string& filename : GetGameIniFilenames(id, revision)) + game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true); + for (const std::string& filename : GetGameIniFilenames(id, revision)) + game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + filename, true); return game_ini; } -void SCoreStartupParameter::LoadGameIni(IniFile* game_ini, const std::string& path, - const std::string& id, int revision) +// Returns all possible filenames in ascending order of priority +std::vector SCoreStartupParameter::GetGameIniFilenames(const std::string& id, int revision) { + std::vector filenames; + // INIs that match all regions if (id.size() >= 4) - game_ini->Load(path + id.substr(0, 3) + ".ini", true); + filenames.push_back(id.substr(0, 3) + ".ini"); // Regular INIs - game_ini->Load(path + id + ".ini", true); + filenames.push_back(id + ".ini"); // INIs with specific revisions - game_ini->Load(path + id + StringFromFormat("r%d", revision) + ".ini", true); + filenames.push_back(id + StringFromFormat("r%d", revision) + ".ini"); + + return filenames; } diff --git a/Source/Core/Core/CoreParameter.h b/Source/Core/Core/CoreParameter.h index 80ab3a628b..e5f9cac9b1 100644 --- a/Source/Core/Core/CoreParameter.h +++ b/Source/Core/Core/CoreParameter.h @@ -257,6 +257,5 @@ struct SCoreStartupParameter static IniFile LoadLocalGameIni(const std::string& id, int revision); static IniFile LoadGameIni(const std::string& id, int revision); -private: - static void LoadGameIni(IniFile* game_ini, const std::string& path, const std::string& id, int revision); + static std::vector GetGameIniFilenames(const std::string& id, int revision); }; diff --git a/Source/Core/DolphinWX/ISOProperties.cpp b/Source/Core/DolphinWX/ISOProperties.cpp index c580606c42..e0f83a76d6 100644 --- a/Source/Core/DolphinWX/ISOProperties.cpp +++ b/Source/Core/DolphinWX/ISOProperties.cpp @@ -149,22 +149,21 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW } } - // Is it really necessary to use GetTitleID in case GetUniqueID fails? - std::string _iniFilename = OpenISO->GetUniqueID(); - if (_iniFilename.empty()) + // TODO: Is it really necessary to use GetTitleID in case GetUniqueID fails? + game_id = OpenISO->GetUniqueID(); + if (game_id.empty()) { - u8 title_id[8]; - if (OpenISO->GetTitleID(title_id)) + u8 game_id_bytes[8]; + if (OpenISO->GetTitleID(game_id_bytes)) { - _iniFilename = StringFromFormat("%016" PRIx64, Common::swap64(title_id)); + game_id = StringFromFormat("%016" PRIx64, Common::swap64(game_id_bytes)); } } // Load game INIs - GameIniFileDefault = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + _iniFilename + ".ini"; - GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + _iniFilename + ".ini"; - GameIniDefault = SCoreStartupParameter::LoadDefaultGameIni(_iniFilename, OpenISO->GetRevision()); - GameIniLocal = SCoreStartupParameter::LoadLocalGameIni(_iniFilename, OpenISO->GetRevision()); + GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + game_id + ".ini"; + GameIniDefault = SCoreStartupParameter::LoadDefaultGameIni(game_id, OpenISO->GetRevision()); + GameIniLocal = SCoreStartupParameter::LoadLocalGameIni(game_id, OpenISO->GetRevision()); // Setup GUI OpenGameListItem = new GameListItem(fileName); @@ -643,7 +642,16 @@ void CISOProperties::CreateGUIControls(bool IsWad) sButtons->Add(new wxButton(this, wxID_OK, _("Close"))); // If there is no default gameini, disable the button. - if (!File::Exists(GameIniFileDefault)) + bool game_ini_exists = false; + for (const std::string& ini_filename : SCoreStartupParameter::GetGameIniFilenames(game_id, OpenISO->GetRevision())) + { + if (File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + ini_filename)) + { + game_ini_exists = true; + break; + } + } + if (!game_ini_exists) EditConfigDefault->Disable(); // Add notebook and buttons to the dialog @@ -1283,9 +1291,16 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event)) m_MD5Sum->SetValue(output_string); } +// Opens all pre-defined INIs for the game. If there are multiple ones, +// they will all be opened, but there is usually only one void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED (event)) { - LaunchExternalEditor(GameIniFileDefault); + for (const std::string& filename : SCoreStartupParameter::GetGameIniFilenames(game_id, OpenISO->GetRevision())) + { + std::string path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename; + if (File::Exists(path)) + LaunchExternalEditor(path); + } } void CISOProperties::ListSelectionChanged(wxCommandEvent& event) diff --git a/Source/Core/DolphinWX/ISOProperties.h b/Source/Core/DolphinWX/ISOProperties.h index 8b396d5b2c..46b31fe12c 100644 --- a/Source/Core/DolphinWX/ISOProperties.h +++ b/Source/Core/DolphinWX/ISOProperties.h @@ -241,8 +241,8 @@ private: IniFile GameIniDefault; IniFile GameIniLocal; - std::string GameIniFileDefault; std::string GameIniFileLocal; + std::string game_id; std::set DefaultPatches; std::set DefaultCheats;