qBittorrent
anonymous_namespace{upgrade.cpp} Namespace Reference

Functions

void exportWebUIHttpsFiles ()
 
void upgradeTorrentContentLayout ()
 
void upgradeListenPortSettings ()
 
void upgradeSchedulerDaysSettings ()
 
void upgradeDNSServiceSettings ()
 
void upgradeTrayIconStyleSettings ()
 
void migrateSettingKeys ()
 

Variables

const int MIGRATION_VERSION = 2
 
const char MIGRATION_VERSION_KEY [] = "Meta/MigrationVersion"
 

Function Documentation

◆ exportWebUIHttpsFiles()

void anonymous_namespace{upgrade.cpp}::exportWebUIHttpsFiles ( )

Definition at line 48 of file upgrade.cpp.

49  {
50  const auto migrate = [](const QString &oldKey, const QString &newKey, const QString &savePath)
51  {
52  SettingsStorage *settingsStorage {SettingsStorage::instance()};
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\"")};
56 
57  if (!newData.isEmpty() || oldData.isEmpty())
58  return;
59 
60  const nonstd::expected<void, QString> result = Utils::IO::saveToFile(savePath, oldData);
61  if (!result)
62  {
63  LogMsg(errorMsgFormat.arg(savePath, result.error()) , Log::WARNING);
64  return;
65  }
66 
67  settingsStorage->storeValue(newKey, savePath);
68  settingsStorage->removeValue(oldKey);
69 
70  LogMsg(QObject::tr("Migrated preferences: WebUI https, exported data to file: \"%1\"").arg(savePath)
71  , Log::INFO);
72  };
73 
74  const QString configPath {specialFolderLocation(SpecialFolder::Config)};
75  migrate(QLatin1String("Preferences/WebUI/HTTPS/Certificate")
76  , QLatin1String("Preferences/WebUI/HTTPS/CertificatePath")
77  , Utils::Fs::toNativePath(configPath + QLatin1String("/WebUICertificate.crt")));
78  migrate(QLatin1String("Preferences/WebUI/HTTPS/Key")
79  , QLatin1String("Preferences/WebUI/HTTPS/KeyPath")
80  , Utils::Fs::toNativePath(configPath + QLatin1String("/WebUIPrivateKey.pem")));
81  }
T loadValue(const QString &key, const T &defaultValue={}) const
static SettingsStorage * instance()
void LogMsg(const QString &message, const Log::MsgType &type)
Definition: logger.cpp:125
@ WARNING
Definition: logger.h:47
@ INFO
Definition: logger.h:46
QString toNativePath(const QString &path)
Definition: fs.cpp:64
nonstd::expected< void, QString > saveToFile(const QString &path, const QByteArray &data)
Definition: io.cpp:69
QString specialFolderLocation(const SpecialFolder folder)
Definition: profile.cpp:131

References Config, Log::INFO, SettingsStorage::instance(), SettingsStorage::loadValue(), LogMsg(), Utils::IO::saveToFile(), specialFolderLocation(), Utils::Fs::toNativePath(), and Log::WARNING.

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ migrateSettingKeys()

void anonymous_namespace{upgrade.cpp}::migrateSettingKeys ( )

Definition at line 232 of file upgrade.cpp.

233  {
234  struct KeyMapping
235  {
236  QString newKey;
237  QString oldKey;
238  };
239 
240  const KeyMapping mappings[] =
241  {
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"}
316  };
317 
318  auto *settingsStorage = SettingsStorage::instance();
319  for (const KeyMapping &mapping : mappings)
320  {
321  if (settingsStorage->hasKey(mapping.oldKey))
322  {
323  const auto value = settingsStorage->loadValue<QVariant>(mapping.oldKey);
324  settingsStorage->storeValue(mapping.newKey, value);
325  // TODO: Remove oldKey after ~v4.4.3 and bump migration version
326  }
327  }
328  }
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64

References SettingsStorage::instance(), and anonymous_namespace{preferences.cpp}::value().

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upgradeDNSServiceSettings()

void anonymous_namespace{upgrade.cpp}::upgradeDNSServiceSettings ( )

Definition at line 170 of file upgrade.cpp.

