Skip to content

Commit

Permalink
Use settings version way
Browse files Browse the repository at this point in the history
  • Loading branch information
iota97 committed Jul 8, 2022
1 parent 5f569db commit 7846340
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 50 deletions.
79 changes: 29 additions & 50 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ static ConfigSetting generalSettings[] = {
ConfigSetting("EnablePlugins", &g_Config.bLoadPlugins, true, true, true),

ReportedConfigSetting("IgnoreCompatSettings", &g_Config.sIgnoreCompatSettings, "", true, true),
ConfigSetting("SettingsVersion", &g_Config.uSettingsVersion, 0u, true, true), // Per game for game configs

ConfigSetting(false),
};
Expand Down Expand Up @@ -1270,6 +1271,24 @@ void Config::UpdateIniLocation(const char *iniFileName, const char *controllerIn
controllerIniFilename_ = FindConfigFile(useControllerIniFilename ? controllerIniFilename : "controls.ini");
}

static void loadOldControlSettings(IniFile &iniFile) {
iniFile.GetIfExists("General", "RightAnalogUp", &g_Config.iRightAnalogUp);
iniFile.GetIfExists("General", "RightAnalogDown", &g_Config.iRightAnalogDown);
iniFile.GetIfExists("General", "RightAnalogLeft", &g_Config.iRightAnalogLeft);
iniFile.GetIfExists("General", "RightAnalogRight", &g_Config.iRightAnalogRight);
iniFile.GetIfExists("General", "RightAnalogPress", &g_Config.iRightAnalogPress);
iniFile.GetIfExists("General", "SwipeUp", &g_Config.iSwipeUp);
iniFile.GetIfExists("General", "SwipeDown", &g_Config.iSwipeDown);
iniFile.GetIfExists("General", "SwipeLeft", &g_Config.iSwipeLeft);
iniFile.GetIfExists("General", "SwipeRight", &g_Config.iSwipeRight);
iniFile.GetIfExists("General", "DoubleTapGesture", &g_Config.iDoubleTapGesture);
iniFile.GetIfExists("General", "SwipeSensitivity", &g_Config.fSwipeSensitivity);
iniFile.GetIfExists("General", "SwipeSmoothing", &g_Config.fSwipeSmoothing);
iniFile.GetIfExists("General", "RightAnalogCustom", &g_Config.bRightAnalogCustom);
iniFile.GetIfExists("General", "RightAnalogDisableDiagonal", &g_Config.bRightAnalogDisableDiagonal);
iniFile.GetIfExists("General", "GestureControlEnabled", &g_Config.bGestureControlEnabled);
}

void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
if (!bUpdatedInstanceCounter) {
InitInstanceCounter();
Expand Down Expand Up @@ -1368,22 +1387,11 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
ResetControlLayout();
}

// Migrate from wrong section...
iniFile.GetIfExists("General", "RightAnalogUp", &g_Config.iRightAnalogUp);
iniFile.GetIfExists("General", "RightAnalogDown", &g_Config.iRightAnalogDown);
iniFile.GetIfExists("General", "RightAnalogLeft", &g_Config.iRightAnalogLeft);
iniFile.GetIfExists("General", "RightAnalogRight", &g_Config.iRightAnalogRight);
iniFile.GetIfExists("General", "RightAnalogPress", &g_Config.iRightAnalogPress);
iniFile.GetIfExists("General", "SwipeUp", &g_Config.iSwipeUp);
iniFile.GetIfExists("General", "SwipeDown", &g_Config.iSwipeDown);
iniFile.GetIfExists("General", "SwipeLeft", &g_Config.iSwipeLeft);
iniFile.GetIfExists("General", "SwipeRight", &g_Config.iSwipeRight);
iniFile.GetIfExists("General", "DoubleTapGesture", &g_Config.iDoubleTapGesture);
iniFile.GetIfExists("General", "SwipeSensitivity", &g_Config.fSwipeSensitivity);
iniFile.GetIfExists("General", "SwipeSmoothing", &g_Config.fSwipeSmoothing);
iniFile.GetIfExists("General", "RightAnalogCustom", &g_Config.bRightAnalogCustom);
iniFile.GetIfExists("General", "RightAnalogDisableDiagonal", &g_Config.bRightAnalogDisableDiagonal);
iniFile.GetIfExists("General", "GestureControlEnabled", &g_Config.bGestureControlEnabled);
if (g_Config.uSettingsVersion == 0) {
g_Config.uSettingsVersion = 1;

loadOldControlSettings(iniFile);
}

