Skip to content

Commit

Permalink
Merge pull request #16608 from unknownbrackets/ini-load-cleanup
Browse files Browse the repository at this point in the history
Cleanup value corrections in config load/save
  • Loading branch information
hrydgard committed Dec 19, 2022
2 parents e54d79a + 2b30714 commit e9ed837
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 46 deletions.
8 changes: 4 additions & 4 deletions Common/Data/Text/I18n.cpp
Expand Up @@ -67,13 +67,13 @@ std::shared_ptr<I18NCategory> I18NRepo::GetCategory(const char *category) {
}
}

std::string I18NRepo::GetIniPath(const std::string &languageID) const {
return "lang/" + languageID + ".ini";
Path I18NRepo::GetIniPath(const std::string &languageID) const {
return Path("lang") / (languageID + ".ini");
}

bool I18NRepo::IniExists(const std::string &languageID) const {
File::FileInfo info;
if (!VFSGetFileInfo(GetIniPath(languageID).c_str(), &info))
if (!VFSGetFileInfo(GetIniPath(languageID).ToString().c_str(), &info))
return false;
if (!info.exists)
return false;
Expand All @@ -88,7 +88,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const Path &overridePath)
if (!overridePath.empty()) {
iniPath = overridePath / (languageID + ".ini");
} else {
iniPath = Path(GetIniPath(languageID));
iniPath = GetIniPath(languageID);
}

if (!ini.LoadFromVFS(iniPath.ToString()))
Expand Down
2 changes: 1 addition & 1 deletion Common/Data/Text/I18n.h
Expand Up @@ -92,7 +92,7 @@ class I18NRepo {
std::map<std::string, std::vector<std::string>> GetMissingKeys() const;

private:
std::string GetIniPath(const std::string &languageID) const;
Path GetIniPath(const std::string &languageID) const;
void Clear();
I18NCategory *LoadSection(const Section *section, const char *name);
void SaveSection(IniFile &ini, Section *section, std::shared_ptr<I18NCategory> cat);
Expand Down
4 changes: 2 additions & 2 deletions Core/Compatibility.cpp
Expand Up @@ -47,7 +47,7 @@ void Compatibility::Load(const std::string &gameID) {
IniFile compat2;
// This one is user-editable. Need to load it after the system one.
Path path = GetSysDirectory(DIRECTORY_SYSTEM) / "compat.ini";
if (compat2.Load(path.ToString())) {
if (compat2.Load(path)) {
CheckSettings(compat2, gameID);
}
}
Expand All @@ -64,7 +64,7 @@ void Compatibility::Load(const std::string &gameID) {
IniFile compat2;
// This one is user-editable. Need to load it after the system one.
Path path = GetSysDirectory(DIRECTORY_SYSTEM) / "compatvr.ini";
if (compat2.Load(path.ToString())) {
if (compat2.Load(path)) {
CheckVRSettings(compat2, gameID);
}
}
Expand Down
98 changes: 59 additions & 39 deletions Core/Config.cpp
Expand Up @@ -1351,7 +1351,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
bShowFrameProfiler = true;

IniFile iniFile;
if (!iniFile.Load(iniFilename_.ToString())) {
if (!iniFile.Load(iniFilename_)) {
ERROR_LOG(LOADER, "Failed to read '%s'. Setting config to default.", iniFilename_.c_str());
// Continue anyway to initialize the config.
}
Expand Down Expand Up @@ -1433,11 +1433,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
vPostShaderNames.push_back(it.second);
}

// This caps the exponent 4 (so 16x.)
if (iAnisotropyLevel > 4) {
iAnisotropyLevel = 4;
}

// Check for an old dpad setting
Section *control = iniFile.GetOrCreateSection("Control");
float f;
Expand Down Expand Up @@ -1483,35 +1478,13 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {

CleanRecent();

// Set a default MAC, and correct if it's an old format.
if (sMACAddress.length() != 17)
sMACAddress = CreateRandMAC();

if (g_Config.bAutoFrameSkip && g_Config.bSkipBufferEffects) {
g_Config.bSkipBufferEffects = false;
}

// Override ppsspp.ini JIT value to prevent crashing
if (DefaultCpuCore() != (int)CPUCore::JIT && g_Config.iCpuCore == (int)CPUCore::JIT) {
jitForcedOff = true;
g_Config.iCpuCore = (int)CPUCore::IR_JIT;
}

// Automatically silence secondary instances. Could be an option I guess, but meh.
if (PPSSPP_ID > 1) {
g_Config.iGlobalVolume = 0;
}

// Automatically switch away from deprecated setting value.
if (iTexScalingLevel <= 0) {
iTexScalingLevel = 1;
}

#if PPSSPP_PLATFORM(ANDROID)
// The on path here is untested, since we don't expose it.
g_Config.bVSync = false;
#endif

PostLoadCleanup(false);

INFO_LOG(LOADER, "Config loaded: '%s'", iniFilename_.c_str());
}

Expand All @@ -1525,13 +1498,11 @@ bool Config::Save(const char *saveReason) {
return true;
}

if (jitForcedOff) {
// if JIT has been forced off, we don't want to screw up the user's ppsspp.ini
g_Config.iCpuCore = (int)CPUCore::JIT;
}
if (!iniFilename_.empty() && g_Config.bSaveSettings) {
saveGameConfig(gameId_, gameIdTitle_);

PreSaveCleanup(false);

CleanRecent();
IniFile iniFile;
if (!iniFile.Load(iniFilename_)) {
Expand Down Expand Up @@ -1611,15 +1582,59 @@ bool Config::Save(const char *saveReason) {
}
INFO_LOG(LOADER, "Controller config saved: %s", controllerIniFilename_.c_str());
}

PostSaveCleanup(false);
} else {
INFO_LOG(LOADER, "Not saving config");
}

return true;
}

void Config::PostLoadCleanup(bool gameSpecific) {
// Override ppsspp.ini JIT value to prevent crashing
if (DefaultCpuCore() != (int)CPUCore::JIT && g_Config.iCpuCore == (int)CPUCore::JIT) {
jitForcedOff = true;
g_Config.iCpuCore = (int)CPUCore::IR_JIT;
}

// This caps the exponent 4 (so 16x.)
if (iAnisotropyLevel > 4) {
iAnisotropyLevel = 4;
}

// Set a default MAC, and correct if it's an old format.
if (sMACAddress.length() != 17)
sMACAddress = CreateRandMAC();

if (g_Config.bAutoFrameSkip && g_Config.bSkipBufferEffects) {
g_Config.bSkipBufferEffects = false;
}

// Automatically silence secondary instances. Could be an option I guess, but meh.
if (PPSSPP_ID > 1) {
g_Config.iGlobalVolume = 0;
}

// Automatically switch away from deprecated setting value.
if (iTexScalingLevel <= 0) {
iTexScalingLevel = 1;
}
}

void Config::PreSaveCleanup(bool gameSpecific) {
if (jitForcedOff) {
// if JIT has been forced off, we don't want to screw up the user's ppsspp.ini
g_Config.iCpuCore = (int)CPUCore::JIT;
}
}

void Config::PostSaveCleanup(bool gameSpecific) {
if (jitForcedOff) {
// force JIT off again just in case Config::Save() is called without exiting PPSSPP
if (g_Config.iCpuCore != (int)CPUCore::INTERPRETER)
g_Config.iCpuCore = (int)CPUCore::IR_JIT;
}
return true;
}

// Use for debugging the version check without messing with the server
Expand Down Expand Up @@ -1858,6 +1873,8 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title
Section *top = iniFile.GetOrCreateSection("");
top->AddComment(StringFromFormat("Game config for %s - %s", pGameId.c_str(), title.c_str()));

PreSaveCleanup(true);

IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) {
if (setting->perGame_) {
setting->Set(section);
Expand All @@ -1879,8 +1896,9 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title
}

KeyMap::SaveToIni(iniFile);
iniFile.Save(fullIniFilePath.ToString());
iniFile.Save(fullIniFilePath);

PostSaveCleanup(true);
return true;
}

Expand All @@ -1894,7 +1912,7 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title

changeGameSpecific(pGameId, title);
IniFile iniFile;
iniFile.Load(iniFileNameFull.ToString());
iniFile.Load(iniFileNameFull);

auto postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting")->ToMap();
mPostShaderSetting.clear();
Expand All @@ -1921,6 +1939,7 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title
});

