@@ -87,7 +87,6 @@ constexpr auto serverDesktopEnterpriseUpdateChannelC = "desktopEnterpriseChannel
8787constexpr auto generalC = " General" ;
8888}
8989
90-
9190namespace OCC {
9291
9392Q_LOGGING_CATEGORY (lcAccountManager, " nextcloud.gui.account.manager" , QtInfoMsg)
@@ -197,110 +196,64 @@ bool AccountManager::restoreFromLegacySettings()
197196{
198197 qCInfo (lcAccountManager) << " Migrate: restoreFromLegacySettings, checking settings group"
199198 << Theme::instance ()->appName ();
200-
201199 // try to open the correctly themed settings
202200 auto settings = ConfigFile::settingsWithGroup (Theme::instance ()->appName ());
203-
204201 auto wasLegacyImportDialogDisplayed = false ;
205- const auto displayLegacyImportDialog = Theme::instance ()->displayLegacyImportDialog ();
206202 QStringList selectedAccountIds;
207-
208- // if the settings file could not be opened, the childKeys list is empty
209- // then try to load settings from a very old place
210- if (settings->childKeys ().isEmpty ()) {
211- // Legacy settings used QDesktopServices to get the location for the config folder in 2.4 and before
212- const auto legacy2_4CfgSettingsLocation = QString (QStandardPaths::writableLocation (QStandardPaths::GenericDataLocation) + QStringLiteral (" /data" ));
213- const auto legacy2_4CfgFileParentFolder = legacy2_4CfgSettingsLocation.left (legacy2_4CfgSettingsLocation.lastIndexOf (' /' ));
214-
215- // 2.5+ (rest of 2.x series)
216- const auto legacy2_5CfgSettingsLocation = QStandardPaths::writableLocation (Utility::isWindows () ? QStandardPaths::AppDataLocation : QStandardPaths::AppConfigLocation);
217- const auto legacy2_5CfgFileParentFolder = legacy2_5CfgSettingsLocation.left (legacy2_5CfgSettingsLocation.lastIndexOf (' /' ));
218-
219- // Now try the locations we use today
220- const auto fullLegacyCfgFile = QDir::fromNativeSeparators (settings->fileName ());
221- const auto legacyCfgFileParentFolder = fullLegacyCfgFile.left (fullLegacyCfgFile.lastIndexOf (' /' ));
222- const auto legacyCfgFileGrandParentFolder = legacyCfgFileParentFolder.left (legacyCfgFileParentFolder.lastIndexOf (' /' ));
223-
224- const auto legacyCfgFileNamePath = QString (QStringLiteral (" /" ) + legacyCfgFileNameC);
225- const auto legacyCfgFileRelativePath = QString (legacyRelativeConfigLocationC);
226-
227- auto legacyLocations = QVector<QString>{legacy2_4CfgFileParentFolder + legacyCfgFileRelativePath,
228- legacy2_5CfgFileParentFolder + legacyCfgFileRelativePath,
229- legacyCfgFileParentFolder + legacyCfgFileNamePath,
230- legacyCfgFileGrandParentFolder + legacyCfgFileRelativePath};
231-
232- if (Theme::instance ()->isBranded ()) {
233- const auto unbrandedCfgFileNamePath = QString (QStringLiteral (" /" ) + unbrandedCfgFileNameC);
234- const auto unbrandedCfgFileRelativePath = QString (unbrandedRelativeConfigLocationC);
235- legacyLocations.append ({legacyCfgFileParentFolder + unbrandedCfgFileNamePath, legacyCfgFileGrandParentFolder + unbrandedCfgFileRelativePath});
236- }
237-
238- for (const auto &configFile : std::as_const (legacyLocations)) {
239- auto oCSettings = std::make_unique<QSettings>(configFile, QSettings::IniFormat);
240- if (oCSettings->status () != QSettings::Status::NoError) {
241- qCInfo (lcAccountManager) << " Error reading legacy configuration file" << oCSettings->status ();
242- break ;
243- }
244-
245- oCSettings->beginGroup (QLatin1String (accountsC));
246- const auto childGroups = oCSettings->childGroups ();
247- const auto accountsListSize = childGroups.size ();
248- oCSettings->endGroup (); // accountsC
249- if (const QFileInfo configFileInfo (configFile);
250- configFileInfo.exists () && configFileInfo.isReadable ()) {
251-
252- qCInfo (lcAccountManager) << " Migrate: checking old config " << configFile;
253- if (!forceLegacyImport () && accountsListSize > 0 && displayLegacyImportDialog) {
254- wasLegacyImportDialogDisplayed = true ;
255- if (accountsListSize == 1 ) {
256- const auto importQuestion =
257- tr (" An account was detected from a legacy desktop client.\n "
258- " Should the account be imported?" );
259- QMessageBox importMessageBox (QMessageBox::Question, tr (" Legacy import" ), importQuestion);
260- importMessageBox.addButton (tr (" Import" ), QMessageBox::AcceptRole);
261- const auto skipButton = importMessageBox.addButton (tr (" Skip" ), QMessageBox::DestructiveRole);
262- importMessageBox.exec ();
263- if (importMessageBox.clickedButton () == skipButton) {
264- return false ;
265- }
266- selectedAccountIds = childGroups;
267- } else {
268- QVector<LegacyAccountSelectionDialog::AccountItem> accountsToDisplay;
269- oCSettings->beginGroup (QLatin1String (accountsC));
270- for (const auto &accId : childGroups) {
271- oCSettings->beginGroup (accId);
272- const auto displayName = oCSettings->value (QLatin1String (displayNameC)).toString ();
273- const auto urlStr = oCSettings->value (QLatin1String (urlC)).toString ();
274- oCSettings->endGroup (); // accId
275- const auto label = QString (" %1 - %2" ).arg (displayName, urlStr);
276- accountsToDisplay.push_back ({accId, label});
277- }
278- oCSettings->endGroup (); // accountsC
279-
280- LegacyAccountSelectionDialog accountSelectionDialog (accountsToDisplay);
281- if (accountSelectionDialog.exec () != QDialog::Accepted) {
282- return false ;
283- }
284- selectedAccountIds = accountSelectionDialog.selectedAccountIds ();
285- if (selectedAccountIds.isEmpty ()) {
286- return false ;
287- }
288- }
289- } else {
290- selectedAccountIds = childGroups;
203+ Migration migration;
204+ if (const auto legacyData = migration.legacyData (); !legacyData.isNull ()) {
205+
206+ const auto displayLegacyImportDialog = Theme::instance ()->displayLegacyImportDialog ();
207+
208+ auto oCSettings = std::move (legacyData);
209+
210+ oCSettings->beginGroup (QLatin1String (accountsC));
211+ const auto childGroups = oCSettings->childGroups ();
212+ const auto accountsListSize = childGroups.size ();
213+ oCSettings->endGroup (); // accountsC
214+
215+ qCInfo (lcAccountManager) << " Migrate: checking old config" ;
216+ if (!forceLegacyImport () && displayLegacyImportDialog && accountsListSize > 0 ) {
217+ wasLegacyImportDialogDisplayed = true ;
218+ if (childGroups.size () == 1 ) {
219+ const auto importQuestion =
220+ tr (" An account was detected from a legacy desktop client.\n "
221+ " Should the account be imported?" );
222+ QMessageBox importMessageBox (QMessageBox::Question, tr (" Legacy import" ), importQuestion);
223+ importMessageBox.addButton (tr (" Import" ), QMessageBox::AcceptRole);
224+ const auto skipButton = importMessageBox.addButton (tr (" Skip" ), QMessageBox::DestructiveRole);
225+ importMessageBox.exec ();
226+ if (importMessageBox.clickedButton () == skipButton) {
227+ return false ;
291228 }
292-
293- const auto legacyVersion = oCSettings->value (ConfigFile::clientVersionC, {}).toString ();
294- ConfigFile ().setClientPreviousVersionString (legacyVersion);
295- qCInfo (lcAccountManager) << " Migrating from" << legacyVersion;
296- qCInfo (lcAccountManager) << " Copy settings" << oCSettings->allKeys ().join (" , " );
297- settings = std::move (oCSettings);
298- ConfigFile::setDiscoveredLegacyConfigPath (configFileInfo.canonicalPath ());
299- break ;
229+ selectedAccountIds = childGroups;
300230 } else {
301- qCInfo (lcAccountManager) << " Migrate: could not read old config " << configFile;
231+ QVector<LegacyAccountSelectionDialog::AccountItem> accountsToDisplay;
232+ oCSettings->beginGroup (QLatin1String (accountsC));
233+ for (const auto &accId : childGroups) {
234+ oCSettings->beginGroup (accId);
235+ const auto displayName = oCSettings->value (QLatin1String (displayNameC)).toString ();
236+ const auto urlStr = oCSettings->value (QLatin1String (urlC)).toString ();
237+ oCSettings->endGroup (); // accId
238+ const auto label = QString (" %1 - %2" ).arg (displayName, urlStr);
239+ accountsToDisplay.push_back ({accId, label});
240+ }
241+ oCSettings->endGroup (); // accountsC
242+
243+ LegacyAccountSelectionDialog accountSelectionDialog (accountsToDisplay);
244+ if (accountSelectionDialog.exec () != QDialog::Accepted) {
245+ return false ;
246+ }
247+ selectedAccountIds = accountSelectionDialog.selectedAccountIds ();
248+ if (selectedAccountIds.isEmpty ()) {
249+ return false ;
250+ }
302251 }
252+ } else {
253+ selectedAccountIds = childGroups;
303254 }
255+
256+ settings.reset (oCSettings.get ());
304257 }
305258
306259 ConfigFile configFile;
@@ -346,8 +299,7 @@ bool AccountManager::restoreFromLegacySettings()
346299 configFile.setDownloadLimit (settings->value (ConfigFile::downloadLimitC, configFile.downloadLimit ()).toInt ());
347300
348301 // Try to load the single account.
349- auto migration = configFile.migration ();
350- migration.setMigrationPhase (Migration::MigrationPhase::SetupUsers);
302+ migration.setPhase (Migration::Phase::SetupUsers);
351303 if (!settings->childKeys ().isEmpty ()) {
352304 settings->beginGroup (accountsC);
353305 const auto childGroups = selectedAccountIds.isEmpty () ? settings->childGroups () : selectedAccountIds;
@@ -696,7 +648,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
696648 acc->setDownloadLimit (settings.value (networkDownloadLimitC).toInt ());
697649
698650 ConfigFile configFile;
699- auto migration = configFile. migration () ;
651+ Migration migration;
700652 const auto proxyPasswordKey = QString (acc->userIdAtHostWithPort () + networkProxyPasswordKeychainKeySuffixC);
701653 const auto appName = migration.isUnbrandedToBrandedMigration () ? ConfigFile::unbrandedAppName
702654 : Theme::instance ()->appName ();
0 commit comments