Browse Source

Migrate "setting key mappings" to upgrade code

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
39f054eef6
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 116
      src/app/upgrade.cpp
  2. 99
      src/base/settingsstorage.cpp

116
src/app/upgrade.cpp

@ -29,7 +29,6 @@ @@ -29,7 +29,6 @@
#include "upgrade.h"
#include <QMetaEnum>
#include <QVector>
#include "base/bittorrent/torrentcontentlayout.h"
#include "base/logger.h"
@ -43,7 +42,7 @@ @@ -43,7 +42,7 @@
namespace
{
const int MIGRATION_VERSION = 1;
const int MIGRATION_VERSION = 2;
void exportWebUIHttpsFiles()
{
@ -228,6 +227,104 @@ namespace @@ -228,6 +227,104 @@ namespace
}
}
}
void migrateSettingKeys()
{
struct KeyMapping
{
QString oldKey;
QString newKey;
};
const KeyMapping mappings[] =
{
{"AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog"},
{"AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded"},
{"AddNewTorrentDialog/Position", "AddNewTorrentDialog/y"},
{"AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history"},
{"AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront"},
{"AddNewTorrentDialog/TreeHeaderState", "AddNewTorrentDialog/qt5/treeHeaderState"},
{"AddNewTorrentDialog/Width", "AddNewTorrentDialog/width"},
{"BitTorrent/Session/AddExtensionToIncompleteFiles", "Preferences/Downloads/UseIncompleteExtension"},
{"BitTorrent/Session/AdditionalTrackers", "Preferences/Bittorrent/TrackersList"},
{"BitTorrent/Session/AddTorrentPaused", "Preferences/Downloads/StartInPause"},
{"BitTorrent/Session/AddTrackersEnabled", "Preferences/Bittorrent/AddTrackers"},
{"BitTorrent/Session/AlternativeGlobalDLSpeedLimit", "Preferences/Connection/GlobalDLLimitAlt"},
{"BitTorrent/Session/AlternativeGlobalUPSpeedLimit", "Preferences/Connection/GlobalUPLimitAlt"},
{"BitTorrent/Session/AnnounceIP", "Preferences/Connection/InetAddress"},
{"BitTorrent/Session/AnnounceToAllTrackers", "Preferences/Advanced/AnnounceToAllTrackers"},
{"BitTorrent/Session/AnonymousModeEnabled", "Preferences/Advanced/AnonymousMode"},
{"BitTorrent/Session/BandwidthSchedulerEnabled", "Preferences/Scheduler/Enabled"},
{"BitTorrent/Session/DefaultSavePath", "Preferences/Downloads/SavePath"},
{"BitTorrent/Session/DHTEnabled", "Preferences/Bittorrent/DHT"},
{"BitTorrent/Session/DiskCacheSize", "Preferences/Downloads/DiskWriteCacheSize"},
{"BitTorrent/Session/DiskCacheTTL", "Preferences/Downloads/DiskWriteCacheTTL"},
{"BitTorrent/Session/Encryption", "Preferences/Bittorrent/Encryption"},
{"BitTorrent/Session/FinishedTorrentExportDirectory", "Preferences/Downloads/FinishedTorrentExportDir"},
{"BitTorrent/Session/ForceProxy", "Preferences/Connection/ProxyForce"},
{"BitTorrent/Session/GlobalDLSpeedLimit", "Preferences/Connection/GlobalDLLimit"},
{"BitTorrent/Session/GlobalMaxRatio", "Preferences/Bittorrent/MaxRatio"},
{"BitTorrent/Session/GlobalUPSpeedLimit", "Preferences/Connection/GlobalUPLimit"},
{"BitTorrent/Session/IgnoreLimitsOnLAN", "Preferences/Advanced/IgnoreLimitsLAN"},
{"BitTorrent/Session/IgnoreSlowTorrentsForQueueing", "Preferences/Queueing/IgnoreSlowTorrents"},
{"BitTorrent/Session/IncludeOverheadInLimits", "Preferences/Advanced/IncludeOverhead"},
{"BitTorrent/Session/Interface", "Preferences/Connection/Interface"},
{"BitTorrent/Session/InterfaceAddress", "Preferences/Connection/InterfaceAddress"},
{"BitTorrent/Session/InterfaceName", "Preferences/Connection/InterfaceName"},
{"BitTorrent/Session/IPFilter", "Preferences/IPFilter/File"},
{"BitTorrent/Session/IPFilteringEnabled", "Preferences/IPFilter/Enabled"},
{"BitTorrent/Session/LSDEnabled", "Preferences/Bittorrent/LSD"},
{"BitTorrent/Session/MaxActiveDownloads", "Preferences/Queueing/MaxActiveDownloads"},
{"BitTorrent/Session/MaxActiveTorrents", "Preferences/Queueing/MaxActiveTorrents"},
{"BitTorrent/Session/MaxActiveUploads", "Preferences/Queueing/MaxActiveUploads"},
{"BitTorrent/Session/MaxConnections", "Preferences/Bittorrent/MaxConnecs"},
{"BitTorrent/Session/MaxConnectionsPerTorrent", "Preferences/Bittorrent/MaxConnecsPerTorrent"},
{"BitTorrent/Session/MaxHalfOpenConnections", "Preferences/Connection/MaxHalfOpenConnec"},
{"BitTorrent/Session/MaxRatioAction", "Preferences/Bittorrent/MaxRatioAction"},
{"BitTorrent/Session/MaxUploads", "Preferences/Bittorrent/MaxUploads"},
{"BitTorrent/Session/MaxUploadsPerTorrent", "Preferences/Bittorrent/MaxUploadsPerTorrent"},
{"BitTorrent/Session/OutgoingPortsMax", "Preferences/Advanced/OutgoingPortsMax"},
{"BitTorrent/Session/OutgoingPortsMin", "Preferences/Advanced/OutgoingPortsMin"},
{"BitTorrent/Session/PeXEnabled", "Preferences/Bittorrent/PeX"},
{"BitTorrent/Session/Port", "Preferences/Connection/PortRangeMin"},
{"BitTorrent/Session/Preallocation", "Preferences/Downloads/PreAllocation"},
{"BitTorrent/Session/ProxyPeerConnections", "Preferences/Connection/ProxyPeerConnections"},
{"BitTorrent/Session/QueueingSystemEnabled", "Preferences/Queueing/QueueingEnabled"},
{"BitTorrent/Session/RefreshInterval", "Preferences/General/RefreshInterval"},
{"BitTorrent/Session/SaveResumeDataInterval", "Preferences/Downloads/SaveResumeDataInterval"},
{"BitTorrent/Session/SuperSeedingEnabled", "Preferences/Advanced/SuperSeeding"},
{"BitTorrent/Session/TempPath", "Preferences/Downloads/TempPath"},
{"BitTorrent/Session/TempPathEnabled", "Preferences/Downloads/TempPathEnabled"},
{"BitTorrent/Session/TorrentExportDirectory", "Preferences/Downloads/TorrentExportDir"},
{"BitTorrent/Session/TrackerFilteringEnabled", "Preferences/IPFilter/FilterTracker"},
{"BitTorrent/Session/UseAlternativeGlobalSpeedLimit", "Preferences/Connection/alt_speeds_on"},
{"BitTorrent/Session/UseOSCache", "Preferences/Advanced/osCache"},
{"BitTorrent/Session/UseRandomPort", "Preferences/General/UseRandomPort"},
{"BitTorrent/Session/uTPEnabled", "Preferences/Bittorrent/uTP"},
{"BitTorrent/Session/uTPRateLimited", "Preferences/Bittorrent/uTP_rate_limited"},
{"BitTorrent/TrackerEnabled", "Preferences/Advanced/trackerEnabled"},
{"Network/PortForwardingEnabled", "Preferences/Connection/UPnP"},
{"Network/Proxy/Authentication", "Preferences/Connection/Proxy/Authentication"},
{"Network/Proxy/IP", "Preferences/Connection/Proxy/IP"},
{"Network/Proxy/OnlyForTorrents", "Preferences/Connection/ProxyOnlyForTorrents"},
{"Network/Proxy/Password", "Preferences/Connection/Proxy/Password"},
{"Network/Proxy/Port", "Preferences/Connection/Proxy/Port"},
{"Network/Proxy/Type", "Preferences/Connection/ProxyType"},
{"Network/Proxy/Username", "Preferences/Connection/Proxy/Username"},
{"State/BannedIPs", "Preferences/IPFilter/BannedIPs"}
};
auto *settingsStorage = SettingsStorage::instance();
for (const KeyMapping &mapping : mappings)
{
if (settingsStorage->hasKey(mapping.oldKey))
{
const auto value = settingsStorage->loadValue<QVariant>(mapping.oldKey);
settingsStorage->storeValue(mapping.newKey, value);
settingsStorage->removeValue(mapping.oldKey);
}
}
}
}
bool upgrade(const bool /*ask*/)
@ -245,6 +342,8 @@ bool upgrade(const bool /*ask*/) @@ -245,6 +342,8 @@ bool upgrade(const bool /*ask*/)
upgradeDNSServiceSettings();
upgradeTrayIconStyleSettings();
}
if (version < 2)
migrateSettingKeys();
version = MIGRATION_VERSION;
}
@ -261,15 +360,18 @@ void handleChangedDefaults(const DefaultPreferencesMode mode) @@ -261,15 +360,18 @@ void handleChangedDefaults(const DefaultPreferencesMode mode)
QVariant current;
};
const QVector<DefaultValue> changedDefaults
const DefaultValue changedDefaults[] =
{
{QLatin1String {"BitTorrent/Session/QueueingSystemEnabled"}, true, false}
};
SettingsStorage *settingsStorage {SettingsStorage::instance()};
for (auto it = changedDefaults.cbegin(); it != changedDefaults.cend(); ++it)
auto *settingsStorage = SettingsStorage::instance();
for (const DefaultValue &value : changedDefaults)
{
if (!settingsStorage->hasKey(it->name))
settingsStorage->storeValue(it->name, (mode == DefaultPreferencesMode::Legacy ? it->legacy : it->current));
if (!settingsStorage->hasKey(value.name))
{
settingsStorage->storeValue(value.name
, (mode == DefaultPreferencesMode::Legacy ? value.legacy : value.current));
}
}
}

