diff --git a/src/global.cpp b/src/global.cpp index 6acad9d..831a4c0 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -372,6 +372,25 @@ const char *x264_version_arch(void) return g_x264_version_arch; } +/* + * Check for portable mode + */ +bool x264_portable(void) +{ + static bool detected = false; + static bool portable = false; + + if(!detected) + { + portable = portable || QFileInfo(QApplication::applicationFilePath()).baseName().contains(QRegExp("^portable[^A-Za-z0-9]", Qt::CaseInsensitive)); + portable = portable || QFileInfo(QApplication::applicationFilePath()).baseName().contains(QRegExp("[^A-Za-z0-9]portable[^A-Za-z0-9]", Qt::CaseInsensitive)); + portable = portable || QFileInfo(QApplication::applicationFilePath()).baseName().contains(QRegExp("[^A-Za-z0-9]portable$", Qt::CaseInsensitive)); + detected = true; + } + + return portable; +} + /* * Get build date date */ diff --git a/src/global.h b/src/global.h index ef511df..94b403f 100644 --- a/src/global.h +++ b/src/global.h @@ -99,6 +99,7 @@ unsigned int x264_version_major(void); unsigned int x264_version_minor(void); unsigned int x264_version_patch(void); const QDate &x264_version_date(void); +bool x264_portable(void); bool x264_is_prerelease(void); const char *x264_version_time(void); const char *x264_version_compiler(void); diff --git a/src/main.cpp b/src/main.cpp index b790d61..9fac9cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,12 @@ static int x264_main(int argc, char* argv[]) return -1; } + //Running in portable mode? + if(x264_portable()) + { + qDebug("Application is running in portable mode!\n"); + } + //Taskbar init WinSevenTaskbar::init(); diff --git a/src/model_options.cpp b/src/model_options.cpp index eacf9c0..a0b99f7 100644 --- a/src/model_options.cpp +++ b/src/model_options.cpp @@ -26,6 +26,7 @@ #include #include #include +#include OptionsModel::OptionsModel(void) { @@ -82,7 +83,7 @@ bool OptionsModel::equals(OptionsModel *model) bool OptionsModel::saveTemplate(OptionsModel *model, const QString &name) { const QString templateName = name.simplified(); - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); if(templateName.contains('\\') || templateName.contains('/')) { @@ -108,7 +109,7 @@ bool OptionsModel::saveTemplate(OptionsModel *model, const QString &name) bool OptionsModel::loadTemplate(OptionsModel *model, const QString &name) { - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); if(name.contains('\\') || name.contains('/')) { @@ -145,7 +146,7 @@ bool OptionsModel::loadTemplate(OptionsModel *model, const QString &name) QMap OptionsModel::loadAllTemplates(void) { QMap list; - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat); QStringList allTemplates = settings.childGroups(); @@ -169,7 +170,7 @@ QMap OptionsModel::loadAllTemplates(void) bool OptionsModel::templateExists(const QString &name) { - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat); QStringList allGroups = settings.childGroups(); return allGroups.contains(name, Qt::CaseInsensitive); @@ -177,7 +178,7 @@ bool OptionsModel::templateExists(const QString &name) bool OptionsModel::deleteTemplate(const QString &name) { - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat); if(settings.childGroups().contains(name, Qt::CaseInsensitive)) diff --git a/src/version.h b/src/version.h index bb9dc91..6eb1fbc 100644 --- a/src/version.h +++ b/src/version.h @@ -21,7 +21,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 0 -#define VER_X264_PATCH 72 +#define VER_X264_PATCH 79 #define VER_X264_MINIMUM_REV 2146 #define VER_X264_CURRENT_API 120 diff --git a/src/win_addJob.cpp b/src/win_addJob.cpp index f3fae18..14c6c53 100644 --- a/src/win_addJob.cpp +++ b/src/win_addJob.cpp @@ -189,7 +189,7 @@ AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options, bool x64suppo connect(cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected())); //Load directories - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/last.ini").arg(appDir), QSettings::IniFormat); initialDir_src = settings.value("path/directory_openFrom", initialDir_src).toString(); initialDir_out = settings.value("path/directory_saveTo", initialDir_out).toString(); @@ -305,7 +305,7 @@ void AddJobDialog::accept(void) } //Save directories - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/last.ini").arg(appDir), QSettings::IniFormat); if(settings.isWritable()) { diff --git a/src/win_main.cpp b/src/win_main.cpp index 4335885..c3e6a8e 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -541,6 +541,24 @@ void MainWindow::init(void) } } + //Check for portable mode + if(x264_portable()) + { + bool ok = false; + static const char *data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + QFile writeTest(QString("%1/%2").arg(QApplication::applicationDirPath(), QUuid::createUuid().toString())); + if(writeTest.open(QIODevice::WriteOnly)) + { + ok = (writeTest.write(data) == strlen(data)); + writeTest.remove(); + } + if(!ok) + { + int val = QMessageBox::warning(this, tr("Write Test Failed"), tr("The application was launched in portable mode, but the program path is not writable!"), tr("Quit"), tr("Ignore")); + if(val != 1) { close(); qApp->exit(-1); return; } + } + } + //Pre-release popup if(x264_is_prerelease()) { diff --git a/src/win_preferences.cpp b/src/win_preferences.cpp index 2eca11a..437b006 100644 --- a/src/win_preferences.cpp +++ b/src/win_preferences.cpp @@ -130,7 +130,7 @@ void PreferencesDialog::initPreferences(Preferences *preferences) void PreferencesDialog::loadPreferences(Preferences *preferences) { - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat); Preferences defaults; @@ -145,7 +145,7 @@ void PreferencesDialog::loadPreferences(Preferences *preferences) void PreferencesDialog::savePreferences(Preferences *preferences) { - const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + const QString appDir = x264_portable() ? QApplication::applicationDirPath() : QDesktopServices::storageLocation(QDesktopServices::DataLocation); QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat); settings.beginGroup("preferences");