Browse Source

Merge pull request #15884 from Chocobo1/migrate

Migrate "setting key mappings" to upgrade code
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
781d7fbf1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/app/main.cpp
  2. 124
      src/app/upgrade.cpp
  3. 1
      src/app/upgrade.h
  4. 99
      src/base/settingsstorage.cpp

3
src/app/main.cpp

@ -188,7 +188,6 @@ int main(int argc, char *argv[])
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
if (!userAgreesWithLegalNotice()) if (!userAgreesWithLegalNotice())
return EXIT_SUCCESS; return EXIT_SUCCESS;
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
if (_isatty(_fileno(stdin)) if (_isatty(_fileno(stdin))
&& _isatty(_fileno(stdout)) && _isatty(_fileno(stdout))
@ -201,6 +200,8 @@ int main(int argc, char *argv[])
&& !userAgreesWithLegalNotice()) && !userAgreesWithLegalNotice())
return EXIT_SUCCESS; return EXIT_SUCCESS;
#endif #endif
setCurrentMigrationVersion();
} }
// Check if qBittorrent is already running for this user // Check if qBittorrent is already running for this user

124
src/app/upgrade.cpp

@ -29,7 +29,6 @@
#include "upgrade.h" #include "upgrade.h"
#include <QMetaEnum> #include <QMetaEnum>
#include <QVector>
#include "base/bittorrent/torrentcontentlayout.h" #include "base/bittorrent/torrentcontentlayout.h"
#include "base/logger.h" #include "base/logger.h"
@ -43,7 +42,8 @@
namespace namespace
{ {
const int MIGRATION_VERSION = 1; const int MIGRATION_VERSION = 2;
const char MIGRATION_VERSION_KEY[] = "Meta/MigrationVersion";
void exportWebUIHttpsFiles() void exportWebUIHttpsFiles()
{ {
@ -228,11 +228,109 @@ 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*/) bool upgrade(const bool /*ask*/)
{ {
CachedSettingValue<int> version {"Meta/MigrationVersion", 0}; CachedSettingValue<int> version {MIGRATION_VERSION_KEY, 0};
if (version != MIGRATION_VERSION) if (version != MIGRATION_VERSION)
{ {
@ -245,6 +343,8 @@ bool upgrade(const bool /*ask*/)
upgradeDNSServiceSettings(); upgradeDNSServiceSettings();
upgradeTrayIconStyleSettings(); upgradeTrayIconStyleSettings();
} }
if (version < 2)
migrateSettingKeys();
version = MIGRATION_VERSION; version = MIGRATION_VERSION;
} }
@ -252,6 +352,11 @@ bool upgrade(const bool /*ask*/)
return true; return true;
} }
void setCurrentMigrationVersion()
{
SettingsStorage::instance()->storeValue(QLatin1String(MIGRATION_VERSION_KEY), MIGRATION_VERSION);
}
void handleChangedDefaults(const DefaultPreferencesMode mode) void handleChangedDefaults(const DefaultPreferencesMode mode)
{ {
struct DefaultValue struct DefaultValue
@ -261,15 +366,18 @@ void handleChangedDefaults(const DefaultPreferencesMode mode)
QVariant current; QVariant current;
}; };
const QVector<DefaultValue> changedDefaults const DefaultValue changedDefaults[] =
{ {
{QLatin1String {"BitTorrent/Session/QueueingSystemEnabled"}, true, false} {QLatin1String {"BitTorrent/Session/QueueingSystemEnabled"}, true, false}
}; };
SettingsStorage *settingsStorage {SettingsStorage::instance()}; auto *settingsStorage = SettingsStorage::instance();
for (auto it = changedDefaults.cbegin(); it != changedDefaults.cend(); ++it) for (const DefaultValue &value : changedDefaults)
{ {
if (!settingsStorage->hasKey(it->name)) if (!settingsStorage->hasKey(value.name))
settingsStorage->storeValue(it->name, (mode == DefaultPreferencesMode::Legacy ? it->legacy : it->current)); {
settingsStorage->storeValue(value.name
, (mode == DefaultPreferencesMode::Legacy ? value.legacy : value.current));
}
} }
} }

1
src/app/upgrade.h

@ -36,3 +36,4 @@ enum class DefaultPreferencesMode
void handleChangedDefaults(DefaultPreferencesMode mode); void handleChangedDefaults(DefaultPreferencesMode mode);
bool upgrade(bool ask = true); bool upgrade(bool ask = true);
void setCurrentMigrationVersion();

99
src/base/settingsstorage.cpp

@ -64,90 +64,6 @@ namespace
const QString m_name; 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; SettingsStorage *SettingsStorage::m_instance = nullptr;
@ -200,17 +116,14 @@ bool SettingsStorage::save()
QVariant SettingsStorage::loadValueImpl(const QString &key, const QVariant &defaultValue) const QVariant SettingsStorage::loadValueImpl(const QString &key, const QVariant &defaultValue) const
{ {
const QString realKey = mapKey(key);
const QReadLocker locker(&m_lock); 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) void SettingsStorage::storeValueImpl(const QString &key, const QVariant &value)
{ {
const QString realKey = mapKey(key);
const QWriteLocker locker(&m_lock); const QWriteLocker locker(&m_lock);
QVariant &currentValue = m_data[key];
QVariant &currentValue = m_data[realKey];
if (currentValue != value) if (currentValue != value)
{ {
m_dirty = true; m_dirty = true;
@ -221,12 +134,11 @@ void SettingsStorage::storeValueImpl(const QString &key, const QVariant &value)
void SettingsStorage::removeValue(const QString &key) void SettingsStorage::removeValue(const QString &key)
{ {
const QString realKey = mapKey(key);
const QWriteLocker locker(&m_lock); const QWriteLocker locker(&m_lock);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (m_data.remove(realKey)) if (m_data.remove(key))
#else #else
if (m_data.remove(realKey) > 0) if (m_data.remove(key) > 0)
#endif #endif
{ {
m_dirty = true; m_dirty = true;
@ -236,9 +148,8 @@ void SettingsStorage::removeValue(const QString &key)
bool SettingsStorage::hasKey(const QString &key) const bool SettingsStorage::hasKey(const QString &key) const
{ {
const QString realKey = mapKey(key);
const QReadLocker locker {&m_lock}; const QReadLocker locker {&m_lock};
return m_data.contains(realKey); return m_data.contains(key);
} }
QVariantHash TransactionalSettings::read() const QVariantHash TransactionalSettings::read() const

Loading…
Cancel
Save