99
src/base/settingsstorage.cpp

@ -64,90 +64,6 @@ namespace @@ -64,90 +64,6 @@ namespace
const QString m_name;
};
QString mapKey(const QString &key)
{
static const QHash<QString, QString> keyMapping =
{
{"BitTorrent/Session/MaxRatioAction", "Preferences/Bittorrent/MaxRatioAction"},
{"BitTorrent/Session/DefaultSavePath", "Preferences/Downloads/SavePath"},
{"BitTorrent/Session/TempPath", "Preferences/Downloads/TempPath"},
{"BitTorrent/Session/TempPathEnabled", "Preferences/Downloads/TempPathEnabled"},
{"BitTorrent/Session/AddTorrentPaused", "Preferences/Downloads/StartInPause"},
{"BitTorrent/Session/RefreshInterval", "Preferences/General/RefreshInterval"},
{"BitTorrent/Session/Preallocation", "Preferences/Downloads/PreAllocation"},
{"BitTorrent/Session/AddExtensionToIncompleteFiles", "Preferences/Downloads/UseIncompleteExtension"},
{"BitTorrent/Session/TorrentExportDirectory", "Preferences/Downloads/TorrentExportDir"},
{"BitTorrent/Session/FinishedTorrentExportDirectory", "Preferences/Downloads/FinishedTorrentExportDir"},
{"BitTorrent/Session/GlobalUPSpeedLimit", "Preferences/Connection/GlobalUPLimit"},
{"BitTorrent/Session/GlobalDLSpeedLimit", "Preferences/Connection/GlobalDLLimit"},
{"BitTorrent/Session/AlternativeGlobalUPSpeedLimit", "Preferences/Connection/GlobalUPLimitAlt"},
{"BitTorrent/Session/AlternativeGlobalDLSpeedLimit", "Preferences/Connection/GlobalDLLimitAlt"},
{"BitTorrent/Session/UseAlternativeGlobalSpeedLimit", "Preferences/Connection/alt_speeds_on"},
{"BitTorrent/Session/BandwidthSchedulerEnabled", "Preferences/Scheduler/Enabled"},
{"BitTorrent/Session/Port", "Preferences/Connection/PortRangeMin"},
{"BitTorrent/Session/UseRandomPort", "Preferences/General/UseRandomPort"},
{"BitTorrent/Session/Interface", "Preferences/Connection/Interface"},
{"BitTorrent/Session/InterfaceName", "Preferences/Connection/InterfaceName"},
{"BitTorrent/Session/InterfaceAddress", "Preferences/Connection/InterfaceAddress"},
{"BitTorrent/Session/SaveResumeDataInterval", "Preferences/Downloads/SaveResumeDataInterval"},
{"BitTorrent/Session/Encryption", "Preferences/Bittorrent/Encryption"},
{"BitTorrent/Session/ForceProxy", "Preferences/Connection/ProxyForce"},
{"BitTorrent/Session/ProxyPeerConnections", "Preferences/Connection/ProxyPeerConnections"},
{"BitTorrent/Session/MaxConnections", "Preferences/Bittorrent/MaxConnecs"},
{"BitTorrent/Session/MaxUploads", "Preferences/Bittorrent/MaxUploads"},
{"BitTorrent/Session/MaxConnectionsPerTorrent", "Preferences/Bittorrent/MaxConnecsPerTorrent"},
{"BitTorrent/Session/MaxUploadsPerTorrent", "Preferences/Bittorrent/MaxUploadsPerTorrent"},
{"BitTorrent/Session/DHTEnabled", "Preferences/Bittorrent/DHT"},
{"BitTorrent/Session/LSDEnabled", "Preferences/Bittorrent/LSD"},
{"BitTorrent/Session/PeXEnabled", "Preferences/Bittorrent/PeX"},
{"BitTorrent/Session/AddTrackersEnabled", "Preferences/Bittorrent/AddTrackers"},
{"BitTorrent/Session/AdditionalTrackers", "Preferences/Bittorrent/TrackersList"},
{"BitTorrent/Session/IPFilteringEnabled", "Preferences/IPFilter/Enabled"},
{"BitTorrent/Session/TrackerFilteringEnabled", "Preferences/IPFilter/FilterTracker"},
{"BitTorrent/Session/IPFilter", "Preferences/IPFilter/File"},
{"BitTorrent/Session/GlobalMaxRatio", "Preferences/Bittorrent/MaxRatio"},
{"BitTorrent/Session/AnnounceToAllTrackers", "Preferences/Advanced/AnnounceToAllTrackers"},
{"BitTorrent/Session/DiskCacheSize", "Preferences/Downloads/DiskWriteCacheSize"},
{"BitTorrent/Session/DiskCacheTTL", "Preferences/Downloads/DiskWriteCacheTTL"},
{"BitTorrent/Session/UseOSCache", "Preferences/Advanced/osCache"},
{"BitTorrent/Session/AnonymousModeEnabled", "Preferences/Advanced/AnonymousMode"},
{"BitTorrent/Session/QueueingSystemEnabled", "Preferences/Queueing/QueueingEnabled"},
{"BitTorrent/Session/MaxActiveDownloads", "Preferences/Queueing/MaxActiveDownloads"},
{"BitTorrent/Session/MaxActiveUploads", "Preferences/Queueing/MaxActiveUploads"},
{"BitTorrent/Session/MaxActiveTorrents", "Preferences/Queueing/MaxActiveTorrents"},
{"BitTorrent/Session/IgnoreSlowTorrentsForQueueing", "Preferences/Queueing/IgnoreSlowTorrents"},
{"BitTorrent/Session/OutgoingPortsMin", "Preferences/Advanced/OutgoingPortsMin"},
{"BitTorrent/Session/OutgoingPortsMax", "Preferences/Advanced/OutgoingPortsMax"},
{"BitTorrent/Session/IgnoreLimitsOnLAN", "Preferences/Advanced/IgnoreLimitsLAN"},
{"BitTorrent/Session/IncludeOverheadInLimits", "Preferences/Advanced/IncludeOverhead"},
{"BitTorrent/Session/AnnounceIP", "Preferences/Connection/InetAddress"},
{"BitTorrent/Session/SuperSeedingEnabled", "Preferences/Advanced/SuperSeeding"},
{"BitTorrent/Session/MaxHalfOpenConnections", "Preferences/Connection/MaxHalfOpenConnec"},
{"BitTorrent/Session/uTPEnabled", "Preferences/Bittorrent/uTP"},
{"BitTorrent/Session/uTPRateLimited", "Preferences/Bittorrent/uTP_rate_limited"},
{"BitTorrent/TrackerEnabled", "Preferences/Advanced/trackerEnabled"},
{"Network/Proxy/OnlyForTorrents", "Preferences/Connection/ProxyOnlyForTorrents"},
{"Network/Proxy/Type", "Preferences/Connection/ProxyType"},
{"Network/Proxy/Authentication", "Preferences/Connection/Proxy/Authentication"},
{"Network/Proxy/Username", "Preferences/Connection/Proxy/Username"},
{"Network/Proxy/Password", "Preferences/Connection/Proxy/Password"},
{"Network/Proxy/IP", "Preferences/Connection/Proxy/IP"},
{"Network/Proxy/Port", "Preferences/Connection/Proxy/Port"},
{"Network/PortForwardingEnabled", "Preferences/Connection/UPnP"},
{"AddNewTorrentDialog/TreeHeaderState", "AddNewTorrentDialog/qt5/treeHeaderState"},
{"AddNewTorrentDialog/Width", "AddNewTorrentDialog/width"},
{"AddNewTorrentDialog/Position", "AddNewTorrentDialog/y"},
{"AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded"},
{"AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history"},
{"AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog"},
{"AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront"},
{"State/BannedIPs", "Preferences/IPFilter/BannedIPs"}
};
return keyMapping.value(key, key);
}
}
SettingsStorage *SettingsStorage::m_instance = nullptr;
@ -200,17 +116,14 @@ bool SettingsStorage::save() @@ -200,17 +116,14 @@ bool SettingsStorage::save()
QVariant SettingsStorage::loadValueImpl(const QString &key, const QVariant &defaultValue) const
{
const QString realKey = mapKey(key);
const QReadLocker locker(&m_lock);
return m_data.value(realKey, defaultValue);
return m_data.value(key, defaultValue);
}
void SettingsStorage::storeValueImpl(const QString &key, const QVariant &value)
{
const QString realKey = mapKey(key);
const QWriteLocker locker(&m_lock);
QVariant &currentValue = m_data[realKey];
QVariant &currentValue = m_data[key];
if (currentValue != value)
{
m_dirty = true;
@ -221,12 +134,11 @@ void SettingsStorage::storeValueImpl(const QString &key, const QVariant &value) @@ -221,12 +134,11 @@ void SettingsStorage::storeValueImpl(const QString &key, const QVariant &value)
void SettingsStorage::removeValue(const QString &key)
{
const QString realKey = mapKey(key);
const QWriteLocker locker(&m_lock);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (m_data.remove(realKey))
if (m_data.remove(key))
#else
if (m_data.remove(realKey) > 0)
if (m_data.remove(key) > 0)
#endif
{
m_dirty = true;
@ -236,9 +148,8 @@ void SettingsStorage::removeValue(const QString &key) @@ -236,9 +148,8 @@ void SettingsStorage::removeValue(const QString &key)
bool SettingsStorage::hasKey(const QString &key) const
{
const QString realKey = mapKey(key);
const QReadLocker locker {&m_lock};
return m_data.contains(realKey);
return m_data.contains(key);
}
QVariantHash TransactionalSettings::read() const

Loading…
Cancel
Save