From 978da1214d16e93e6f097ee10591114e0ddec866 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Wed, 17 Apr 2013 22:05:45 +0200 Subject: [PATCH] Added built-time option to make "portable" version. --- src/Config.h | 6 ++++++ src/Global.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/Config.h b/src/Config.h index e4f367e0..a61ca77b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -32,6 +32,12 @@ #define VER_LAMEXP_PATCH 2 #define VER_LAMEXP_BUILD 1274 +/////////////////////////////////////////////////////////////////////////////// +// LameXP Build Options +/////////////////////////////////////////////////////////////////////////////// + +#define VER_LAMEXP_PORTABLE_EDITION 0 + /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Global.cpp b/src/Global.cpp index ed3ba033..72e0e762 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -277,6 +277,15 @@ static struct } g_lamexp_os_version; +//Portable Mode +static struct +{ + bool bInitialized; + bool bPortableModeEnabled; + QReadWriteLock lock; +} +g_lamexp_portable; + //Win32 Theme support static struct { @@ -1428,10 +1437,34 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize) */ bool lamexp_portable_mode(void) { - QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName(); - int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive); - int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive); - return (idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2); + QReadLocker readLock(&g_lamexp_portable.lock); + + if(g_lamexp_portable.bInitialized) + { + return g_lamexp_portable.bPortableModeEnabled; + } + + readLock.unlock(); + QWriteLocker writeLock(&g_lamexp_portable.lock); + + if(!g_lamexp_portable.bInitialized) + { + if(VER_LAMEXP_PORTABLE_EDITION) + { + qWarning("LameXP portable edition!\n"); + g_lamexp_portable.bPortableModeEnabled = true; + } + else + { + QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName(); + int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive); + int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive); + g_lamexp_portable.bPortableModeEnabled = (idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2); + } + g_lamexp_portable.bInitialized = true; + } + + return g_lamexp_portable.bPortableModeEnabled; } /* @@ -2401,6 +2434,7 @@ extern "C" LAMEXP_ZERO_MEMORY(g_lamexp_ipc_ptr); LAMEXP_ZERO_MEMORY(g_lamexp_os_version); LAMEXP_ZERO_MEMORY(g_lamexp_themes_enabled); + LAMEXP_ZERO_MEMORY(g_lamexp_portable); //Make sure we will pass the check g_lamexp_entry_check_flag = ~g_lamexp_entry_check_flag;