171  {
172  auto *settingsStorage = SettingsStorage::instance();
173  const auto key = QString::fromLatin1("Preferences/DynDNS/Service");
174  const auto value = settingsStorage->loadValue<QString>(key);
175 
176  bool ok = false;
177  const auto number = value.toInt(&ok);
178 
179  if (ok)
180  {
181  switch (number)
182  {
183  case -1:
184  settingsStorage->storeValue(key, DNS::Service::None);
185  break;
186  case 0:
187  settingsStorage->storeValue(key, DNS::Service::DynDNS);
188  break;
189  case 1:
190  settingsStorage->storeValue(key, DNS::Service::NoIP);
191  break;
192  default:
193  LogMsg(QObject::tr("Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
194  .arg(key, QString::number(number)), Log::WARNING);
195  settingsStorage->removeValue(key);
196  break;
197  }
198  }
199  }

References DNS::DynDNS, SettingsStorage::instance(), LogMsg(), DNS::NoIP, DNS::None, anonymous_namespace{preferences.cpp}::value(), and Log::WARNING.

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upgradeListenPortSettings()

void anonymous_namespace{upgrade.cpp}::upgradeListenPortSettings ( )

Definition at line 103 of file upgrade.cpp.

104  {
105  const auto oldKey = QString::fromLatin1("BitTorrent/Session/UseRandomPort");
106  const auto newKey = QString::fromLatin1("Preferences/Connection/PortRangeMin");
107  auto *settingsStorage = SettingsStorage::instance();
108 
109  if (settingsStorage->hasKey(oldKey))
110  {
111  if (settingsStorage->loadValue<bool>(oldKey))
112  settingsStorage->storeValue(newKey, 0);
113 
114  settingsStorage->removeValue(oldKey);
115  }
116  }

References SettingsStorage::instance().

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upgradeSchedulerDaysSettings()

void anonymous_namespace{upgrade.cpp}::upgradeSchedulerDaysSettings ( )

Definition at line 118 of file upgrade.cpp.

119  {
120  auto *settingsStorage = SettingsStorage::instance();
121  const auto key = QString::fromLatin1("Preferences/Scheduler/days");
122  const auto value = settingsStorage->loadValue<QString>(key);
123 
124  bool ok = false;
125  const auto number = value.toInt(&ok);
126 
127  if (ok)
128  {
129  switch (number)
130  {
131  case 0:
132  settingsStorage->storeValue(key, Scheduler::Days::EveryDay);
133  break;
134  case 1:
135  settingsStorage->storeValue(key, Scheduler::Days::Weekday);
136  break;
137  case 2:
138  settingsStorage->storeValue(key, Scheduler::Days::Weekend);
139  break;
140  case 3:
141  settingsStorage->storeValue(key, Scheduler::Days::Monday);
142  break;
143  case 4:
144  settingsStorage->storeValue(key, Scheduler::Days::Tuesday);
145  break;
146  case 5:
147  settingsStorage->storeValue(key, Scheduler::Days::Wednesday);
148  break;
149  case 6:
150  settingsStorage->storeValue(key, Scheduler::Days::Thursday);
151  break;
152  case 7:
153  settingsStorage->storeValue(key, Scheduler::Days::Friday);
154  break;
155  case 8:
156  settingsStorage->storeValue(key, Scheduler::Days::Saturday);
157  break;
158  case 9:
159  settingsStorage->storeValue(key, Scheduler::Days::Sunday);
160  break;
161  default:
162  LogMsg(QObject::tr("Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
163  .arg(key, QString::number(number)), Log::WARNING);
164  settingsStorage->removeValue(key);
165  break;
166  }
167  }
168  }

References Scheduler::EveryDay, Scheduler::Friday, SettingsStorage::instance(), LogMsg(), Scheduler::Monday, Scheduler::Saturday, Scheduler::Sunday, Scheduler::Thursday, Scheduler::Tuesday, anonymous_namespace{preferences.cpp}::value(), Log::WARNING, Scheduler::Wednesday, Scheduler::Weekday, and Scheduler::Weekend.

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upgradeTorrentContentLayout()

void anonymous_namespace{upgrade.cpp}::upgradeTorrentContentLayout ( )

Definition at line 83 of file upgrade.cpp.

84  {
85  const QString oldKey {QLatin1String {"BitTorrent/Session/CreateTorrentSubfolder"}};
86  const QString newKey {QLatin1String {"BitTorrent/Session/TorrentContentLayout"}};
87 
88  SettingsStorage *settingsStorage {SettingsStorage::instance()};
89  const auto oldData {settingsStorage->loadValue<QVariant>(oldKey)};
90  const auto newData {settingsStorage->loadValue<QString>(newKey)};
91 
92  if (!newData.isEmpty() || !oldData.isValid())
93  return;
94 
95  const bool createSubfolder = oldData.toBool();
96  const BitTorrent::TorrentContentLayout torrentContentLayout =
97  (createSubfolder ? BitTorrent::TorrentContentLayout::Original : BitTorrent::TorrentContentLayout::NoSubfolder);
98 
99  settingsStorage->storeValue(newKey, Utils::String::fromEnum(torrentContentLayout));
100  settingsStorage->removeValue(oldKey);
101  }
QString fromEnum(const T &value)
Definition: string.h:67

References Utils::String::fromEnum(), SettingsStorage::instance(), and SettingsStorage::loadValue().

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upgradeTrayIconStyleSettings()

void anonymous_namespace{upgrade.cpp}::upgradeTrayIconStyleSettings ( )

Definition at line 201 of file upgrade.cpp.

202  {
203  auto *settingsStorage = SettingsStorage::instance();
204  const auto key = QString::fromLatin1("Preferences/Advanced/TrayIconStyle");
205  const auto value = settingsStorage->loadValue<QString>(key);
206 
207  bool ok = false;
208  const auto number = value.toInt(&ok);
209 
210  if (ok)
211  {
212  switch (number)
213  {
214  case 0:
215  settingsStorage->storeValue(key, TrayIcon::Style::Normal);
216  break;
217  case 1:
218  settingsStorage->storeValue(key, TrayIcon::Style::MonoDark);
219  break;
220  case 2:
221  settingsStorage->storeValue(key, TrayIcon::Style::MonoLight);
222  break;
223  default:
224  LogMsg(QObject::tr("Invalid value found in configuration file, reverting it to default. Key: \"%1\". Invalid value: \"%2\".")
225  .arg(key, QString::number(number)), Log::WARNING);
226  settingsStorage->removeValue(key);
227  break;
228  }
229  }
230  }

References SettingsStorage::instance(), LogMsg(), TrayIcon::MonoDark, TrayIcon::MonoLight, TrayIcon::Normal, anonymous_namespace{preferences.cpp}::value(), and Log::WARNING.

Referenced by upgrade().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MIGRATION_VERSION

const int anonymous_namespace{upgrade.cpp}::MIGRATION_VERSION = 2

Definition at line 45 of file upgrade.cpp.

Referenced by setCurrentMigrationVersion(), and upgrade().

◆ MIGRATION_VERSION_KEY

const char anonymous_namespace{upgrade.cpp}::MIGRATION_VERSION_KEY[] = "Meta/MigrationVersion"

Definition at line 46 of file upgrade.cpp.

Referenced by setCurrentMigrationVersion(), and upgrade().