50 const auto migrate = [](
const QString &oldKey,
const QString &newKey,
const QString &savePath)
53 const auto oldData {settingsStorage->
loadValue<QByteArray>(oldKey)};
54 const auto newData {settingsStorage->loadValue<QString>(newKey)};
55 const QString errorMsgFormat {QObject::tr(
"Migrate preferences failed: WebUI https, file: \"%1\", error: \"%2\"")};
57 if (!newData.isEmpty() || oldData.isEmpty())
67 settingsStorage->storeValue(newKey, savePath);
68 settingsStorage->removeValue(oldKey);
70 LogMsg(QObject::tr(
"Migrated preferences: WebUI https, exported data to file: \"%1\"").arg(savePath)
75 migrate(QLatin1String(
"Preferences/WebUI/HTTPS/Certificate")
76 , QLatin1String(
"Preferences/WebUI/HTTPS/CertificatePath")
78 migrate(QLatin1String(
"Preferences/WebUI/HTTPS/Key")
79 , QLatin1String(
"Preferences/WebUI/HTTPS/KeyPath")
85 const QString oldKey {QLatin1String {
"BitTorrent/Session/CreateTorrentSubfolder"}};
86 const QString newKey {QLatin1String {
"BitTorrent/Session/TorrentContentLayout"}};
89 const auto oldData {settingsStorage->
loadValue<QVariant>(oldKey)};
90 const auto newData {settingsStorage->loadValue<QString>(newKey)};
92 if (!newData.isEmpty() || !oldData.isValid())
95 const bool createSubfolder = oldData.toBool();
97 (createSubfolder ? BitTorrent::TorrentContentLayout::Original : BitTorrent::TorrentContentLayout::NoSubfolder);
100 settingsStorage->removeValue(oldKey);
105 const auto oldKey = QString::fromLatin1(
"BitTorrent/Session/UseRandomPort");
106 const auto newKey = QString::fromLatin1(
"Preferences/Connection/PortRangeMin");
109 if (settingsStorage->hasKey(oldKey))
111 if (settingsStorage->loadValue<
bool>(oldKey))
112 settingsStorage->storeValue(newKey, 0);
114 settingsStorage->removeValue(oldKey);
121 const auto key = QString::fromLatin1(
"Preferences/Scheduler/days");
122 const auto value = settingsStorage->loadValue<QString>(key);
125 const auto number =
value.toInt(&ok);
162 LogMsg(QObject::tr(
"Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
164 settingsStorage->removeValue(key);
173 const auto key = QString::fromLatin1(
"Preferences/DynDNS/Service");
174 const auto value = settingsStorage->loadValue<QString>(key);
177 const auto number =
value.toInt(&ok);
193 LogMsg(QObject::tr(
"Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
195 settingsStorage->removeValue(key);
204 const auto key = QString::fromLatin1(
"Preferences/Advanced/TrayIconStyle");
205 const auto value = settingsStorage->loadValue<QString>(key);
208 const auto number =
value.toInt(&ok);
224 LogMsg(QObject::tr(
"Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
226 settingsStorage->removeValue(key);
240 const KeyMapping mappings[] =
242 {
"AddNewTorrentDialog/Enabled",
"Preferences/Downloads/NewAdditionDialog"},
243 {
"AddNewTorrentDialog/Expanded",
"AddNewTorrentDialog/expanded"},
244 {
"AddNewTorrentDialog/Position",
"AddNewTorrentDialog/y"},
245 {
"AddNewTorrentDialog/SavePathHistory",
"TorrentAdditionDlg/save_path_history"},
246 {
"AddNewTorrentDialog/TopLevel",
"Preferences/Downloads/NewAdditionDialogFront"},
247 {
"AddNewTorrentDialog/TreeHeaderState",
"AddNewTorrentDialog/qt5/treeHeaderState"},
248 {
"AddNewTorrentDialog/Width",
"AddNewTorrentDialog/width"},
249 {
"BitTorrent/Session/AddExtensionToIncompleteFiles",
"Preferences/Downloads/UseIncompleteExtension"},
250 {
"BitTorrent/Session/AdditionalTrackers",
"Preferences/Bittorrent/TrackersList"},
251 {
"BitTorrent/Session/AddTorrentPaused",
"Preferences/Downloads/StartInPause"},
252 {
"BitTorrent/Session/AddTrackersEnabled",
"Preferences/Bittorrent/AddTrackers"},
253 {
"BitTorrent/Session/AlternativeGlobalDLSpeedLimit",
"Preferences/Connection/GlobalDLLimitAlt"},
254 {
"BitTorrent/Session/AlternativeGlobalUPSpeedLimit",
"Preferences/Connection/GlobalUPLimitAlt"},
255 {
"BitTorrent/Session/AnnounceIP",
"Preferences/Connection/InetAddress"},
256 {
"BitTorrent/Session/AnnounceToAllTrackers",
"Preferences/Advanced/AnnounceToAllTrackers"},
257 {
"BitTorrent/Session/AnonymousModeEnabled",
"Preferences/Advanced/AnonymousMode"},
258 {
"BitTorrent/Session/BandwidthSchedulerEnabled",
"Preferences/Scheduler/Enabled"},
259 {
"BitTorrent/Session/DefaultSavePath",
"Preferences/Downloads/SavePath"},
260 {
"BitTorrent/Session/DHTEnabled",
"Preferences/Bittorrent/DHT"},
261 {
"BitTorrent/Session/DiskCacheSize",
"Preferences/Downloads/DiskWriteCacheSize"},
262 {
"BitTorrent/Session/DiskCacheTTL",
"Preferences/Downloads/DiskWriteCacheTTL"},
263 {
"BitTorrent/Session/Encryption",
"Preferences/Bittorrent/Encryption"},
264 {
"BitTorrent/Session/FinishedTorrentExportDirectory",
"Preferences/Downloads/FinishedTorrentExportDir"},
265 {
"BitTorrent/Session/ForceProxy",
"Preferences/Connection/ProxyForce"},
266 {
"BitTorrent/Session/GlobalDLSpeedLimit",
"Preferences/Connection/GlobalDLLimit"},
267 {
"BitTorrent/Session/GlobalMaxRatio",
"Preferences/Bittorrent/MaxRatio"},
268 {
"BitTorrent/Session/GlobalUPSpeedLimit",
"Preferences/Connection/GlobalUPLimit"},
269 {
"BitTorrent/Session/IgnoreLimitsOnLAN",
"Preferences/Advanced/IgnoreLimitsLAN"},
270 {
"BitTorrent/Session/IgnoreSlowTorrentsForQueueing",
"Preferences/Queueing/IgnoreSlowTorrents"},
271 {
"BitTorrent/Session/IncludeOverheadInLimits",
"Preferences/Advanced/IncludeOverhead"},
272 {
"BitTorrent/Session/Interface",
"Preferences/Connection/Interface"},
273 {
"BitTorrent/Session/InterfaceAddress",
"Preferences/Connection/InterfaceAddress"},
274 {
"BitTorrent/Session/InterfaceName",
"Preferences/Connection/InterfaceName"},
275 {
"BitTorrent/Session/IPFilter",
"Preferences/IPFilter/File"},
276 {
"BitTorrent/Session/IPFilteringEnabled",
"Preferences/IPFilter/Enabled"},
277 {
"BitTorrent/Session/LSDEnabled",
"Preferences/Bittorrent/LSD"},
278 {
"BitTorrent/Session/MaxActiveDownloads",
"Preferences/Queueing/MaxActiveDownloads"},
279 {
"BitTorrent/Session/MaxActiveTorrents",
"Preferences/Queueing/MaxActiveTorrents"},
280 {
"BitTorrent/Session/MaxActiveUploads",
"Preferences/Queueing/MaxActiveUploads"},
281 {
"BitTorrent/Session/MaxConnections",
"Preferences/Bittorrent/MaxConnecs"},
282 {
"BitTorrent/Session/MaxConnectionsPerTorrent",
"Preferences/Bittorrent/MaxConnecsPerTorrent"},
283 {
"BitTorrent/Session/MaxHalfOpenConnections",
"Preferences/Connection/MaxHalfOpenConnec"},
284 {
"BitTorrent/Session/MaxRatioAction",
"Preferences/Bittorrent/MaxRatioAction"},
285 {
"BitTorrent/Session/MaxUploads",
"Preferences/Bittorrent/MaxUploads"},
286 {
"BitTorrent/Session/MaxUploadsPerTorrent",
"Preferences/Bittorrent/MaxUploadsPerTorrent"},
287 {
"BitTorrent/Session/OutgoingPortsMax",
"Preferences/Advanced/OutgoingPortsMax"},
288 {
"BitTorrent/Session/OutgoingPortsMin",
"Preferences/Advanced/OutgoingPortsMin"},
289 {
"BitTorrent/Session/PeXEnabled",
"Preferences/Bittorrent/PeX"},
290 {
"BitTorrent/Session/Port",
"Preferences/Connection/PortRangeMin"},
291 {
"BitTorrent/Session/Preallocation",
"Preferences/Downloads/PreAllocation"},
292 {
"BitTorrent/Session/ProxyPeerConnections",
"Preferences/Connection/ProxyPeerConnections"},
293 {
"BitTorrent/Session/QueueingSystemEnabled",
"Preferences/Queueing/QueueingEnabled"},
294 {
"BitTorrent/Session/RefreshInterval",
"Preferences/General/RefreshInterval"},
295 {
"BitTorrent/Session/SaveResumeDataInterval",
"Preferences/Downloads/SaveResumeDataInterval"},
296 {
"BitTorrent/Session/SuperSeedingEnabled",
"Preferences/Advanced/SuperSeeding"},
297 {
"BitTorrent/Session/TempPath",
"Preferences/Downloads/TempPath"},
298 {
"BitTorrent/Session/TempPathEnabled",
"Preferences/Downloads/TempPathEnabled"},
299 {
"BitTorrent/Session/TorrentExportDirectory",
"Preferences/Downloads/TorrentExportDir"},
300 {
"BitTorrent/Session/TrackerFilteringEnabled",
"Preferences/IPFilter/FilterTracker"},
301 {
"BitTorrent/Session/UseAlternativeGlobalSpeedLimit",
"Preferences/Connection/alt_speeds_on"},
302 {
"BitTorrent/Session/UseOSCache",
"Preferences/Advanced/osCache"},
303 {
"BitTorrent/Session/UseRandomPort",
"Preferences/General/UseRandomPort"},
304 {
"BitTorrent/Session/uTPEnabled",
"Preferences/Bittorrent/uTP"},
305 {
"BitTorrent/Session/uTPRateLimited",
"Preferences/Bittorrent/uTP_rate_limited"},
306 {
"BitTorrent/TrackerEnabled",
"Preferences/Advanced/trackerEnabled"},
307 {
"Network/PortForwardingEnabled",
"Preferences/Connection/UPnP"},
308 {
"Network/Proxy/Authentication",
"Preferences/Connection/Proxy/Authentication"},
309 {
"Network/Proxy/IP",
"Preferences/Connection/Proxy/IP"},
310 {
"Network/Proxy/OnlyForTorrents",
"Preferences/Connection/ProxyOnlyForTorrents"},
311 {
"Network/Proxy/Password",
"Preferences/Connection/Proxy/Password"},
312 {
"Network/Proxy/Port",
"Preferences/Connection/Proxy/Port"},
313 {
"Network/Proxy/Type",
"Preferences/Connection/ProxyType"},
314 {
"Network/Proxy/Username",
"Preferences/Connection/Proxy/Username"},
315 {
"State/BannedIPs",
"Preferences/IPFilter/BannedIPs"}
319 for (
const KeyMapping &mapping : mappings)
321 if (settingsStorage->hasKey(mapping.oldKey))
323 const auto value = settingsStorage->loadValue<QVariant>(mapping.oldKey);
324 settingsStorage->storeValue(mapping.newKey,
value);
369 const DefaultValue changedDefaults[] =
371 {QLatin1String {
"BitTorrent/Session/QueueingSystemEnabled"},
true,
false}
375 for (
const DefaultValue &
value : changedDefaults)
377 if (!settingsStorage->hasKey(
value.name))
379 settingsStorage->storeValue(
value.name
void storeValue(const QString &key, const T &value)
T loadValue(const QString &key, const T &defaultValue={}) const
static SettingsStorage * instance()
void LogMsg(const QString &message, const Log::MsgType &type)
QString toNativePath(const QString &path)
nonstd::expected< void, QString > saveToFile(const QString &path, const QByteArray &data)
QString fromEnum(const T &value)
T value(const QString &key, const T &defaultValue={})
void upgradeListenPortSettings()
const char MIGRATION_VERSION_KEY[]
void upgradeTrayIconStyleSettings()
void upgradeTorrentContentLayout()
void migrateSettingKeys()
void upgradeSchedulerDaysSettings()
void exportWebUIHttpsFiles()
const int MIGRATION_VERSION
void upgradeDNSServiceSettings()
QString specialFolderLocation(const SpecialFolder folder)
void handleChangedDefaults(const DefaultPreferencesMode mode)
void setCurrentMigrationVersion()