Merge pull request #5777 from JosJuice/unify-getgameinifilenames
Unify GetGameIniFilenames
This commit is contained in:
commit
100b0a52d3
|
@ -8,6 +8,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -28,13 +29,17 @@
|
||||||
|
|
||||||
namespace ConfigLoaders
|
namespace ConfigLoaders
|
||||||
{
|
{
|
||||||
using ConfigLocation = Config::ConfigLocation;
|
|
||||||
|
|
||||||
// Returns all possible filenames in ascending order of priority
|
// Returns all possible filenames in ascending order of priority
|
||||||
static std::vector<std::string> GetGameIniFilenames(const std::string& id, u16 revision)
|
std::vector<std::string> GetGameIniFilenames(const std::string& id, std::optional<u16> revision)
|
||||||
{
|
{
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
|
|
||||||
|
if (id.empty())
|
||||||
|
return filenames;
|
||||||
|
|
||||||
|
// INIs that match the system code (unique for each Virtual Console system)
|
||||||
|
filenames.push_back(id.substr(0, 1) + ".ini");
|
||||||
|
|
||||||
// INIs that match all regions
|
// INIs that match all regions
|
||||||
if (id.size() >= 4)
|
if (id.size() >= 4)
|
||||||
filenames.push_back(id.substr(0, 3) + ".ini");
|
filenames.push_back(id.substr(0, 3) + ".ini");
|
||||||
|
@ -43,11 +48,13 @@ static std::vector<std::string> GetGameIniFilenames(const std::string& id, u16 r
|
||||||
filenames.push_back(id + ".ini");
|
filenames.push_back(id + ".ini");
|
||||||
|
|
||||||
// INIs with specific revisions
|
// INIs with specific revisions
|
||||||
filenames.push_back(id + StringFromFormat("r%d", revision) + ".ini");
|
if (revision)
|
||||||
|
filenames.push_back(id + StringFromFormat("r%d", *revision) + ".ini");
|
||||||
|
|
||||||
return filenames;
|
return filenames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using ConfigLocation = Config::ConfigLocation;
|
||||||
using INIToLocationMap = std::map<std::pair<std::string, std::string>, ConfigLocation>;
|
using INIToLocationMap = std::map<std::pair<std::string, std::string>, ConfigLocation>;
|
||||||
|
|
||||||
// This is a mapping from the legacy section-key pairs to ConfigLocations.
|
// This is a mapping from the legacy section-key pairs to ConfigLocations.
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
@ -17,6 +19,8 @@ class ConfigLayerLoader;
|
||||||
|
|
||||||
namespace ConfigLoaders
|
namespace ConfigLoaders
|
||||||
{
|
{
|
||||||
|
std::vector<std::string> GetGameIniFilenames(const std::string& id, std::optional<u16> revision);
|
||||||
|
|
||||||
std::unique_ptr<Config::ConfigLayerLoader> GenerateGlobalGameConfigLoader(const std::string& id,
|
std::unique_ptr<Config::ConfigLayerLoader> GenerateGlobalGameConfigLoader(const std::string& id,
|
||||||
u16 revision);
|
u16 revision);
|
||||||
std::unique_ptr<Config::ConfigLayerLoader> GenerateLocalGameConfigLoader(const std::string& id,
|
std::unique_ptr<Config::ConfigLayerLoader> GenerateLocalGameConfigLoader(const std::string& id,
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "Core/Analytics.h"
|
#include "Core/Analytics.h"
|
||||||
#include "Core/Boot/Boot.h"
|
#include "Core/Boot/Boot.h"
|
||||||
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/FifoPlayer/FifoDataFile.h"
|
#include "Core/FifoPlayer/FifoDataFile.h"
|
||||||
#include "Core/HLE/HLE.h"
|
#include "Core/HLE/HLE.h"
|
||||||
|
@ -1082,7 +1083,7 @@ IniFile SConfig::LoadGameIni() const
|
||||||
IniFile SConfig::LoadDefaultGameIni(const std::string& id, std::optional<u16> revision)
|
IniFile SConfig::LoadDefaultGameIni(const std::string& id, std::optional<u16> revision)
|
||||||
{
|
{
|
||||||
IniFile game_ini;
|
IniFile game_ini;
|
||||||
for (const std::string& filename : GetGameIniFilenames(id, revision))
|
for (const std::string& filename : ConfigLoaders::GetGameIniFilenames(id, revision))
|
||||||
game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true);
|
game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true);
|
||||||
return game_ini;
|
return game_ini;
|
||||||
}
|
}
|
||||||
|
@ -1090,7 +1091,7 @@ IniFile SConfig::LoadDefaultGameIni(const std::string& id, std::optional<u16> re
|
||||||
IniFile SConfig::LoadLocalGameIni(const std::string& id, std::optional<u16> revision)
|
IniFile SConfig::LoadLocalGameIni(const std::string& id, std::optional<u16> revision)
|
||||||
{
|
{
|
||||||
IniFile game_ini;
|
IniFile game_ini;
|
||||||
for (const std::string& filename : GetGameIniFilenames(id, revision))
|
for (const std::string& filename : ConfigLoaders::GetGameIniFilenames(id, revision))
|
||||||
game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + filename, true);
|
game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + filename, true);
|
||||||
return game_ini;
|
return game_ini;
|
||||||
}
|
}
|
||||||
|
@ -1098,35 +1099,9 @@ IniFile SConfig::LoadLocalGameIni(const std::string& id, std::optional<u16> revi
|
||||||
IniFile SConfig::LoadGameIni(const std::string& id, std::optional<u16> revision)
|
IniFile SConfig::LoadGameIni(const std::string& id, std::optional<u16> revision)
|
||||||
{
|
{
|
||||||
IniFile game_ini;
|
IniFile game_ini;
|
||||||
for (const std::string& filename : GetGameIniFilenames(id, revision))
|
for (const std::string& filename : ConfigLoaders::GetGameIniFilenames(id, revision))
|
||||||
game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true);
|
game_ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true);
|
||||||
for (const std::string& filename : GetGameIniFilenames(id, revision))
|
for (const std::string& filename : ConfigLoaders::GetGameIniFilenames(id, revision))
|
||||||
game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + filename, true);
|
game_ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + filename, true);
|
||||||
return game_ini;
|
return game_ini;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns all possible filenames in ascending order of priority
|
|
||||||
std::vector<std::string> SConfig::GetGameIniFilenames(const std::string& id,
|
|
||||||
std::optional<u16> revision)
|
|
||||||
{
|
|
||||||
std::vector<std::string> filenames;
|
|
||||||
|
|
||||||
if (id.empty())
|
|
||||||
return filenames;
|
|
||||||
|
|
||||||
// INIs that match the system code (unique for each Virtual Console system)
|
|
||||||
filenames.push_back(id.substr(0, 1) + ".ini");
|
|
||||||
|
|
||||||
// INIs that match all regions
|
|
||||||
if (id.size() >= 4)
|
|
||||||
filenames.push_back(id.substr(0, 3) + ".ini");
|
|
||||||
|
|
||||||
// Regular INIs
|
|
||||||
filenames.push_back(id + ".ini");
|
|
||||||
|
|
||||||
// INIs with specific revisions
|
|
||||||
if (revision)
|
|
||||||
filenames.push_back(id + StringFromFormat("r%d", *revision) + ".ini");
|
|
||||||
|
|
||||||
return filenames;
|
|
||||||
}
|
|
||||||
|
|
|
@ -231,9 +231,6 @@ struct SConfig : NonCopyable
|
||||||
static IniFile LoadLocalGameIni(const std::string& id, std::optional<u16> revision);
|
static IniFile LoadLocalGameIni(const std::string& id, std::optional<u16> revision);
|
||||||
static IniFile LoadGameIni(const std::string& id, std::optional<u16> revision);
|
static IniFile LoadGameIni(const std::string& id, std::optional<u16> revision);
|
||||||
|
|
||||||
static std::vector<std::string> GetGameIniFilenames(const std::string& id,
|
|
||||||
std::optional<u16> revision);
|
|
||||||
|
|
||||||
std::string m_NANDPath;
|
std::string m_NANDPath;
|
||||||
std::string m_DumpPath;
|
std::string m_DumpPath;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/GeckoCodeConfig.h"
|
#include "Core/GeckoCodeConfig.h"
|
||||||
|
@ -444,7 +445,7 @@ void CISOProperties::CreateGUIControls()
|
||||||
|
|
||||||
// If there is no default gameini, disable the button.
|
// If there is no default gameini, disable the button.
|
||||||
const std::vector<std::string> ini_names =
|
const std::vector<std::string> ini_names =
|
||||||
SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision());
|
ConfigLoaders::GetGameIniFilenames(game_id, m_open_iso->GetRevision());
|
||||||
const bool game_ini_exists =
|
const bool game_ini_exists =
|
||||||
std::any_of(ini_names.cbegin(), ini_names.cend(), [](const std::string& name) {
|
std::any_of(ini_names.cbegin(), ini_names.cend(), [](const std::string& name) {
|
||||||
return File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + name);
|
return File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + name);
|
||||||
|
@ -752,7 +753,7 @@ void CISOProperties::OnChangeTitle(wxCommandEvent& event)
|
||||||
void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED(event))
|
void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
for (const std::string& filename :
|
for (const std::string& filename :
|
||||||
SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
|
ConfigLoaders::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
|
||||||
{
|
{
|
||||||
std::string path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename;
|
std::string path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename;
|
||||||
if (File::Exists(path))
|
if (File::Exists(path))
|
||||||
|
|
Loading…
Reference in New Issue