From: lordmulder Date: Sun, 23 Jan 2011 23:04:07 +0000 (+0100) Subject: Added support for a true "portable" mode: If you rename the LameXP executable to... X-Git-Tag: Release_400~67 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=fb707cb257df5a3e4ae961a48f01a39de47faf69;p=lamexp%2FLameXP.git Added support for a true "portable" mode: If you rename the LameXP executable to 'LameXP-Portable.exe' it will store the configuration file in the same folder where the executable is located. This might be helpful if you put LameXP onto your USB stick and use it on different computers regularly. Important: In "portable" mode the user is responsible to make sure that write-access to LameXP folder is available! --- diff --git a/src/Config.h b/src/Config.h index 37da620f..c9f1a200 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 252 +#define VER_LAMEXP_BUILD 253 #define VER_LAMEXP_SUFFIX Beta-1 /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index cc00a082..f7393bd6 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -61,6 +61,7 @@ #include #include #include +#include //Win32 includes #include @@ -693,11 +694,13 @@ void MainWindow::windowShown(void) else { radioButtonEncoderAAC->setEnabled(false); + QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath(); + if(appPath.isEmpty()) appPath = QCoreApplication::applicationDirPath(); QString messageText; messageText += QString("%1
").arg(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")); messageText += QString("%1

").arg(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")); messageText += QString("%1
").arg(tr("Your LameXP directory is located here:")); - messageText += QString("
%1

").arg(QDir::toNativeSeparators(QCoreApplication::applicationDirPath())); + messageText += QString("%1

").arg(QDir::toNativeSeparators(appPath)); messageText += QString("%1
").arg(tr("You can download the Nero AAC encoder for free from the official Nero website at:")); messageText += "" + LINK(AboutDialog::neroAacUrl) + "
"; QMessageBox::information(this, tr("AAC Support Disabled"), messageText); @@ -1702,6 +1705,7 @@ void MainWindow::resetAdvancedOptionsButtonClicked() comboBoxNeroAACProfile->setCurrentIndex(m_settings->neroAACProfileDefault()); while(checkBoxBitrateManagement->isChecked() != m_settings->bitrateManagementEnabledDefault()) checkBoxBitrateManagement->click(); while(checkBoxNeroAAC2PassMode->isChecked() != m_settings->neroAACEnable2PassDefault()) checkBoxNeroAAC2PassMode->click(); + scrollArea->verticalScrollBar()->setValue(0); } /* diff --git a/src/Global.cpp b/src/Global.cpp index a1588eda..3830f5d3 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -716,6 +716,15 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize) } /* + * Check for LameXP "portable" mode + */ +bool lamexp_portable_mode(void) +{ + QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName(); + return baseName.contains("lamexp", Qt::CaseInsensitive) && baseName.contains("portable", Qt::CaseInsensitive); +} + +/* * Get a random string */ QString lamexp_rand_str(void) diff --git a/src/Global.h b/src/Global.h index 01f4067b..a39e88ba 100644 --- a/src/Global.h +++ b/src/Global.h @@ -92,6 +92,7 @@ const QString &lamexp_temp_folder(void); void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize); void lamexp_ipc_send(unsigned int command, const char* message); lamexp_cpu_t lamexp_detect_cpu_features(void); +bool lamexp_portable_mode(void); //Translation support QStringList lamexp_query_translations(void); diff --git a/src/Model_Settings.cpp b/src/Model_Settings.cpp index 79c22e0a..2274f5d2 100644 --- a/src/Model_Settings.cpp +++ b/src/Model_Settings.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -87,8 +88,24 @@ SettingsModel::SettingsModel(void) : m_defaultLanguage(NULL) { - QString appPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); - m_settings = new QSettings(appPath.append("/config.ini"), QSettings::IniFormat); + QString configPath; + + if(!lamexp_portable_mode()) + { + QString dataPath = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)).canonicalPath(); + if(dataPath.isEmpty()) dataPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + QDir(dataPath).mkpath("."); + configPath = QString("%1/config.ini").arg(dataPath); + } + else + { + qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n"); + QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath(); + if(appPath.isEmpty()) appPath = QApplication::applicationFilePath(); + configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName()); + } + + m_settings = new QSettings(configPath, QSettings::IniFormat); m_settings->beginGroup(QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build())); m_settings->setValue(g_settingsId_versionNumber, QApplication::applicationVersion()); m_settings->sync();