From 96fa0919be58b015676c54469b7eaff520ee5c56 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 27 Dec 2021 19:09:47 +0100 Subject: [PATCH] Config: Port AutoUpdate settings to new config system. --- Source/Core/Core/Config/MainSettings.cpp | 8 ++++++++ Source/Core/Core/Config/MainSettings.h | 5 +++++ .../Core/ConfigLoaders/IsSettingSaveable.cpp | 2 +- Source/Core/Core/ConfigManager.cpp | 18 ------------------ Source/Core/Core/ConfigManager.h | 6 ------ Source/Core/Core/DolphinAnalytics.cpp | 2 +- Source/Core/DolphinQt/Main.cpp | 3 ++- Source/Core/DolphinQt/MenuBar.cpp | 10 ++-------- Source/Core/DolphinQt/Settings.cpp | 4 ++-- Source/Core/DolphinQt/Updater.cpp | 10 +++++++--- Source/Core/DolphinQt/Updater.h | 6 +++++- Source/Core/UICommon/AutoUpdate.cpp | 19 +++++++++---------- Source/Core/UICommon/AutoUpdate.h | 3 ++- 13 files changed, 44 insertions(+), 52 deletions(-) diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index d0b5a1ab01..9cb6a71266 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -7,6 +7,7 @@ #include "AudioCommon/AudioCommon.h" #include "Common/Config/Config.h" +#include "Common/Version.h" #include "Core/Config/DefaultLocale.h" #include "Core/HW/EXI/EXI_Device.h" #include "Core/HW/Memmap.h" @@ -252,4 +253,11 @@ const Info MAIN_GAMELIST_COLUMN_TAGS{{System::Main, "GameList", "ColumnTag const Info MAIN_FIFOPLAYER_LOOP_REPLAY{{System::Main, "FifoPlayer", "LoopReplay"}, true}; +// Main.AutoUpdate + +const Info MAIN_AUTOUPDATE_UPDATE_TRACK{{System::Main, "AutoUpdate", "UpdateTrack"}, + Common::scm_update_track_str}; +const Info MAIN_AUTOUPDATE_HASH_OVERRIDE{{System::Main, "AutoUpdate", "HashOverride"}, + ""}; + } // namespace Config diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 91816519e7..60706765a0 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -215,4 +215,9 @@ extern const Info MAIN_GAMELIST_COLUMN_TAGS; extern const Info MAIN_FIFOPLAYER_LOOP_REPLAY; +// Main.AutoUpdate + +extern const Info MAIN_AUTOUPDATE_UPDATE_TRACK; +extern const Info MAIN_AUTOUPDATE_HASH_OVERRIDE; + } // namespace Config diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 7756df6f7d..8bb37908a4 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -27,7 +27,7 @@ bool IsSettingSaveable(const Config::Location& config_location) { for (const std::string_view section : {"NetPlay", "General", "GBA", "Display", "Network", "Analytics", "AndroidOverlayButtons", - "DSP", "GameList", "FifoPlayer"}) + "DSP", "GameList", "FifoPlayer", "AutoUpdate"}) { if (config_location.section == section) return true; diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index cda80e9884..6124deb877 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -95,7 +95,6 @@ void SConfig::SaveSettings() SaveInputSettings(ini); SaveBluetoothPassthroughSettings(ini); SaveUSBPassthroughSettings(ini); - SaveAutoUpdateSettings(ini); SaveJitDebugSettings(ini); ini.Save(File::GetUserPath(F_DOLPHINCONFIG_IDX)); @@ -244,14 +243,6 @@ void SConfig::SaveUSBPassthroughSettings(IniFile& ini) section->Set("Devices", devices_string); } -void SConfig::SaveAutoUpdateSettings(IniFile& ini) -{ - IniFile::Section* section = ini.GetOrCreateSection("AutoUpdate"); - - section->Set("UpdateTrack", m_auto_update_track); - section->Set("HashOverride", m_auto_update_hash_override); -} - void SConfig::SaveJitDebugSettings(IniFile& ini) { IniFile::Section* section = ini.GetOrCreateSection("Debug"); @@ -283,7 +274,6 @@ void SConfig::LoadSettings() LoadInputSettings(ini); LoadBluetoothPassthroughSettings(ini); LoadUSBPassthroughSettings(ini); - LoadAutoUpdateSettings(ini); LoadJitDebugSettings(ini); } @@ -442,14 +432,6 @@ void SConfig::LoadUSBPassthroughSettings(IniFile& ini) } } -void SConfig::LoadAutoUpdateSettings(IniFile& ini) -{ - IniFile::Section* section = ini.GetOrCreateSection("AutoUpdate"); - - section->Get("UpdateTrack", &m_auto_update_track, Common::scm_update_track_str); - section->Get("HashOverride", &m_auto_update_hash_override, ""); -} - void SConfig::LoadJitDebugSettings(IniFile& ini) { IniFile::Section* section = ini.GetOrCreateSection("Debug"); diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 5fc2669637..51ec5d2a40 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -241,10 +241,6 @@ struct SConfig bool m_AdapterRumble[4]; bool m_AdapterKonga[4]; - // Auto-update settings - std::string m_auto_update_track; - std::string m_auto_update_hash_override; - SConfig(const SConfig&) = delete; SConfig& operator=(const SConfig&) = delete; SConfig(SConfig&&) = delete; @@ -272,7 +268,6 @@ private: void SaveMovieSettings(IniFile& ini); void SaveBluetoothPassthroughSettings(IniFile& ini); void SaveUSBPassthroughSettings(IniFile& ini); - void SaveAutoUpdateSettings(IniFile& ini); void SaveJitDebugSettings(IniFile& ini); void LoadGeneralSettings(IniFile& ini); @@ -282,7 +277,6 @@ private: void LoadMovieSettings(IniFile& ini); void LoadBluetoothPassthroughSettings(IniFile& ini); void LoadUSBPassthroughSettings(IniFile& ini); - void LoadAutoUpdateSettings(IniFile& ini); void LoadJitDebugSettings(IniFile& ini); void SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id, diff --git a/Source/Core/Core/DolphinAnalytics.cpp b/Source/Core/Core/DolphinAnalytics.cpp index e780f21685..6ef1109cb4 100644 --- a/Source/Core/Core/DolphinAnalytics.cpp +++ b/Source/Core/Core/DolphinAnalytics.cpp @@ -254,7 +254,7 @@ void DolphinAnalytics::MakeBaseBuilder() builder.AddData("version-dist", Common::scm_distributor_str); // Auto-Update information. - builder.AddData("update-track", SConfig::GetInstance().m_auto_update_track); + builder.AddData("update-track", Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK)); // CPU information. builder.AddData("cpu-summary", cpu_info.Summarize()); diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp index 9c05198ca7..507765a143 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -286,7 +286,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine if (!Settings::Instance().IsBatchModeEnabled()) { - auto* updater = new Updater(&win); + auto* updater = new Updater(&win, Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK), + Config::Get(Config::MAIN_AUTOUPDATE_HASH_OVERRIDE)); updater->start(); } diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp index bfc29d26e3..c3d303044c 100644 --- a/Source/Core/DolphinQt/MenuBar.cpp +++ b/Source/Core/DolphinQt/MenuBar.cpp @@ -548,12 +548,8 @@ void MenuBar::AddOptionsMenu() void MenuBar::InstallUpdateManually() { - auto& track = SConfig::GetInstance().m_auto_update_track; - auto previous_value = track; - - track = "dev"; - - auto* updater = new Updater(this->parentWidget()); + auto* updater = + new Updater(this->parentWidget(), "dev", Config::Get(Config::MAIN_AUTOUPDATE_HASH_OVERRIDE)); if (!updater->CheckForUpdate()) { @@ -561,8 +557,6 @@ void MenuBar::InstallUpdateManually() this, tr("Update"), tr("You are running the latest version available on this update track.")); } - - track = previous_value; } void MenuBar::AddHelpMenu() diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index 7e91064a25..6c6050bf73 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -614,14 +614,14 @@ void Settings::SetAutoUpdateTrack(const QString& mode) if (mode == GetAutoUpdateTrack()) return; - SConfig::GetInstance().m_auto_update_track = mode.toStdString(); + Config::SetBase(Config::MAIN_AUTOUPDATE_UPDATE_TRACK, mode.toStdString()); emit AutoUpdateTrackChanged(mode); } QString Settings::GetAutoUpdateTrack() const { - return QString::fromStdString(SConfig::GetInstance().m_auto_update_track); + return QString::fromStdString(Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK)); } void Settings::SetFallbackRegion(const DiscIO::Region& region) diff --git a/Source/Core/DolphinQt/Updater.cpp b/Source/Core/DolphinQt/Updater.cpp index b3204474c3..9388175a65 100644 --- a/Source/Core/DolphinQt/Updater.cpp +++ b/Source/Core/DolphinQt/Updater.cpp @@ -3,6 +3,8 @@ #include "DolphinQt/Updater.h" +#include + #include #include #include @@ -18,20 +20,22 @@ // Refer to docs/autoupdate_overview.md for a detailed overview of the autoupdate process -Updater::Updater(QWidget* parent) : m_parent(parent) +Updater::Updater(QWidget* parent, std::string update_track, std::string hash_override) + : m_parent(parent), m_update_track(std::move(update_track)), + m_hash_override(std::move(hash_override)) { connect(this, &QThread::finished, this, &QObject::deleteLater); } void Updater::run() { - AutoUpdateChecker::CheckForUpdate(); + AutoUpdateChecker::CheckForUpdate(m_update_track, m_hash_override); } bool Updater::CheckForUpdate() { m_update_available = false; - AutoUpdateChecker::CheckForUpdate(); + AutoUpdateChecker::CheckForUpdate(m_update_track, m_hash_override); return m_update_available; } diff --git a/Source/Core/DolphinQt/Updater.h b/Source/Core/DolphinQt/Updater.h index 84df3a8aec..a725e2019b 100644 --- a/Source/Core/DolphinQt/Updater.h +++ b/Source/Core/DolphinQt/Updater.h @@ -3,6 +3,8 @@ #pragma once +#include + #include #include "UICommon/AutoUpdate.h" @@ -15,7 +17,7 @@ class Updater : public QThread, public AutoUpdateChecker { Q_OBJECT public: - explicit Updater(QWidget* parent); + explicit Updater(QWidget* parent, std::string update_track, std::string hash_override); void run() override; void OnUpdateAvailable(const NewVersionInformation& info) override; @@ -23,5 +25,7 @@ public: private: QWidget* m_parent; + std::string m_update_track; + std::string m_hash_override; bool m_update_available = false; }; diff --git a/Source/Core/UICommon/AutoUpdate.cpp b/Source/Core/UICommon/AutoUpdate.cpp index 27ccda4c26..ce316758b0 100644 --- a/Source/Core/UICommon/AutoUpdate.cpp +++ b/Source/Core/UICommon/AutoUpdate.cpp @@ -3,16 +3,17 @@ #include "UICommon/AutoUpdate.h" -#include #include +#include +#include + #include "Common/CommonPaths.h" #include "Common/FileUtil.h" #include "Common/HttpRequest.h" #include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "Common/Version.h" -#include "Core/ConfigManager.h" #ifdef _WIN32 #include @@ -149,22 +150,20 @@ static std::string GetPlatformID() #endif } -void AutoUpdateChecker::CheckForUpdate() +void AutoUpdateChecker::CheckForUpdate(std::string_view update_track, + std::string_view hash_override) { // Don't bother checking if updates are not supported or not enabled. - if (!SystemSupportsAutoUpdates() || SConfig::GetInstance().m_auto_update_track.empty()) + if (!SystemSupportsAutoUpdates() || update_track.empty()) return; #ifdef OS_SUPPORTS_UPDATER CleanupFromPreviousUpdate(); #endif - std::string version_hash = SConfig::GetInstance().m_auto_update_hash_override.empty() ? - Common::scm_rev_git_str : - SConfig::GetInstance().m_auto_update_hash_override; - std::string url = "https://dolphin-emu.org/update/check/v1/" + - SConfig::GetInstance().m_auto_update_track + "/" + version_hash + "/" + - GetPlatformID(); + std::string_view version_hash = hash_override.empty() ? Common::scm_rev_git_str : hash_override; + std::string url = fmt::format("https://dolphin-emu.org/update/check/v1/{}/{}/{}", update_track, + version_hash, GetPlatformID()); Common::HttpRequest req{std::chrono::seconds{10}}; auto resp = req.Get(url); diff --git a/Source/Core/UICommon/AutoUpdate.h b/Source/Core/UICommon/AutoUpdate.h index 516e40b7b7..d46b82b9ae 100644 --- a/Source/Core/UICommon/AutoUpdate.h +++ b/Source/Core/UICommon/AutoUpdate.h @@ -4,6 +4,7 @@ #pragma once #include +#include // Refer to docs/autoupdate_overview.md for a detailed overview of the autoupdate process @@ -14,7 +15,7 @@ class AutoUpdateChecker public: // Initiates a check for updates in the background. Calls the OnUpdateAvailable callback if an // update is available, does "nothing" otherwise. - void CheckForUpdate(); + void CheckForUpdate(std::string_view update_track, std::string_view hash_override); static bool SystemSupportsAutoUpdates();