Qt: Simplify settings version check

This commit is contained in:
Connor McLaughlin 2020-10-09 18:26:21 +10:00
parent 74880ac047
commit cb6502afa3
7 changed files with 15 additions and 31 deletions

View file

@ -55,8 +55,6 @@ int main(int argc, char* argv[])
window->startupUpdateCheck();
}
window->reportSettingsVersionMismatchString();
int result = app.exec();
window.reset();

View file

@ -1121,13 +1121,6 @@ void MainWindow::startupUpdateCheck()
checkForUpdates(false);
}
void MainWindow::reportSettingsVersionMismatchString()
{
const QString mismatch_str = QString::fromStdString(m_host_interface->GetSettingsVersionMismatchString());
if (!mismatch_str.isEmpty())
reportError(mismatch_str);
}
void MainWindow::updateDebugMenuVisibility()
{
const bool visible = m_host_interface->GetBoolSettingValue("Main", "ShowDebugMenu", false);

View file

@ -30,10 +30,6 @@ public:
/// Performs update check if enabled in settings.
void startupUpdateCheck();
/// Reports m_host_interface's settings version mismatch string. Does nothing if string is empty (no settings version
/// mismatch detected).
void reportSettingsVersionMismatchString();
public Q_SLOTS:
/// Updates debug menu visibility (hides if disabled).
void updateDebugMenuVisibility();

View file

@ -680,8 +680,14 @@ void QtHostInterface::OnSystemStateSaved(bool global, s32 slot)
void QtHostInterface::LoadSettings()
{
m_settings_interface = std::make_unique<INISettingsInterface>(CommonHostInterface::GetSettingsFileName());
Log::SetConsoleOutputParams(true);
if (!CommonHostInterface::CheckSettings(*m_settings_interface.get()))
{
QTimer::singleShot(1000,
[this]() { ReportError("Settings version mismatch, settings have been reset to defaults."); });
}
CommonHostInterface::CheckSettings(*m_settings_interface.get());
CommonHostInterface::LoadSettings(*m_settings_interface.get());
CommonHostInterface::FixIncompatibleSettings(false);
}

View file

@ -47,10 +47,12 @@ public:
bool Initialize() override;
void Shutdown() override;
public Q_SLOTS:
void ReportError(const char* message) override;
void ReportMessage(const char* message) override;
bool ConfirmMessage(const char* message) override;
public:
/// Thread-safe settings access.
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override;
bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false) override;

View file

@ -1989,19 +1989,19 @@ std::string CommonHostInterface::GetMostRecentResumeSaveStatePath() const
return std::move(most_recent->FileName);
}
void CommonHostInterface::CheckSettings(SettingsInterface& si)
bool CommonHostInterface::CheckSettings(SettingsInterface& si)
{
const int settings_version = si.GetIntValue("Main", "SettingsVersion", -1);
if (settings_version == SETTINGS_VERSION)
return;
return true;
m_settings_version_mismatch_str = StringUtil::StdStringFromFormat(
"Settings version %d does not match expected version %d, resetting", settings_version, SETTINGS_VERSION);
ReportError(m_settings_version_mismatch_str.c_str());
Log_ErrorPrintf("Settings version %d does not match expected version %d, resetting", settings_version,
SETTINGS_VERSION);
si.Clear();
si.SetIntValue("Main", "SettingsVersion", SETTINGS_VERSION);
SetDefaultSettings(si);
return false;
}
void CommonHostInterface::SetDefaultSettings(SettingsInterface& si)
@ -2103,11 +2103,6 @@ void CommonHostInterface::CheckForSettingsChanges(const Settings& old_settings)
UpdateInputMap();
}
const std::string& CommonHostInterface::GetSettingsVersionMismatchString() const
{
return m_settings_version_mismatch_str;
}
void CommonHostInterface::SetTimerResolutionIncreased(bool enabled)
{
if (m_timer_resolution_increased == enabled)

View file

@ -174,10 +174,6 @@ public:
/// Reloads post processing shaders with the current configuration.
void ReloadPostProcessingShaders();
/// Returns an empty string if no settings version mismatch was detected, non-empty otherwise. Should not be called
/// before CheckSettings(SettingsInterface& si).
const std::string& GetSettingsVersionMismatchString() const;
protected:
enum : u32
{
@ -282,7 +278,7 @@ protected:
std::string GetCheatFileName() const;
/// Ensures the settings is valid and the correct version. If not, resets to defaults.
void CheckSettings(SettingsInterface& si);
bool CheckSettings(SettingsInterface& si);
/// Restores all settings to defaults.
virtual void SetDefaultSettings(SettingsInterface& si) override;
@ -375,8 +371,6 @@ private:
// running in batch mode? i.e. exit after stopping emulation
bool m_batch_mode = false;
std::string m_settings_version_mismatch_str;
#ifdef WITH_DISCORD_PRESENCE
// discord rich presence
bool m_discord_presence_enabled = false;