void SetupDatabase::applySettings() { AlbumSettings* settings = AlbumSettings::instance(); if (!settings) { return; } if (d->databaseWidget->currentDatabaseType() == QString(DatabaseParameters::SQLiteDatabaseType())) { QString newPath = d->databaseWidget->databasePathEdit->url().path(); QDir oldDir(d->databaseWidget->originalDbPath); QDir newDir(newPath); if (oldDir != newDir || d->databaseWidget->currentDatabaseType() != d->databaseWidget->originalDbType) { settings->setDatabaseParameters(DatabaseParameters::parametersForSQLiteDefaultFile(newPath)); // clear other fields d->databaseWidget->internalServer->setChecked(false); settings->saveSettings(); } } else { if (d->databaseWidget->internalServer->isChecked()) { DatabaseParameters internalServerParameters = DatabaseParameters::defaultParameters(d->databaseWidget->currentDatabaseType()); settings->setInternalDatabaseServer(true); settings->setDatabaseType(d->databaseWidget->currentDatabaseType()); settings->setDatabaseName(internalServerParameters.databaseName); settings->setDatabaseNameThumbnails(internalServerParameters.databaseName); settings->setDatabaseConnectoptions(internalServerParameters.connectOptions); settings->setDatabaseHostName(internalServerParameters.hostName); settings->setDatabasePort(internalServerParameters.port); settings->setDatabaseUserName(internalServerParameters.userName); settings->setDatabasePassword(internalServerParameters.password); } else { settings->setInternalDatabaseServer(d->databaseWidget->internalServer->isChecked()); settings->setDatabaseType(d->databaseWidget->currentDatabaseType()); settings->setDatabaseName(d->databaseWidget->databaseName->text()); settings->setDatabaseNameThumbnails(d->databaseWidget->databaseNameThumbnails->text()); settings->setDatabaseConnectoptions(d->databaseWidget->connectionOptions->text()); settings->setDatabaseHostName(d->databaseWidget->hostName->text()); settings->setDatabasePort(d->databaseWidget->hostPort->text().toInt()); settings->setDatabaseUserName(d->databaseWidget->userName->text()); settings->setDatabasePassword(d->databaseWidget->password->text()); } settings->saveSettings(); } }
void AutoStoreNetworksHelper::storeNetworks() { World *world = Evolution::getEvolutionManager()->getEvolutionWorlds().value(0); if(world != 0) { Population *pop = world->getPopulations().value(0); if(pop != 0) { const QList<Individual*> &individuals = pop->getIndividuals(); for(int i = 0; i < individuals.size(); ++i) { NeuralNetwork *net = dynamic_cast<NeuralNetwork*>(individuals.at(i)->getGenome()); int id = individuals.at(i)->getId(); int genNo = Evolution::getEvolutionManager()->getCurrentGenerationValue()->get(); QString netDir = Evolution::getEvolutionManager()->getEvolutionWorkingDirectory() + "gen" + QString::number(genNo) + "/nets"; Core::getInstance()->enforceDirectoryPath(netDir); QString fileName = netDir + "/net" + QString::number(i) + "_" + QString::number(id); QString errorMsg; QList<QString> warnings; QString onnFileName = fileName + ".onn"; //cerr << "Saving to " << onnFileName.toStdString().c_str() << endl; QString xml = NeuralNetworkIOOrcsV1Xml::createXmlFromNetwork(net); QFile file(onnFileName); if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { Core::log(QString("Could not open file ") .append(onnFileName).append(" to write network.")); file.close(); continue; } QTextStream output(&file); output << xml; if(mStoreSimbaFiles->get()) { QString smbFileName = fileName + ".smb"; NeuralNetworkIOSimbaV3Xml::createFileFromNetwork(smbFileName, net, 0); } //delete previous generation directory QString oldNetDir = Evolution::getEvolutionManager()->getEvolutionWorkingDirectory() + "gen" + QString::number(genNo - 1) + "/nets"; QDir oldDir(oldNetDir); if(oldDir.exists()) { QStringList files = oldDir.entryList(); for(QListIterator<QString> i(files); i.hasNext();) { oldDir.remove(i.next()); } oldDir.rmdir(oldNetDir); } file.close(); } } } }
// We return the UserSettings here because we have to make changes to the // configuration and the location of the file may change between releases. UserSettingsPointer Upgrade::versionUpgrade(const QString& settingsPath) { /* Pre-1.7.0: * * Since we didn't store version numbers in the config file prior to 1.7.0, * we check to see if the user is upgrading if his config files are in the old location, * since we moved them in 1.7.0. This code takes care of moving them. */ QDir oldLocation = QDir(QDir::homePath()); #ifdef __WINDOWS__ QFileInfo* pre170Config = new QFileInfo(oldLocation.filePath("mixxx.cfg")); #else QFileInfo* pre170Config = new QFileInfo(oldLocation.filePath(".mixxx.cfg")); #endif if (pre170Config->exists()) { // Move the files to their new location QDir newLocation = QDir(settingsPath); if (!newLocation.exists()) { qDebug() << "Creating new settings directory" << newLocation.absolutePath(); newLocation.mkpath("."); } QString errorText = "Error moving your %1 file %2 to the new location %3: \n"; #ifdef __WINDOWS__ QString oldFilePath = oldLocation.filePath("mixxxtrack.xml"); #else QString oldFilePath = oldLocation.filePath(".mixxxtrack.xml"); #endif QString newFilePath = newLocation.filePath("mixxxtrack.xml"); QFile* oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) { oldFile->remove(); } else { if (oldFile->error()==14) qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.filePath("mixxxbpmschemes.xml"); #else oldFilePath = oldLocation.filePath(".mixxxbpmscheme.xml"); #endif newFilePath = newLocation.filePath("mixxxbpmscheme.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.filePath("MixxxMIDIBindings.xml"); #else oldFilePath = oldLocation.filePath(".MixxxMIDIBindings.xml"); #endif newFilePath = newLocation.filePath("MixxxMIDIBindings.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { qWarning() << "The MIDI mapping file format has changed in this version of Mixxx. You will need to reconfigure your MIDI controller. See the Wiki for full details on the new format."; if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } // Tidy up delete oldFile; #ifdef __WINDOWS__ QFile::remove(oldLocation.filePath("MixxxMIDIDevice.xml")); // Obsolete file, so just delete it #else QFile::remove(oldLocation.filePath(".MixxxMIDIDevice.xml")); // Obsolete file, so just delete it #endif #ifdef __WINDOWS__ oldFilePath = oldLocation.filePath("mixxx.cfg"); #else oldFilePath = oldLocation.filePath(".mixxx.cfg"); #endif newFilePath = newLocation.filePath(SETTINGS_FILE); oldFile = new QFile(oldFilePath); if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } delete oldFile; } // Tidy up delete pre170Config; // End pre-1.7.0 code /*************************************************************************** * Post-1.7.0 upgrade code * * Add entries to the IF ladder below if anything needs to change from the * previous to the current version. This allows for incremental upgrades * in case a user upgrades from a few versions prior. ****************************************************************************/ // Read the config file from home directory UserSettingsPointer config(new ConfigObject<ConfigValue>( QDir(settingsPath).filePath(SETTINGS_FILE))); QString configVersion = config->getValueString(ConfigKey("[Config]","Version")); if (configVersion.isEmpty()) { #ifdef __APPLE__ qDebug() << "Config version is empty, trying to read pre-1.9.0 config"; // Try to read the config from the pre-1.9.0 final directory on OS X (we moved it in 1.9.0 final) QScopedPointer<QFile> oldConfigFile(new QFile(QDir::homePath().append("/").append(".mixxx/mixxx.cfg"))); if (oldConfigFile->exists() && ! CmdlineArgs::Instance().getSettingsPathSet()) { qDebug() << "Found pre-1.9.0 config for OS X"; // Note: We changed SETTINGS_PATH in 1.9.0 final on OS X so it must be hardcoded to ".mixxx" here for legacy. config = UserSettingsPointer(new ConfigObject<ConfigValue>( QDir::homePath().append("/.mixxx/mixxx.cfg"))); // Just to be sure all files like logs and soundconfig go with mixxx.cfg // TODO(XXX) Trailing slash not needed anymore as we switches from String::append // to QDir::filePath elsewhere in the code. This is candidate for removal. CmdlineArgs::Instance().setSettingsPath(QDir::homePath().append("/.mixxx/")); configVersion = config->getValueString(ConfigKey("[Config]","Version")); } else { #elif __WINDOWS__ qDebug() << "Config version is empty, trying to read pre-1.12.0 config"; // Try to read the config from the pre-1.12.0 final directory on Windows (we moved it in 1.12.0 final) QScopedPointer<QFile> oldConfigFile(new QFile(QDir::homePath().append("/Local Settings/Application Data/Mixxx/mixxx.cfg"))); if (oldConfigFile->exists() && ! CmdlineArgs::Instance().getSettingsPathSet()) { qDebug() << "Found pre-1.12.0 config for Windows"; // Note: We changed SETTINGS_PATH in 1.12.0 final on Windows so it must be hardcoded to "Local Settings/Application Data/Mixxx/" here for legacy. config = UserSettingsPointer(new ConfigObject<ConfigValue>( QDir::homePath().append("/Local Settings/Application Data/Mixxx/mixxx.cfg"))); // Just to be sure all files like logs and soundconfig go with mixxx.cfg // TODO(XXX) Trailing slash not needed anymore as we switches from String::append // to QDir::filePath elsewhere in the code. This is candidate for removal. CmdlineArgs::Instance().setSettingsPath(QDir::homePath().append("/Local Settings/Application Data/Mixxx/")); configVersion = config->getValueString(ConfigKey("[Config]","Version")); } else { #endif // This must have been the first run... right? :) qDebug() << "No version number in configuration file. Setting to" << MIXXX_VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(MIXXX_VERSION)); m_bFirstRun = true; return config; #ifdef __APPLE__ } #elif __WINDOWS__ } #endif } // If it's already current, stop here if (configVersion == MIXXX_VERSION) { qDebug() << "Configuration file is at the current version" << MIXXX_VERSION; return config; } // Allows for incremental upgrades in case someone upgrades from a few versions prior // (I wish we could do a switch on a QString.) /* // Examples, since we didn't store the version number prior to v1.7.0 if (configVersion.startsWith("1.6.0")) { qDebug() << "Upgrading from v1.6.0 to 1.6.1..."; // Upgrade tasks go here configVersion = "1.6.1"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.6.1")); } if (configVersion.startsWith("1.6.1")) { qDebug() << "Upgrading from v1.6.1 to 1.7.0..."; // Upgrade tasks go here configVersion = "1.7.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.7.0")); } */ // We use the following blocks to detect if this is the first time // you've run the latest version of Mixxx. This lets us show // the promo tracks stats agreement stuff for all users that are // upgrading Mixxx. if (configVersion.startsWith("1.7")) { qDebug() << "Upgrading from v1.7.x..."; // Upgrade tasks go here // Nothing to change, really configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8.0~beta1") || configVersion.startsWith("1.8.0~beta2")) { qDebug() << "Upgrading from v1.8.0~beta..."; // Upgrade tasks go here configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8") || configVersion.startsWith("1.9.0beta1")) { qDebug() << "Upgrading from" << configVersion << "..."; // Upgrade tasks go here #ifdef __APPLE__ QString OSXLocation180 = QDir::homePath().append("/").append(".mixxx"); QString OSXLocation190 = settingsPath; QDir newOSXDir(OSXLocation190); newOSXDir.mkpath(OSXLocation190); QList<QPair<QString, QString> > dirsToMove; dirsToMove.push_back(QPair<QString, QString>(OSXLocation180, OSXLocation190)); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/midi", OSXLocation190 + "midi")); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/presets", OSXLocation190 + "presets")); QListIterator<QPair<QString, QString> > dirIt(dirsToMove); QPair<QString, QString> curPair; while (dirIt.hasNext()) { curPair = dirIt.next(); qDebug() << "Moving" << curPair.first << "to" << curPair.second; QDir oldSubDir(curPair.first); QDir newSubDir(curPair.second); newSubDir.mkpath(curPair.second); // Create the new destination directory QStringList contents = oldSubDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; // Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); QString src = curPair.first + "/" + cur; QString dest = curPair.second + "/" + cur; qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to move file during upgrade."; } } // Rename the old directory. newOSXDir.rename(OSXLocation180, OSXLocation180 + "-1.8"); } // Reload the configuration file from the new location. // (We want to make sure we save to the new location...) config = UserSettingsPointer(new ConfigObject<ConfigValue>( QDir(settingsPath).filePath(SETTINGS_FILE))); #endif configVersion = "1.9.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.9.0")); } if (configVersion.startsWith("1.9") || configVersion.startsWith("1.10")) { qDebug() << "Upgrading from v1.9.x/1.10.x..."; bool successful = true; qDebug() << "Copying midi/ to controllers/"; QString midiPath = legacyUserPresetsPath(config); QString controllerPath = userPresetsPath(config); QDir oldDir(midiPath); QDir newDir(controllerPath); newDir.mkpath(controllerPath); // create the new directory QStringList contents = oldDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; // Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); if (newDir.exists(cur)) { qDebug() << cur << "already exists in" << controllerPath << "Skipping."; continue; } QString src = oldDir.absoluteFilePath(cur); QString dest = newDir.absoluteFilePath(cur); qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to copy file during upgrade."; successful = false; } } bool reanalyze_choice = askReanalyzeBeats(); BeatDetectionSettings bpmSettings(config); bpmSettings.setReanalyzeWhenSettingsChange(reanalyze_choice); if (successful) { qDebug() << "Upgrade Successful"; configVersion = "1.11.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue(configVersion)); } else { qDebug() << "Upgrade Failed"; } } if (configVersion.startsWith("1.11")) { qDebug() << "Upgrading from v1.11.x..."; bool successful = false; { MixxxDb mixxxDb(config); const mixxx::DbConnectionPooler dbConnectionPooler( mixxxDb.connectionPool()); if (dbConnectionPooler.isPooling()) { QSqlDatabase dbConnection = mixxx::DbConnectionPooled(mixxxDb.connectionPool()); DEBUG_ASSERT(dbConnection.isOpen()); if (MixxxDb::initDatabaseSchema(dbConnection)) { TrackCollection tc(config); tc.connectDatabase(dbConnection); // upgrade to the multi library folder settings QString currentFolder = config->getValueString(PREF_LEGACY_LIBRARY_DIR); // to migrate the DB just add the current directory to the new // directories table // NOTE(rryan): We don't have to ask for sandbox permission to this // directory because the normal startup integrity check in Library will // notice if we don't have permission and ask for access. Also, the // Sandbox isn't setup yet at this point in startup because it relies on // the config settings path and this function is what loads the config // so it's not ready yet. successful = tc.getDirectoryDAO().addDirectory(currentFolder); tc.disconnectDatabase(); } } } // ask for library rescan to activate cover art. We can later ask for // this variable when the library scanner is constructed. m_bRescanLibrary = askReScanLibrary(); // Versions of mixxx until 1.11 had a hack that multiplied gain by 1/2, // which was compensation for another hack that set replaygain to a // default of 6. We've now removed all of the hacks, so subtracting // 6 from everyone's replay gain should keep things consistent for // all users. int oldReplayGain = config->getValue( ConfigKey("[ReplayGain]", "InitialReplayGainBoost"), 6); int newReplayGain = math_max(-6, oldReplayGain - 6); config->set(ConfigKey("[ReplayGain]", "InitialReplayGainBoost"), ConfigValue(newReplayGain)); // if everything until here worked fine we can mark the configuration as // updated if (successful) { configVersion = MIXXX_VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(MIXXX_VERSION)); } else { qDebug() << "Upgrade failed!\n"; } } if (configVersion.startsWith("1.12") || configVersion.startsWith("2.0") || configVersion.startsWith("2.1.0")) { // No special upgrade required, just update the value. configVersion = MIXXX_VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(MIXXX_VERSION)); } if (configVersion == MIXXX_VERSION) qDebug() << "Configuration file is now at the current version" << MIXXX_VERSION; else { qWarning() << "Configuration file is at version" << configVersion << "instead of the current" << MIXXX_VERSION; } return config; }
bool SynchronizeOldPilots(ProMan* profileManager) { if (!(FlagListManager::GetFlagListManager()->GetBuildCaps() & FlagListManager::BUILD_CAPS_SDL)) { // Nothing to do, we have an old build return true; } wxLogStatus(_T("Synchronizing old pilot files...")); wxFileName oldConfigFolder; #if IS_WIN32 wxString rootPath; if (!profileManager->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &rootPath)) { wxLogWarning(_T("No TC root folder in configuration!")); return false; } oldConfigFolder.AssignDir(rootPath, wxPATH_NATIVE); #else oldConfigFolder.Assign(GetPlatformDefaultConfigFilePathOld()); #endif oldConfigFolder.AppendDir(_T("data")); oldConfigFolder.AppendDir(_T("players")); wxFileName newConfigFolder(GetPlatformDefaultConfigFilePathNew()); newConfigFolder.AppendDir(_T("data")); newConfigFolder.AppendDir(_T("players")); if (!oldConfigFolder.DirExists()) { // No old config folder so there are no pilot files to copy wxLogStatus(_T(" Old pilot directory does not exist, nothing to be done.")); return true; } // Heuristic to determine if the files were copied before if (newConfigFolder.DirExists()) { // new players directory already exists so it was already used before // Don't try to copy in this case wxLogStatus(_T(" New pilot directory already exists, was probably copied before.")); return true; } if (!newConfigFolder.Mkdir(0777, wxPATH_MKDIR_FULL)) { wxLogError(_T("Failed to create directory '%s'"), newConfigFolder.GetFullPath().c_str()); return false; } // If we are here we need to copy the old pilot files wxDir oldDir(oldConfigFolder.GetFullPath()); wxString pilotFile; bool cont = oldDir.GetFirst(&pilotFile, wxEmptyString, wxDIR_FILES); wxLogStatus(_T("Copying pilot files from '%s' to '%s'."), oldConfigFolder.GetFullPath().c_str(), newConfigFolder.GetFullPath().c_str()); while (cont) { wxFileName pilotFileName; pilotFileName.Assign(oldConfigFolder.GetFullPath(), pilotFile); wxFileName newPilotFile; newPilotFile.Assign(newConfigFolder.GetFullPath(), pilotFile); wxLogStatus(_T(" Copying '%s' to '%s'"), pilotFileName.GetFullPath().c_str(), newPilotFile.GetFullPath().c_str()); if (!wxCopyFile(pilotFileName.GetFullPath(), newPilotFile.GetFullPath())) { wxLogError(_T("Failed to copy pilot file '%s'!"), pilotFileName.GetFullPath().c_str()); } cont = oldDir.GetNext(&pilotFile); } wxLogStatus(_T(" Done copying pilot files.")); return true; }
// We return the ConfigObject here because we have to make changes to the // configuration and the location of the file may change between releases. ConfigObject<ConfigValue>* Upgrade::versionUpgrade(const QString& settingsPath) { /* Pre-1.7.0: * * Since we didn't store version numbers in the config file prior to 1.7.0, * we check to see if the user is upgrading if his config files are in the old location, * since we moved them in 1.7.0. This code takes care of moving them. */ QString oldLocation = QDir::homePath().append("/%1"); #ifdef __WINDOWS__ QFileInfo* pre170Config = new QFileInfo(oldLocation.arg("mixxx.cfg")); #else QFileInfo* pre170Config = new QFileInfo(oldLocation.arg(".mixxx.cfg")); #endif if (pre170Config->exists()) { // Move the files to their new location QString newLocation = settingsPath; if (!QDir(newLocation).exists()) { qDebug() << "Creating new settings directory" << newLocation; QDir().mkpath(newLocation); } newLocation.append("%1"); QString errorText = "Error moving your %1 file %2 to the new location %3: \n"; #ifdef __WINDOWS__ QString oldFilePath = oldLocation.arg("mixxxtrack.xml"); #else QString oldFilePath = oldLocation.arg(".mixxxtrack.xml"); #endif QString newFilePath = newLocation.arg("mixxxtrack.xml"); QFile* oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) { oldFile->remove(); m_bUpgraded = true; } else { if (oldFile->error()==14) qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.arg("mixxxbpmschemes.xml"); #else oldFilePath = oldLocation.arg(".mixxxbpmscheme.xml"); #endif newFilePath = newLocation.arg("mixxxbpmscheme.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.arg("MixxxMIDIBindings.xml"); #else oldFilePath = oldLocation.arg(".MixxxMIDIBindings.xml"); #endif newFilePath = newLocation.arg("MixxxMIDIBindings.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { qWarning() << "The MIDI mapping file format has changed in this version of Mixxx. You will need to reconfigure your MIDI controller. See the Wiki for full details on the new format."; if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } // Tidy up delete oldFile; QFile::remove(oldLocation.arg(".MixxxMIDIDevice.xml")); // Obsolete file, so just delete it #ifdef __WINDOWS__ oldFilePath = oldLocation.arg("mixxx.cfg"); #else oldFilePath = oldLocation.arg(".mixxx.cfg"); #endif newFilePath = newLocation.arg(SETTINGS_FILE); oldFile = new QFile(oldFilePath); if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } delete oldFile; } // Tidy up delete pre170Config; // End pre-1.7.0 code /*************************************************************************** * Post-1.7.0 upgrade code * * Add entries to the IF ladder below if anything needs to change from the * previous to the current version. This allows for incremental upgrades * incase a user upgrades from a few versions prior. ****************************************************************************/ // Read the config file from home directory ConfigObject<ConfigValue> *config = new ConfigObject<ConfigValue>(settingsPath + SETTINGS_FILE); QString configVersion = config->getValueString(ConfigKey("[Config]","Version")); if (configVersion.isEmpty()) { #ifdef __APPLE__ qDebug() << "Config version is empty, trying to read pre-1.9.0 config"; //Try to read the config from the pre-1.9.0 final directory on OS X (we moved it in 1.9.0 final) QFile* oldFile = new QFile(QDir::homePath().append("/").append(".mixxx/mixxx.cfg")); if (oldFile->exists()) { qDebug() << "Found pre-1.9.0 config for OS X"; config = new ConfigObject<ConfigValue>(QDir::homePath().append("/").append(".mixxx/mixxx.cfg")); //Note: We changed SETTINGS_PATH in 1.9.0 final on OS X so it must be hardcoded to ".mixxx" here for legacy. configVersion = config->getValueString(ConfigKey("[Config]","Version")); delete oldFile; } else { #endif //This must have been the first run... right? :) qDebug() << "No version number in configuration file. Setting to" << VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(VERSION)); m_bFirstRun = true; return config; #ifdef __APPLE__ } #endif } // If it's already current, stop here if (configVersion == VERSION) { qDebug() << "Configuration file is at the current version" << VERSION; return config; } // Allows for incremental upgrades incase someone upgrades from a few versions prior // (I wish we could do a switch on a QString.) /* // Examples, since we didn't store the version number prior to v1.7.0 if (configVersion.startsWith("1.6.0")) { qDebug() << "Upgrading from v1.6.0 to 1.6.1..."; // Upgrade tasks go here configVersion = "1.6.1"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.6.1")); } if (configVersion.startsWith("1.6.1")) { qDebug() << "Upgrading from v1.6.1 to 1.7.0..."; // Upgrade tasks go here configVersion = "1.7.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.7.0")); } */ //We use the following blocks to detect if this is the first time //you've run the latest version of Mixxx. This lets us show //the promo tracks stats agreement stuff for all users that are //upgrading Mixxx. if (configVersion.startsWith("1.7")) { qDebug() << "Upgrading from v1.7.x..."; // Upgrade tasks go here // Nothing to change, really configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8.0~beta1") || configVersion.startsWith("1.8.0~beta2")) { qDebug() << "Upgrading from v1.8.0~beta..."; // Upgrade tasks go here configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8") || configVersion.startsWith("1.9.0beta1")) { qDebug() << "Upgrading from" << configVersion << "..."; // Upgrade tasks go here #ifdef __APPLE__ QString OSXLocation180 = QDir::homePath().append("/").append(".mixxx"); QString OSXLocation190 = settingsPath; QDir newOSXDir(OSXLocation190); newOSXDir.mkpath(OSXLocation190); QList<QPair<QString, QString> > dirsToMove; dirsToMove.push_back(QPair<QString, QString>(OSXLocation180, OSXLocation190)); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/midi", OSXLocation190 + "midi")); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/presets", OSXLocation190 + "presets")); QListIterator<QPair<QString, QString> > dirIt(dirsToMove); QPair<QString, QString> curPair; while (dirIt.hasNext()) { curPair = dirIt.next(); qDebug() << "Moving" << curPair.first << "to" << curPair.second; QDir oldSubDir(curPair.first); QDir newSubDir(curPair.second); newSubDir.mkpath(curPair.second); //Create the new destination directory QStringList contents = oldSubDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; //Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); QString src = curPair.first + "/" + cur; QString dest = curPair.second + "/" + cur; qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to move file during upgrade."; } } //Rename the old directory. newOSXDir.rename(OSXLocation180, OSXLocation180 + "-1.8"); } //Reload the configuration file from the new location. //(We want to make sure we save to the new location...) config = new ConfigObject<ConfigValue>(settingsPath + SETTINGS_FILE); #endif configVersion = "1.9.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.9.0")); } if (configVersion.startsWith("1.9") || configVersion.startsWith("1.10")) { qDebug() << "Upgrading from v1.9.x/1.10.x..."; bool successful = true; qDebug() << "Copying midi/ to controllers/"; QString midiPath = legacyUserPresetsPath(config); QString controllerPath = userPresetsPath(config); QDir oldDir(midiPath); QDir newDir(controllerPath); newDir.mkpath(controllerPath); // create the new directory QStringList contents = oldDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; //Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); if (newDir.exists(cur)) { qDebug() << cur << "already exists in" << controllerPath << "Skipping."; continue; } QString src = oldDir.absoluteFilePath(cur); QString dest = newDir.absoluteFilePath(cur); qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to copy file during upgrade."; successful = false; } } bool reanalyze_choice = askReanalyzeBeats(); config->set(ConfigKey(BPM_CONFIG_KEY, BPM_REANALYZE_WHEN_SETTINGS_CHANGE), ConfigValue(reanalyze_choice)); if (successful) { qDebug() << "Upgrade Successful"; configVersion = "1.11.0"; m_bUpgraded = true; config->set(ConfigKey("[Config]","Version"), ConfigValue(configVersion)); } else { qDebug() << "Upgrade Failed"; } } if (configVersion.startsWith("1.11")) { qDebug() << "Upgrading from v1.11.x..."; // upgrade to the multi library folder settings QString currentFolder = config->getValueString(PREF_LEGACY_LIBRARY_DIR); // to migrate the DB just add the current directory to the new // directories table TrackCollection tc(config); DirectoryDAO directoryDAO = tc.getDirectoryDAO(); // NOTE(rryan): We don't have to ask for sandbox permission to this // directory because the normal startup integrity check in Library will // notice if we don't have permission and ask for access. Also, the // Sandbox isn't setup yet at this point in startup because it relies on // the config settings path and this function is what loads the config // so it's not ready yet. bool successful = directoryDAO.addDirectory(currentFolder); // ask for library rescan to activate cover art. We can later ask for // this variable when the library scanner is constructed. m_bRescanLibrary = askReScanLibrary(); // if everything until here worked fine we can mark the configuration as // updated if (successful) { configVersion = VERSION; m_bUpgraded = true; config->set(ConfigKey("[Config]","Version"), ConfigValue(VERSION)); } else { qDebug() << "Upgrade failed!\n"; } } if (configVersion == VERSION) qDebug() << "Configuration file is now at the current version" << VERSION; else { /* Way too verbose, this confuses the hell out of Linux users when they see this: qWarning() << "Configuration file is at version" << configVersion << "and I don't know how to upgrade it to the current" << VERSION << "\n (That means a function to do this needs to be added to upgrade.cpp.)" << "\n-> Leaving the configuration file version as-is."; */ qWarning() << "Configuration file is at version" << configVersion << "instead of the current" << VERSION; } return config; }