From a828b54be4a3753a07b84a399c66ab529e3611bf Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Wed, 9 Feb 2022 20:20:32 -0800 Subject: [PATCH] refactor(Paths): Remove portable state from Settings It now duplicates the state in Paths where it is needed, creating the chance for desync --- src/persistence/settings.cpp | 19 ++++++++----------- src/persistence/settings.h | 1 - 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index f4c27f35f..18ac3b86c 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -65,7 +65,6 @@ QThread* Settings::settingsThread{nullptr}; Settings::Settings() : loaded(false) , useCustomDhtList{false} - , makeToxPortable{false} , currentProfileId(0) { settingsThread = new QThread(); @@ -159,7 +158,7 @@ void Settings::loadGlobal() s.beginGroup("Advanced"); { - makeToxPortable = s.value("makeToxPortable", false).toBool(); + paths.setPortable(s.value("makeToxPortable", false).toBool()); enableIPv6 = s.value("enableIPv6", true).toBool(); forceTCP = s.value("forceTCP", false).toBool(); enableLanDiscovery = s.value("enableLanDiscovery", true).toBool(); @@ -623,7 +622,7 @@ void Settings::saveGlobal() s.beginGroup("Advanced"); { - s.setValue("makeToxPortable", makeToxPortable); + s.setValue("makeToxPortable", paths.isPortable()); s.setValue("enableIPv6", enableIPv6); s.setValue("forceTCP", forceTCP); s.setValue("enableLanDiscovery", enableLanDiscovery); @@ -864,7 +863,7 @@ void Settings::setEnableIPv6(bool enabled) bool Settings::getMakeToxPortable() const { QMutexLocker locker{&bigLock}; - return makeToxPortable; + return paths.isPortable(); } void Settings::setMakeToxPortable(bool newValue) @@ -872,16 +871,14 @@ void Settings::setMakeToxPortable(bool newValue) bool changed = false; { QMutexLocker locker{&bigLock}; - if (newValue != makeToxPortable) { - QFile(paths.getSettingsDirPath() + globalSettingsFile).remove(); - makeToxPortable = newValue; - changed = paths.setPortable(newValue); + auto const oldSettingsPath = paths.getSettingsDirPath() + globalSettingsFile; + changed = paths.setPortable(newValue); + if (changed) { + QFile(oldSettingsPath).remove(); saveGlobal(); + emit makeToxPortableChanged(newValue); } } - if (changed) { - emit makeToxPortableChanged(newValue); - } } bool Settings::getAutorun() const diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 3fe48c106..2ea53b461 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -595,7 +595,6 @@ private: bool showIdenticons; bool enableIPv6; QString translation; - bool makeToxPortable; bool autostartInTray; bool closeToTray; bool minimizeToTray;