Merge pull request #16185 from iota97/config-append

Allow to append some configs
This commit is contained in:
Henrik Rydgård 2023-01-12 16:20:13 +01:00 committed by GitHub
commit ca3303d507
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -1310,6 +1310,29 @@ void Config::UpdateIniLocation(const char *iniFileName, const char *controllerIn
controllerIniFilename_ = FindConfigFile(useControllerIniFilename ? controllerIniFilename : controlsIniFilename);
}
bool Config::LoadAppendedConfig() {
IniFile iniFile;
if (!iniFile.Load(appendedConfigFileName_)) {
ERROR_LOG(LOADER, "Failed to read appended config '%s'.", appendedConfigFileName_.c_str());
return false;
}
IterateSettings(iniFile, [&iniFile](Section *section, ConfigSetting *setting) {
if (iniFile.Exists(section->name().c_str(), setting->iniKey_))
setting->Get(section);
});
INFO_LOG(LOADER, "Loaded appended config '%s'.", appendedConfigFileName_.c_str());
Save("Loaded appended config"); // Let's prevent reset
return true;
}
void Config::SetAppendedConfigIni(const Path &path) {
appendedConfigFileName_ = path;
}
void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
if (!bUpdatedInstanceCounter) {
InitInstanceCounter();
@ -1916,6 +1939,14 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title
});
KeyMap::LoadFromIni(iniFile);
if (!appendedConfigFileName_.ToString().empty() &&
std::find(appendedConfigUpdatedGames_.begin(), appendedConfigUpdatedGames_.end(), pGameId) == appendedConfigUpdatedGames_.end()) {
LoadAppendedConfig();
appendedConfigUpdatedGames_.push_back(pGameId);
}
PostLoadCleanup(true);
return true;
}

View File

@ -567,6 +567,8 @@ public:
void ClearRecentIsos();
const std::map<std::string, std::pair<std::string, int>> &GetLangValuesMapping();
bool LoadAppendedConfig();
void SetAppendedConfigIni(const Path &path);
protected:
void LoadStandardControllerIni();
@ -585,6 +587,9 @@ private:
Path iniFilename_;
Path controllerIniFilename_;
Path searchPath_;
Path appendedConfigFileName_;
// A set make more sense, but won't have many entry, and I dont want to include the whole std::set header here
std::vector<std::string> appendedConfigUpdatedGames_;
ConfigPrivate *private_ = nullptr;
};

View File

@ -665,6 +665,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
gotoTouchScreenTest = true;
if (!strcmp(argv[i], "--gamesettings"))
gotoGameSettings = true;
if (!strncmp(argv[i], "--appendconfig=", strlen("--appendconfig=")) && strlen(argv[i]) > strlen("--appendconfig=")) {
g_Config.SetAppendedConfigIni(Path(std::string(argv[i] + strlen("--appendconfig="))));
g_Config.LoadAppendedConfig();
}
break;
}
} else {