KeyMap::LoadFromIni(iniFile);
PostLoadCleanup(true);
return true;
}

Expand All @@ -1929,7 +1948,7 @@ void Config::unloadGameConfig() {
changeGameSpecific();

IniFile iniFile;
iniFile.Load(iniFilename_.ToString());
iniFile.Load(iniFilename_);

// Reload game specific settings back to standard.
IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) {
Expand All @@ -1952,12 +1971,13 @@ void Config::unloadGameConfig() {
}

LoadStandardControllerIni();
PostLoadCleanup(true);
}
}

void Config::LoadStandardControllerIni() {
IniFile controllerIniFile;
if (!controllerIniFile.Load(controllerIniFilename_.ToString())) {
if (!controllerIniFile.Load(controllerIniFilename_)) {
ERROR_LOG(LOADER, "Failed to read %s. Setting controller config to default.", controllerIniFilename_.c_str());
KeyMap::RestoreDefault();
} else {
Expand Down
4 changes: 4 additions & 0 deletions Core/Config.h
Expand Up @@ -575,6 +575,10 @@ struct Config {
void LoadStandardControllerIni();
void LoadLangValuesMapping();

void PostLoadCleanup(bool gameSpecific);
void PreSaveCleanup(bool gameSpecific);
void PostSaveCleanup(bool gameSpecific);

private:
bool reload_ = false;
std::string gameId_;
Expand Down

0 comments on commit e9ed837

Please sign in to comment.