const char *gitVer = PPSSPP_GIT_VERSION;
Version installed(gitVer);
Expand Down Expand Up @@ -1577,24 +1585,6 @@ bool Config::Save(const char *saveReason) {
Section *control = iniFile.GetOrCreateSection("Control");
control->Delete("DPadRadius");

// Migrate from wrong section...
Section *general = iniFile.GetOrCreateSection("General");
general->Delete("RightAnalogUp");
general->Delete("RightAnalogDown");
general->Delete("RightAnalogLeft");
general->Delete("RightAnalogRight");
general->Delete("RightAnalogPress");
general->Delete("SwipeUp");
general->Delete("SwipeDown");
general->Delete("SwipeLeft");
general->Delete("SwipeRight");
general->Delete("DoubleTapGesture");
general->Delete("SwipeSensitivity");
general->Delete("SwipeSmoothing");
general->Delete("RightAnalogCustom");
general->Delete("RightAnalogDisableDiagonal");
general->Delete("GestureControlEnabled");

Section *log = iniFile.GetOrCreateSection(logSectionName);
if (LogManager::GetInstance())
LogManager::GetInstance()->SaveConfig(log);
Expand Down Expand Up @@ -1908,22 +1898,11 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title
}
});

// Migrate from wrong section...
iniFile.GetIfExists("General", "RightAnalogUp", &g_Config.iRightAnalogUp);
iniFile.GetIfExists("General", "RightAnalogDown", &g_Config.iRightAnalogDown);
iniFile.GetIfExists("General", "RightAnalogLeft", &g_Config.iRightAnalogLeft);
iniFile.GetIfExists("General", "RightAnalogRight", &g_Config.iRightAnalogRight);
iniFile.GetIfExists("General", "RightAnalogPress", &g_Config.iRightAnalogPress);
iniFile.GetIfExists("General", "SwipeUp", &g_Config.iSwipeUp);
iniFile.GetIfExists("General", "SwipeDown", &g_Config.iSwipeDown);
iniFile.GetIfExists("General", "SwipeLeft", &g_Config.iSwipeLeft);
iniFile.GetIfExists("General", "SwipeRight", &g_Config.iSwipeRight);
iniFile.GetIfExists("General", "DoubleTapGesture", &g_Config.iDoubleTapGesture);
iniFile.GetIfExists("General", "SwipeSensitivity", &g_Config.fSwipeSensitivity);
iniFile.GetIfExists("General", "SwipeSmoothing", &g_Config.fSwipeSmoothing);
iniFile.GetIfExists("General", "RightAnalogCustom", &g_Config.bRightAnalogCustom);
iniFile.GetIfExists("General", "RightAnalogDisableDiagonal", &g_Config.bRightAnalogDisableDiagonal);
iniFile.GetIfExists("General", "GestureControlEnabled", &g_Config.bGestureControlEnabled);
if (g_Config.uSettingsVersion == 0) {
g_Config.uSettingsVersion = 1;

loadOldControlSettings(iniFile);
}

KeyMap::LoadFromIni(iniFile);
return true;
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct Config {
bool bEnableLogging;
bool bDumpDecryptedEboot;
bool bFullscreenOnDoubleclick;
uint32_t uSettingsVersion;

// These four are Win UI only
bool bPauseOnLostFocus;
Expand Down

0 comments on commit 7846340

Please sign in to comment.