From f9d6c17c08f0aca5ac9f72432e5de780d50bafdf Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 7 Feb 2015 21:27:26 +0100 Subject: [PATCH] Use CoreParameter's game INI functions in more places --- Source/Core/Core/CoreParameter.cpp | 41 ++++++++++++++++----- Source/Core/Core/CoreParameter.h | 6 ++- Source/Core/DolphinQt/GameList/GameFile.cpp | 5 +-- Source/Core/DolphinWX/GameListCtrl.cpp | 20 ++-------- Source/Core/DolphinWX/ISOFile.cpp | 10 ++--- Source/Core/DolphinWX/ISOProperties.cpp | 14 +++---- Source/Core/InputCommon/InputConfig.cpp | 6 +-- 7 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Source/Core/Core/CoreParameter.cpp b/Source/Core/Core/CoreParameter.cpp index 117c25b32f..d5ee98aacd 100644 --- a/Source/Core/Core/CoreParameter.cpp +++ b/Source/Core/Core/CoreParameter.cpp @@ -378,34 +378,57 @@ void SCoreStartupParameter::CheckMemcardPath(std::string& memcardPath, std::stri IniFile SCoreStartupParameter::LoadDefaultGameIni() const { IniFile game_ini; - LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP); + LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP, GetUniqueID(), m_revision); return game_ini; } IniFile SCoreStartupParameter::LoadLocalGameIni() const { IniFile game_ini; - LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX)); + LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX), GetUniqueID(), m_revision); return game_ini; } IniFile SCoreStartupParameter::LoadGameIni() const { IniFile game_ini; - LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP); - LoadGameIni(&game_ini, File::GetUserPath(D_GAMESETTINGS_IDX)); + 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; } -void SCoreStartupParameter::LoadGameIni(IniFile* game_ini, const std::string& path) const +IniFile SCoreStartupParameter::LoadDefaultGameIni(const std::string& id, int revision) +{ + IniFile game_ini; + LoadGameIni(&game_ini, File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP, id, revision); + 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); + 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); + return game_ini; +} + +void SCoreStartupParameter::LoadGameIni(IniFile* game_ini, const std::string& path, + const std::string& id, int revision) { // INIs that match all regions - if (GetUniqueID().size() >= 4) - game_ini->Load(path + GetUniqueID().substr(0, 3) + ".ini", true); + if (id.size() >= 4) + game_ini->Load(path + id.substr(0, 3) + ".ini", true); // Regular INIs - game_ini->Load(path + GetUniqueID() + ".ini", true); + game_ini->Load(path + id + ".ini", true); // INIs with specific revisions - game_ini->Load(path + GetUniqueID() + StringFromFormat("r%d", m_revision) + ".ini", true); + game_ini->Load(path + id + StringFromFormat("r%d", revision) + ".ini", true); } diff --git a/Source/Core/Core/CoreParameter.h b/Source/Core/Core/CoreParameter.h index 2054794384..6bec140b4e 100644 --- a/Source/Core/Core/CoreParameter.h +++ b/Source/Core/Core/CoreParameter.h @@ -264,6 +264,10 @@ struct SCoreStartupParameter IniFile LoadLocalGameIni() const; IniFile LoadGameIni() const; + static IniFile LoadDefaultGameIni(const std::string& id, int revision); + static IniFile LoadLocalGameIni(const std::string& id, int revision); + static IniFile LoadGameIni(const std::string& id, int revision); + private: - void LoadGameIni(IniFile* game_ini, const std::string& path) const; + static void LoadGameIni(IniFile* game_ini, const std::string& path, const std::string& id, int revision); }; diff --git a/Source/Core/DolphinQt/GameList/GameFile.cpp b/Source/Core/DolphinQt/GameList/GameFile.cpp index f8601d05e6..a5216b4ead 100644 --- a/Source/Core/DolphinQt/GameList/GameFile.cpp +++ b/Source/Core/DolphinQt/GameList/GameFile.cpp @@ -126,10 +126,7 @@ GameFile::GameFile(const QString& fileName) if (m_valid) { - IniFile ini; - ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + m_unique_id.toStdString() + ".ini"); - ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_unique_id.toStdString() + ".ini", true); - + IniFile ini = SCoreStartupParameter::LoadGameIni(m_unique_id.toStdString(), m_revision); std::string issues_temp; ini.GetIfExists("EmuState", "EmulationStateId", &m_emu_state); ini.GetIfExists("EmuState", "EmulationIssues", &issues_temp); diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index a055aa270d..df7bfe291d 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -462,24 +462,10 @@ void CGameListCtrl::InsertItemInReportView(long _Index) titlestxt.close(); } - std::string GameIni[3]; - GameIni[0] = File::GetUserPath(D_GAMESETTINGS_IDX) + rISOFile.GetUniqueID() + ".ini"; - GameIni[1] = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + rISOFile.GetUniqueID() + std::to_string(rISOFile.GetRevision()) + ".ini"; - GameIni[2] = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + rISOFile.GetUniqueID() + ".ini"; std::string title; - IniFile gameini; - for (int i = 0; i < 3; ++i) - { - if (File::Exists(GameIni[i])) - { - gameini.Load(GameIni[i]); - if (gameini.GetIfExists("EmuState", "Title", &title)) - { - name = title; - break; - } - } - } + IniFile gameini = SCoreStartupParameter::LoadGameIni(rISOFile.GetUniqueID(), rISOFile.GetRevision()); + if (gameini.GetIfExists("EmuState", "Title", &title)) + name = title; SetItem(_Index, COLUMN_TITLE, StrToWxStr(name), -1); diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp index 58eecce21c..2213dfd727 100644 --- a/Source/Core/DolphinWX/ISOFile.cpp +++ b/Source/Core/DolphinWX/ISOFile.cpp @@ -121,13 +121,9 @@ GameListItem::GameListItem(const std::string& _rFileName) if (IsValid()) { - IniFile ini; - ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + m_UniqueID + ".ini"); - ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_UniqueID + ".ini", true); - - IniFile::Section* emu_state = ini.GetOrCreateSection("EmuState"); - emu_state->Get("EmulationStateId", &m_emu_state); - emu_state->Get("EmulationIssues", &m_issues); + IniFile ini = SCoreStartupParameter::LoadGameIni(m_UniqueID, m_Revision); + ini.GetIfExists("EmuState", "EmulationStateId", &m_emu_state); + ini.GetIfExists("EmuState", "EmulationIssues", &m_issues); } if (!m_pImage.empty()) diff --git a/Source/Core/DolphinWX/ISOProperties.cpp b/Source/Core/DolphinWX/ISOProperties.cpp index af373efd68..80f14791a1 100644 --- a/Source/Core/DolphinWX/ISOProperties.cpp +++ b/Source/Core/DolphinWX/ISOProperties.cpp @@ -163,11 +163,9 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW } } - // Load game ini + // Is it really necessary to use GetTitleID in case GetUniqueID fails? std::string _iniFilename = OpenISO->GetUniqueID(); - std::string _iniFilenameRevisionSpecific = _iniFilename + "r" + std::to_string(OpenISO->GetRevision()); - - if (!_iniFilename.length()) + if (_iniFilename.empty()) { u8 title_id[8]; if (OpenISO->GetTitleID(title_id)) @@ -176,13 +174,11 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW } } + // Load game INIs GameIniFileDefault = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + _iniFilename + ".ini"; - std::string GameIniFileDefaultRevisionSpecific = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + _iniFilenameRevisionSpecific + ".ini"; GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + _iniFilename + ".ini"; - - GameIniDefault.Load(GameIniFileDefault); - GameIniDefault.Load(GameIniFileDefaultRevisionSpecific, true); - GameIniLocal.Load(GameIniFileLocal); + GameIniDefault = SCoreStartupParameter::LoadDefaultGameIni(_iniFilename, OpenISO->GetRevision()); + GameIniLocal = SCoreStartupParameter::LoadLocalGameIni(_iniFilename, OpenISO->GetRevision()); // Setup GUI OpenGameListItem = new GameListItem(fileName); diff --git a/Source/Core/InputCommon/InputConfig.cpp b/Source/Core/InputCommon/InputConfig.cpp index 5920b39b99..da5bb5081a 100644 --- a/Source/Core/InputCommon/InputConfig.cpp +++ b/Source/Core/InputCommon/InputConfig.cpp @@ -17,7 +17,6 @@ InputConfig::~InputConfig() bool InputConfig::LoadConfig(bool isGC) { IniFile inifile; - IniFile game_ini; bool useProfile[MAX_BBMOTES] = {false, false, false, false, false}; std::string num[MAX_BBMOTES] = {"1", "2", "3", "4", "BB"}; std::string profile[MAX_BBMOTES]; @@ -37,8 +36,7 @@ bool InputConfig::LoadConfig(bool isGC) path = "Profiles/Wiimote/"; } - game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() + ".ini"); - game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID() + ".ini", true); + IniFile game_ini = SConfig::GetInstance().m_LocalCoreStartupParameter.LoadGameIni(); IniFile::Section* control_section = game_ini.GetOrCreateSection("Controls"); for (int i = 0; i < 4; i++) @@ -53,7 +51,7 @@ bool InputConfig::LoadConfig(bool isGC) } else { - // TODO: Having a PanicAlert for this is dumb. + // TODO: PanicAlert shouldn't be used for this. PanicAlertT("Selected controller profile does not exist"); } }