OSDN Git Service

Added support for a true "portable" mode: If you rename the LameXP executable to...
authorlordmulder <mulder2@gmx.de>
Sun, 23 Jan 2011 23:04:07 +0000 (00:04 +0100)
committerlordmulder <mulder2@gmx.de>
Sun, 23 Jan 2011 23:04:07 +0000 (00:04 +0100)
src/Config.h
src/Dialog_MainWindow.cpp
src/Global.cpp
src/Global.h
src/Model_Settings.cpp

index 37da620..c9f1a20 100644 (file)
@@ -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
 
 /*
index cc00a08..f7393bd 100644 (file)
@@ -61,6 +61,7 @@
 #include <QCryptographicHash>
 #include <QTranslator>
 #include <QResource>
+#include <QScrollBar>
 
 //Win32 includes
 #include <Windows.h>
@@ -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("<nobr>%1<br>").arg(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled."));
                        messageText += QString("%1<br><br>").arg(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!"));
                        messageText += QString("%1<br>").arg(tr("Your LameXP directory is located here:"));
-                       messageText += QString("<i><nobr><a href=\"file:///%1\">%1</a></nobr></i><br><br>").arg(QDir::toNativeSeparators(QCoreApplication::applicationDirPath()));
+                       messageText += QString("<i><nobr><a href=\"file:///%1\">%1</a></nobr></i><br><br>").arg(QDir::toNativeSeparators(appPath));
                        messageText += QString("%1<br>").arg(tr("You can download the Nero AAC encoder for free from the official Nero website at:"));
                        messageText += "<b>" + LINK(AboutDialog::neroAacUrl) + "</b><br></nobr>";
                        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);
 }
 
 /*
index a1588ed..3830f5d 100644 (file)
@@ -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)
index 01f4067..a39e88b 100644 (file)
@@ -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);
index 79c22e0..2274f5d 100644 (file)
@@ -28,6 +28,7 @@
 #include <QApplication>
 #include <QString>
 #include <QFileInfo>
+#include <QDir>
 #include <QStringList>
 #include <QLocale>
 
@@ -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();