void migrateConfigToAppDir() { const QString appDir = QCoreApplication::applicationDirPath(); const QString path = appDir + "/config"; const QString uninstPath = appDir + "/unins000.exe"; QDir dir(path); if ( !QFile::exists(uninstPath) && QFileInfo(appDir).isWritable() && dir.mkpath("copyq") && dir.cd("copyq") && dir.isReadable() && QFileInfo(dir.absolutePath()).isWritable() ) { QSettings oldSettings; const QString oldConfigFileName = QSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()).fileName(); const QString oldConfigPath = QDir::cleanPath(oldConfigFileName + "/.."); QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, path); QSettings::setDefaultFormat(QSettings::IniFormat); Settings newSettings; if ( Settings::canModifySettings() && newSettings.isEmpty() ) { COPYQ_LOG("Migrating configuration to application directory."); const QString newConfigPath = QDir::cleanPath(newSettings.fileName() + "/.."); // Migrate configuration from system directory. migrateDirectory(oldConfigPath, newConfigPath); // Migrate themes from system directory. migrateDirectory(oldConfigPath + "/themes", newConfigPath + "/themes"); // Migrate rest of the configuration from the system registry. migrateConfig(oldSettings, newSettings); } } else { log( QString("Ignoring configuration in \"%1\" (https://github.com/hluk/CopyQ/issues/583).") .arg(path), LogWarning ); QSettings oldSettings; QSettings::setDefaultFormat(QSettings::IniFormat); Settings newSettings; // Move settings from Windows registry. if (newSettings.isEmpty()) { COPYQ_LOG("Moving configuration from Windows registry."); migrateConfig(oldSettings, newSettings); } } }
void migrateConfigToAppDir() { const QString path = QCoreApplication::applicationDirPath() + "/config"; QDir dir(path); if ( dir.mkpath("copyq") && dir.isReadable() && QFileInfo(path).isWritable() ) { QSettings oldSettings; const QString oldConfigFileName = QSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()).fileName(); const QString oldConfigPath = QDir::cleanPath(oldConfigFileName + "/.."); QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, path); QSettings::setDefaultFormat(QSettings::IniFormat); Settings newSettings; if ( Settings::canModifySettings() && newSettings.isEmpty() ) { COPYQ_LOG("Migrating configuration to application directory."); const QString newConfigPath = QDir::cleanPath(newSettings.fileName() + "/.."); // Migrate configuration from system directory. migrateDirectory(oldConfigPath, newConfigPath); // Migrate themes from system directory. migrateDirectory(oldConfigPath + "/themes", newConfigPath + "/themes"); // Migrate rest of the configuration from the system registry. migrateConfig(oldSettings, newSettings); } } else { COPYQ_LOG( QString("Cannot use \"%1\" directory to save user configuration and items.") .arg(path) ); QSettings oldSettings; QSettings::setDefaultFormat(QSettings::IniFormat); Settings newSettings; // Move settings from Windows registry. if (newSettings.isEmpty()) { COPYQ_LOG("Moving configuration from Windows registry."); migrateConfig(oldSettings, newSettings); } } }