///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include <QEventLoop>
#include <QTimer>
#include <QLibraryInfo>
+#include <QEvent>
+#include <QReadWriteLock>
+#include <QReadLocker>
+#include <QWriteLocker>
//LameXP includes
#include "Resource.h"
#include <fcntl.h>
#include <intrin.h>
#include <math.h>
+#include <time.h>
+#include <process.h>
+
+//Shell API
+#include <Shellapi.h>
//COM includes
#include <Objbase.h>
//Initialize static Qt plugins
#ifdef QT_NODLL
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
Q_IMPORT_PLUGIN(qico)
Q_IMPORT_PLUGIN(qsvg)
+#else
+Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
+Q_IMPORT_PLUGIN(QICOPlugin)
+#endif
#endif
///////////////////////////////////////////////////////////////////////////////
// TYPES
///////////////////////////////////////////////////////////////////////////////
+static const size_t g_lamexp_ipc_slots = 128;
+
typedef struct
{
unsigned int command;
unsigned int reserved_1;
unsigned int reserved_2;
char parameter[4096];
-} lamexp_ipc_t;
+}
+lamexp_ipc_data_t;
+
+typedef struct
+{
+ unsigned int pos_write;
+ unsigned int pos_read;
+ lamexp_ipc_data_t data[g_lamexp_ipc_slots];
+}
+lamexp_ipc_t;
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARS
#if (__INTEL_COMPILER >= 1200)
static const char *g_lamexp_version_compiler = "ICL 12.x";
#elif (__INTEL_COMPILER >= 1100)
- static const char *g_lamexp_version_compiler = = "ICL 11.x";
+ static const char *g_lamexp_version_compiler = "ICL 11.x";
#elif (__INTEL_COMPILER >= 1000)
- static const char *g_lamexp_version_compiler = = "ICL 10.x";
+ static const char *g_lamexp_version_compiler = "ICL 10.x";
#else
#error Compiler is not supported!
#endif
static const unsigned int g_lamexp_toolver_coreaudio = VER_LAMEXP_TOOL_COREAUDIO;
//Special folders
-static QString g_lamexp_temp_folder;
+static struct
+{
+ QString temp;
+ QString knownFolders[3];
+ QReadWriteLock lock;
+}
+g_lamexp_folder;
//Tools
-static QMap<QString, LockedFile*> g_lamexp_tool_registry;
-static QMap<QString, unsigned int> g_lamexp_tool_versions;
+static struct
+{
+ QMap<QString, LockedFile*> registry;
+ QMap<QString, unsigned int> versions;
+ QReadWriteLock lock;
+}
+g_lamexp_tools;
//Languages
static struct
QMap<QString, QString> names;
QMap<QString, unsigned int> sysid;
QMap<QString, unsigned int> cntry;
+ QReadWriteLock lock;
}
g_lamexp_translation;
//Translator
-static QTranslator *g_lamexp_currentTranslator = NULL;
+static struct
+{
+ QVariant instance;
+ QReadWriteLock lock;
+}
+g_lamexp_currentTranslator;
//Shared memory
static const struct
{
char *sharedmem;
char *semaphore_read;
+ char *semaphore_read_mutex;
char *semaphore_write;
+ char *semaphore_write_mutex;
}
g_lamexp_ipc_uuid =
{
"{21A68A42-6923-43bb-9CF6-64BF151942EE}",
"{7A605549-F58C-4d78-B4E5-06EFC34F405B}",
- "{60AA8D04-F6B8-497d-81EB-0F600F4A65B5}"
+ "{60AA8D04-F6B8-497d-81EB-0F600F4A65B5}",
+ "{726061D5-1615-4B82-871C-75FD93458E46}",
+ "{1A616023-AA6A-4519-8AF3-F7736E899977}"
};
static struct
{
QSharedMemory *sharedmem;
QSystemSemaphore *semaphore_read;
+ QSystemSemaphore *semaphore_read_mutex;
QSystemSemaphore *semaphore_write;
+ QSystemSemaphore *semaphore_write_mutex;
}
g_lamexp_ipc_ptr =
{
};
//Image formats
-static const char *g_lamexp_imageformats[] = {"png", "jpg", "gif", "ico", "svg", NULL};
+static const char *g_lamexp_imageformats[] = {"bmp", "png", "jpg", "gif", "ico", "xpm", NULL}; //"svg"
//Global locks
static QMutex g_lamexp_message_mutex;
//Main thread ID
static const DWORD g_main_thread_id = GetCurrentThreadId();
-//Session ending flag
-static bool g_sessionIsEnding = false;
+//Log file
+static FILE *g_lamexp_log_file = NULL;
+
+//CLI Arguments
+static struct
+{
+ QStringList list;
+ QReadWriteLock lock;
+}
+g_lamexp_argv;
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
*/
QDate lamexp_version_expires(void)
{
- return lamexp_version_date().addDays(LAMEXP_DEBUG ? 2 : 30);
+ return lamexp_version_date().addDays(LAMEXP_DEBUG ? 7 : 30);
}
/*
{
if(!g_lamexp_version_date.isValid())
{
- char temp[32];
- int date[3];
-
- char *this_token = NULL;
- char *next_token = NULL;
-
- strncpy_s(temp, 32, g_lamexp_version_raw_date, _TRUNCATE);
- this_token = strtok_s(temp, " ", &next_token);
+ int date[3] = {0, 0, 0}; char temp[12] = {'\0'};
+ strncpy_s(temp, 12, g_lamexp_version_raw_date, _TRUNCATE);
- for(int i = 0; i < 3; i++)
+ if(strlen(temp) == 11)
{
- date[i] = -1;
- if(this_token)
+ temp[3] = temp[6] = '\0';
+ date[2] = atoi(&temp[4]);
+ date[0] = atoi(&temp[7]);
+
+ for(int j = 0; j < 12; j++)
{
- for(int j = 0; j < 12; j++)
+ if(!_strcmpi(&temp[0], g_lamexp_months[j]))
{
- if(!_strcmpi(this_token, g_lamexp_months[j]))
- {
- date[i] = j+1;
- break;
- }
- }
- if(date[i] < 0)
- {
- date[i] = atoi(this_token);
+ date[1] = j+1;
+ break;
}
- this_token = strtok_s(NULL, " ", &next_token);
}
+
+ g_lamexp_version_date = QDate(date[0], date[1], date[2]);
}
- if(date[0] >= 0 && date[1] >= 0 && date[2] >= 0)
+ if(!g_lamexp_version_date.isValid())
{
- g_lamexp_version_date = QDate(date[2], date[0], date[1]);
+ qFatal("Internal error: Date format could not be recognized!");
}
}
*/
DWORD lamexp_get_os_version(void)
{
- OSVERSIONINFO osVerInfo;
- memset(&osVerInfo, 0, sizeof(OSVERSIONINFO));
- osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- DWORD version = 0;
+ static DWORD osVersion = 0;
- if(GetVersionEx(&osVerInfo) == TRUE)
+ if(!osVersion)
{
- if(osVerInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ OSVERSIONINFO osVerInfo;
+ memset(&osVerInfo, 0, sizeof(OSVERSIONINFO));
+ osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if(GetVersionEx(&osVerInfo) == TRUE)
{
- throw "Ouuups: Not running under Windows NT. This is not supposed to happen!";
+ if(osVerInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ {
+ throw "Ouuups: Not running under Windows NT. This is not supposed to happen!";
+ }
+ const DWORD osVerHi = (DWORD)(((DWORD)(osVerInfo.dwMajorVersion)) << 16);
+ const DWORD osVerLo = (DWORD)(((DWORD)(osVerInfo.dwMinorVersion)) & ((DWORD)(0xffff)));
+ osVersion = (DWORD)(((DWORD)(osVerHi)) | ((DWORD)(osVerLo)));
+ }
+ else
+ {
+ throw "GetVersionEx() has failed. This is not supposed to happen!";
+ }
+ }
+
+ return osVersion;
+}
+
+/*
+ * Check if we are running under wine
+ */
+bool lamexp_detect_wine(void)
+{
+ static bool isWine = false;
+ static bool isWine_initialized = false;
+
+ if(!isWine_initialized)
+ {
+ QLibrary ntdll("ntdll.dll");
+ if(ntdll.load())
+ {
+ if(ntdll.resolve("wine_nt_to_unix_file_name") != NULL) isWine = true;
+ if(ntdll.resolve("wine_get_version") != NULL) isWine = true;
+ ntdll.unload();
}
- version = (DWORD)((osVerInfo.dwMajorVersion << 16) | (osVerInfo.dwMinorVersion & 0xffff));
+ isWine_initialized = true;
}
- return version;
+ return isWine;
}
/*
QMutexLocker lock(&g_lamexp_message_mutex);
- //if((strlen(msg) > 8) && (_strnicmp(msg, "@BASE64@", 8) == 0))
- //{
- // buffer = _strdup(QByteArray::fromBase64(msg + 8).constData());
- // if(buffer) text = buffer;
- //}
+ if(g_lamexp_log_file)
+ {
+ static char prefix[] = "DWCF";
+ int index = qBound(0, static_cast<int>(type), 3);
+ unsigned int timestamp = static_cast<unsigned int>(_time64(NULL) % 3600I64);
+ QString str = QString::fromUtf8(msg).trimmed().replace('\n', '\t');
+ fprintf(g_lamexp_log_file, "[%c][%04u] %s\r\n", prefix[index], timestamp, str.toUtf8().constData());
+ fflush(g_lamexp_log_file);
+ }
if(g_lamexp_console_attached)
{
if(type == QtCriticalMsg || type == QtFatalMsg)
{
lock.unlock();
+
+ if(GetCurrentThreadId() != g_main_thread_id)
+ {
+ HANDLE mainThread = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id);
+ if(mainThread) TerminateThread(mainThread, ULONG_MAX);
+ }
+
MessageBoxW(NULL, QWCHAR(QString::fromUtf8(msg)), L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
TerminateProcess(GetCurrentProcess(), -1);
/*
* Initialize the console
*/
-void lamexp_init_console(int argc, char* argv[])
+void lamexp_init_console(const QStringList &argv)
{
bool enableConsole = lamexp_version_demo();
+ if(_environ)
+ {
+ wchar_t *logfile = NULL;
+ size_t logfile_len = 0;
+ if(!_wdupenv_s(&logfile, &logfile_len, L"LAMEXP_LOGFILE"))
+ {
+ if(logfile && (logfile_len > 0))
+ {
+ FILE *temp = NULL;
+ if(!_wfopen_s(&temp, logfile, L"wb"))
+ {
+ fprintf(temp, "%c%c%c", 0xEF, 0xBB, 0xBF);
+ g_lamexp_log_file = temp;
+ }
+ free(logfile);
+ }
+ }
+ }
+
if(!LAMEXP_DEBUG)
{
- for(int i = 0; i < argc; i++)
+ for(int i = 0; i < argv.count(); i++)
{
- if(!_stricmp(argv[i], "--console"))
+ if(!argv.at(i).compare("--console", Qt::CaseInsensitive))
{
enableConsole = true;
}
- else if(!_stricmp(argv[i], "--no-console"))
+ else if(!argv.at(i).compare("--no-console", Qt::CaseInsensitive))
{
enableConsole = false;
}
/*
* Detect CPU features
*/
-lamexp_cpu_t lamexp_detect_cpu_features(int argc, char **argv)
+lamexp_cpu_t lamexp_detect_cpu_features(const QStringList &argv)
{
typedef BOOL (WINAPI *IsWow64ProcessFun)(__in HANDLE hProcess, __out PBOOL Wow64Process);
typedef VOID (WINAPI *GetNativeSystemInfoFun)(__out LPSYSTEM_INFO lpSystemInfo);
features.x64 = true;
#endif
- if((argv != NULL) && (argc > 0))
+ if(argv.count() > 0)
{
bool flag = false;
- for(int i = 0; i < argc; i++)
+ for(int i = 0; i < argv.count(); i++)
{
- if(!_stricmp("--force-cpu-no-64bit", argv[i])) { flag = true; features.x64 = false; }
- if(!_stricmp("--force-cpu-no-sse", argv[i])) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
- if(!_stricmp("--force-cpu-no-intel", argv[i])) { flag = true; features.intel = false; }
+ if(!argv[i].compare("--force-cpu-no-64bit", Qt::CaseInsensitive)) { flag = true; features.x64 = false; }
+ if(!argv[i].compare("--force-cpu-no-sse", Qt::CaseInsensitive)) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
+ if(!argv[i].compare("--force-cpu-no-intel", Qt::CaseInsensitive)) { flag = true; features.intel = false; }
}
if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n");
}
/*
* Check for debugger (detect routine)
*/
-static bool lamexp_check_for_debugger(void)
+static __forceinline bool lamexp_check_for_debugger(void)
{
+ if(IsDebuggerPresent())
+ {
+ return true;
+ }
+
+ __try
+ {
+ CloseHandle((HANDLE) 0x7FFFFFFF);
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER)
+ {
+ return true;
+ }
+
__try
{
DebugBreak();
}
- __except(GetExceptionCode() == EXCEPTION_BREAKPOINT ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
+ __except(EXCEPTION_EXECUTE_HANDLER)
{
return false;
}
+
return true;
}
/*
* Check for debugger (thread proc)
*/
-static void WINAPI lamexp_debug_thread_proc(__in LPVOID lpParameter)
+static unsigned int __stdcall lamexp_debug_thread_proc(LPVOID lpParameter)
{
- while(!(IsDebuggerPresent() || lamexp_check_for_debugger()))
+ while(!lamexp_check_for_debugger())
{
- Sleep(333);
+ Sleep(32);
+ }
+ if(HANDLE thrd = OpenThread(THREAD_TERMINATE, FALSE, g_main_thread_id))
+ {
+ if(TerminateThread(thrd, -1))
+ {
+ FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
+ }
+ CloseHandle(thrd);
}
TerminateProcess(GetCurrentProcess(), -1);
+ return 666;
}
/*
*/
static HANDLE lamexp_debug_thread_init(void)
{
- if(IsDebuggerPresent() || lamexp_check_for_debugger())
+ if(lamexp_check_for_debugger())
{
FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
TerminateProcess(GetCurrentProcess(), -1);
}
- return CreateThread(NULL, NULL, reinterpret_cast<LPTHREAD_START_ROUTINE>(&lamexp_debug_thread_proc), NULL, NULL, NULL);
+ return (HANDLE) _beginthreadex(NULL, 0, lamexp_debug_thread_proc, NULL, 0, NULL);
}
/*
* Check for compatibility mode
*/
-static bool lamexp_check_compatibility_mode(const char *exportName, const char *executableName)
+static bool lamexp_check_compatibility_mode(const char *exportName, const QString &executableName)
{
QLibrary kernel32("kernel32.dll");
- if(exportName != NULL)
+ if((exportName != NULL) && kernel32.load())
{
if(kernel32.resolve(exportName) != NULL)
{
qWarning("Function '%s' exported from 'kernel32.dll' -> Windows compatibility mode!", exportName);
- qFatal("%s", QApplication::tr("Executable '%1' doesn't support Windows compatibility mode.").arg(QString::fromLatin1(executableName)).toLatin1().constData());
+ qFatal("%s", QApplication::tr("Executable '%1' doesn't support Windows compatibility mode.").arg(executableName).toLatin1().constData());
return false;
}
}
}
/*
- * Qt event filter
+ * Broadcast event to all windows
*/
-static bool lamexp_event_filter(void *message, long *result)
+static bool lamexp_broadcast(int eventType, bool onlyToVisible)
{
- switch(reinterpret_cast<MSG*>(message)->message)
+ if(QApplication *app = dynamic_cast<QApplication*>(QApplication::instance()))
{
- case WM_QUERYENDSESSION:
- qWarning("WM_QUERYENDSESSION message received!");
- if(!g_sessionIsEnding)
+ qDebug("Broadcasting %d", eventType);
+
+ bool allOk = true;
+ QEvent poEvent(static_cast<QEvent::Type>(eventType));
+ QWidgetList list = app->topLevelWidgets();
+
+ while(!list.isEmpty())
{
- g_sessionIsEnding = true;
- if(QApplication *app = reinterpret_cast<QApplication*>(QApplication::instance()))
+ QWidget *widget = list.takeFirst();
+ if(!onlyToVisible || widget->isVisible())
{
- for(int i = 0; i < 128; i++)
+ if(!app->sendEvent(widget, &poEvent))
{
- app->closeAllWindows();
- app->processEvents();
- Sleep(8);
+ allOk = false;
}
}
}
- *result = TRUE;
+
+ qDebug("Broadcast %d done (%s)", eventType, (allOk ? "OK" : "Stopped"));
+ return allOk;
+ }
+ else
+ {
+ qWarning("Broadcast failed, could not get QApplication instance!");
+ return false;
+ }
+}
+
+/*
+ * Qt event filter
+ */
+static bool lamexp_event_filter(void *message, long *result)
+{
+ if((!(LAMEXP_DEBUG)) && lamexp_check_for_debugger())
+ {
+ FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
+ TerminateProcess(GetCurrentProcess(), -1);
+ }
+
+ switch(reinterpret_cast<MSG*>(message)->message)
+ {
+ case WM_QUERYENDSESSION:
+ qWarning("WM_QUERYENDSESSION message received!");
+ *result = lamexp_broadcast(lamexp_event_queryendsession, false) ? TRUE : FALSE;
return true;
case WM_ENDSESSION:
qWarning("WM_ENDSESSION message received!");
if(reinterpret_cast<MSG*>(message)->wParam == TRUE)
{
- g_sessionIsEnding = true;
+ lamexp_broadcast(lamexp_event_endsession, false);
if(QApplication *app = reinterpret_cast<QApplication*>(QApplication::instance()))
{
+ app->closeAllWindows();
app->quit();
- app->processEvents();
- lamexp_finalization();
- exit(1);
}
+ lamexp_finalization();
+ exit(1);
}
*result = 0;
return true;
bool lamexp_init_qt(int argc, char* argv[])
{
static bool qt_initialized = false;
- bool isWine = false;
typedef BOOL (WINAPI *SetDllDirectoryProc)(WCHAR *lpPathName);
+ const QStringList &arguments = lamexp_arguments();
//Don't initialized again, if done already
if(qt_initialized)
{
return true;
}
-
+
//Secure DLL loading
QLibrary kernel32("kernel32.dll");
if(kernel32.load())
}
//Extract executable name from argv[] array
- char *executableName = argv[0];
- while(char *temp = strpbrk(executableName, "\\/:?"))
+ QString executableName = QLatin1String("LameXP.exe");
+ if(arguments.count() > 0)
{
- executableName = temp + 1;
+ static const char *delimiters = "\\/:?";
+ executableName = arguments[0].trimmed();
+ for(int i = 0; delimiters[i]; i++)
+ {
+ int temp = executableName.lastIndexOf(QChar(delimiters[i]));
+ if(temp >= 0) executableName = executableName.mid(temp + 1);
+ }
+ executableName = executableName.trimmed();
+ if(executableName.isEmpty())
+ {
+ executableName = QLatin1String("LameXP.exe");
+ }
}
//Check Qt version
+#ifdef QT_BUILD_KEY
qDebug("Using Qt v%s [%s], %s, %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"), QLibraryInfo::buildKey().toLatin1().constData());
qDebug("Compiled with Qt v%s [%s], %s\n", QT_VERSION_STR, QT_PACKAGEDATE_STR, QT_BUILD_KEY);
if(_stricmp(qVersion(), QT_VERSION_STR))
{
- qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(QString::fromLatin1(executableName), QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
+ qFatal("%s", QApplication::tr("Executable '%1' requires Qt v%2, but found Qt v%3.").arg(executableName, QString::fromLatin1(QT_VERSION_STR), QString::fromLatin1(qVersion())).toLatin1().constData());
return false;
}
if(QLibraryInfo::buildKey().compare(QString::fromLatin1(QT_BUILD_KEY), Qt::CaseInsensitive))
{
- qFatal("%s", QApplication::tr("Executable '%1' was built for Qt '%2', but found Qt '%3'.").arg(QString::fromLatin1(executableName), QString::fromLatin1(QT_BUILD_KEY), QLibraryInfo::buildKey()).toLatin1().constData());
+ qFatal("%s", QApplication::tr("Executable '%1' was built for Qt '%2', but found Qt '%3'.").arg(executableName, QString::fromLatin1(QT_BUILD_KEY), QLibraryInfo::buildKey()).toLatin1().constData());
return false;
}
+#else
+ qDebug("Using Qt v%s [%s], %s", qVersion(), QLibraryInfo::buildDate().toString(Qt::ISODate).toLatin1().constData(), (qSharedBuild() ? "DLL" : "Static"));
+ qDebug("Compiled with Qt v%s [%s]\n", QT_VERSION_STR, QT_PACKAGEDATE_STR);
+#endif
//Check the Windows version
switch(QSysInfo::windowsVersion() & QSysInfo::WV_NT_based)
{
case 0:
case QSysInfo::WV_NT:
- qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(QString::fromLatin1(executableName)).toLatin1().constData());
+ qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(executableName).toLatin1().constData());
break;
case QSysInfo::WV_2000:
qDebug("Running on Windows 2000 (not officially supported!).\n");
break;
case QSysInfo::WV_WINDOWS7:
qDebug("Running on Windows 7 or Windows Server 2008 R2.\n");
- lamexp_check_compatibility_mode(NULL, executableName);
+ lamexp_check_compatibility_mode("CreateFile2", executableName);
break;
default:
{
DWORD osVersionNo = lamexp_get_os_version();
- qWarning("Running on an unknown/untested WinNT-based OS (v%u.%u).\n", HIWORD(osVersionNo), LOWORD(osVersionNo));
+ if(LAMEXP_EQL_OS_VER(osVersionNo, 6, 2))
+ {
+ qDebug("Running on Windows 8 or Windows Server 2012\n");
+ lamexp_check_compatibility_mode(NULL, executableName);
+ }
+ else
+ {
+ qWarning("Running on an unknown/untested WinNT-based OS (v%u.%u).\n", HIWORD(osVersionNo), LOWORD(osVersionNo));
+ }
}
break;
}
//Check for Wine
- QLibrary ntdll("ntdll.dll");
- if(ntdll.load())
+ if(lamexp_detect_wine())
{
- if(ntdll.resolve("wine_nt_to_unix_file_name") != NULL) isWine = true;
- if(ntdll.resolve("wine_get_version") != NULL) isWine = true;
- if(isWine) qWarning("It appears we are running under Wine, unexpected things might happen!\n");
- ntdll.unload();
+ qWarning("It appears we are running under Wine, unexpected things might happen!\n");
}
- //Create Qt application instance and setup version info
+ //Set text Codec for locale
+ QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
+
+ //Create Qt application instance
QApplication *application = new QApplication(argc, argv);
+
+ //Load plugins from application directory
+ QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath());
+ qDebug("Library Path:\n%s\n", QApplication::libraryPaths().first().toUtf8().constData());
+
+ //Set application properties
application->setApplicationName("LameXP - Audio Encoder Front-End");
application->setApplicationVersion(QString().sprintf("%d.%02d.%04d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
application->setOrganizationName("LoRd_MuldeR");
application->setWindowIcon(lamexp_app_icon());
application->setEventFilter(lamexp_event_filter);
- //Set text Codec for locale
- QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
-
- //Load plugins from application directory
- QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath());
- qDebug("Library Path:\n%s\n", QApplication::libraryPaths().first().toUtf8().constData());
-
//Check for supported image formats
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
for(int i = 0; g_lamexp_imageformats[i]; i++)
return false;
}
}
-
+
//Add default translations
+ QWriteLocker writeLockTranslations(&g_lamexp_translation.lock);
g_lamexp_translation.files.insert(LAMEXP_DEFAULT_LANGID, "");
g_lamexp_translation.names.insert(LAMEXP_DEFAULT_LANGID, "English");
+ writeLockTranslations.unlock();
//Check for process elevation
- if(!lamexp_check_elevation())
+ if((!lamexp_check_elevation()) && (!lamexp_detect_wine()))
{
- if(QMessageBox::warning(NULL, "LameXP", "<nobr>LameXP was started with elevated rights. This is a potential security risk!</nobr>", "Quit Program (Recommended)", "Ignore") == 0)
+ QMessageBox messageBox(QMessageBox::Warning, "LameXP", "<nobr>LameXP was started with 'elevated' rights, altough LameXP does not need these rights.<br>Running an applications with unnecessary rights is a potential security risk!</nobr>", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
+ messageBox.addButton("Quit Program (Recommended)", QMessageBox::NoRole);
+ messageBox.addButton("Ignore", QMessageBox::NoRole);
+ if(messageBox.exec() == 0)
{
return false;
}
}
//Update console icon, if a console is attached
- if(g_lamexp_console_attached && !isWine)
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
+ if(g_lamexp_console_attached && (!lamexp_detect_wine()))
{
typedef DWORD (__stdcall *SetConsoleIconFun)(HICON);
QLibrary kernel32("kernel32.dll");
kernel32.unload();
}
}
+#endif
//Done
qt_initialized = true;
*/
int lamexp_init_ipc(void)
{
- if(g_lamexp_ipc_ptr.sharedmem && g_lamexp_ipc_ptr.semaphore_read && g_lamexp_ipc_ptr.semaphore_write)
+ if(g_lamexp_ipc_ptr.sharedmem && g_lamexp_ipc_ptr.semaphore_read && g_lamexp_ipc_ptr.semaphore_write && g_lamexp_ipc_ptr.semaphore_read_mutex && g_lamexp_ipc_ptr.semaphore_write_mutex)
{
return 0;
}
g_lamexp_ipc_ptr.semaphore_read = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_read), 0);
g_lamexp_ipc_ptr.semaphore_write = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_write), 0);
+ g_lamexp_ipc_ptr.semaphore_read_mutex = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_read_mutex), 0);
+ g_lamexp_ipc_ptr.semaphore_write_mutex = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_write_mutex), 0);
if(g_lamexp_ipc_ptr.semaphore_read->error() != QSystemSemaphore::NoError)
{
QString errorMessage = g_lamexp_ipc_ptr.semaphore_read->errorString();
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
qFatal("Failed to create system smaphore: %s", errorMessage.toUtf8().constData());
return -1;
}
QString errorMessage = g_lamexp_ipc_ptr.semaphore_write->errorString();
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
+ qFatal("Failed to create system smaphore: %s", errorMessage.toUtf8().constData());
+ return -1;
+ }
+ if(g_lamexp_ipc_ptr.semaphore_read_mutex->error() != QSystemSemaphore::NoError)
+ {
+ QString errorMessage = g_lamexp_ipc_ptr.semaphore_read_mutex->errorString();
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
+ qFatal("Failed to create system smaphore: %s", errorMessage.toUtf8().constData());
+ return -1;
+ }
+ if(g_lamexp_ipc_ptr.semaphore_write_mutex->error() != QSystemSemaphore::NoError)
+ {
+ QString errorMessage = g_lamexp_ipc_ptr.semaphore_write_mutex->errorString();
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
qFatal("Failed to create system smaphore: %s", errorMessage.toUtf8().constData());
return -1;
}
else
{
QString errorMessage = g_lamexp_ipc_ptr.sharedmem->errorString();
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.sharedmem);
qFatal("Failed to attach to shared memory: %s", errorMessage.toUtf8().constData());
return -1;
}
else
{
QString errorMessage = g_lamexp_ipc_ptr.sharedmem->errorString();
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.sharedmem);
qFatal("Failed to create shared memory: %s", errorMessage.toUtf8().constData());
return -1;
}
}
memset(g_lamexp_ipc_ptr.sharedmem->data(), 0, sizeof(lamexp_ipc_t));
- g_lamexp_ipc_ptr.semaphore_write->release();
+ g_lamexp_ipc_ptr.semaphore_write->release(g_lamexp_ipc_slots);
+ g_lamexp_ipc_ptr.semaphore_read_mutex->release();
+ g_lamexp_ipc_ptr.semaphore_write_mutex->release();
return 0;
}
*/
void lamexp_ipc_send(unsigned int command, const char* message)
{
- if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write)
+ if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write || !g_lamexp_ipc_ptr.semaphore_read_mutex || !g_lamexp_ipc_ptr.semaphore_write_mutex)
{
throw "Shared memory for IPC not initialized yet.";
}
- lamexp_ipc_t *lamexp_ipc = new lamexp_ipc_t;
- memset(lamexp_ipc, 0, sizeof(lamexp_ipc_t));
- lamexp_ipc->command = command;
+ lamexp_ipc_data_t ipc_data;
+ memset(&ipc_data, 0, sizeof(lamexp_ipc_data_t));
+ ipc_data.command = command;
+
if(message)
{
- strncpy_s(lamexp_ipc->parameter, 4096, message, _TRUNCATE);
+ strncpy_s(ipc_data.parameter, 4096, message, _TRUNCATE);
}
if(g_lamexp_ipc_ptr.semaphore_write->acquire())
{
- memcpy(g_lamexp_ipc_ptr.sharedmem->data(), lamexp_ipc, sizeof(lamexp_ipc_t));
- g_lamexp_ipc_ptr.semaphore_read->release();
+ if(g_lamexp_ipc_ptr.semaphore_write_mutex->acquire())
+ {
+ lamexp_ipc_t *ptr = reinterpret_cast<lamexp_ipc_t*>(g_lamexp_ipc_ptr.sharedmem->data());
+ memcpy(&ptr->data[ptr->pos_write], &ipc_data, sizeof(lamexp_ipc_data_t));
+ ptr->pos_write = (ptr->pos_write + 1) % g_lamexp_ipc_slots;
+ g_lamexp_ipc_ptr.semaphore_read->release();
+ g_lamexp_ipc_ptr.semaphore_write_mutex->release();
+ }
}
-
- LAMEXP_DELETE(lamexp_ipc);
}
/*
*command = 0;
message[0] = '\0';
- if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write)
+ if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write || !g_lamexp_ipc_ptr.semaphore_read_mutex || !g_lamexp_ipc_ptr.semaphore_write_mutex)
{
throw "Shared memory for IPC not initialized yet.";
}
- lamexp_ipc_t *lamexp_ipc = new lamexp_ipc_t;
- memset(lamexp_ipc, 0, sizeof(lamexp_ipc_t));
+ lamexp_ipc_data_t ipc_data;
+ memset(&ipc_data, 0, sizeof(lamexp_ipc_data_t));
if(g_lamexp_ipc_ptr.semaphore_read->acquire())
{
- memcpy(lamexp_ipc, g_lamexp_ipc_ptr.sharedmem->data(), sizeof(lamexp_ipc_t));
- g_lamexp_ipc_ptr.semaphore_write->release();
-
- if(!(lamexp_ipc->reserved_1 || lamexp_ipc->reserved_2))
- {
- *command = lamexp_ipc->command;
- strncpy_s(message, buffSize, lamexp_ipc->parameter, _TRUNCATE);
- }
- else
+ if(g_lamexp_ipc_ptr.semaphore_read_mutex->acquire())
{
- qWarning("Malformed IPC message, will be ignored");
+ lamexp_ipc_t *ptr = reinterpret_cast<lamexp_ipc_t*>(g_lamexp_ipc_ptr.sharedmem->data());
+ memcpy(&ipc_data, &ptr->data[ptr->pos_read], sizeof(lamexp_ipc_data_t));
+ ptr->pos_read = (ptr->pos_read + 1) % g_lamexp_ipc_slots;
+ g_lamexp_ipc_ptr.semaphore_write->release();
+ g_lamexp_ipc_ptr.semaphore_read_mutex->release();
+
+ if(!(ipc_data.reserved_1 || ipc_data.reserved_2))
+ {
+ *command = ipc_data.command;
+ strncpy_s(message, buffSize, ipc_data.parameter, _TRUNCATE);
+ }
+ else
+ {
+ qWarning("Malformed IPC message, will be ignored");
+ }
}
}
-
- LAMEXP_DELETE(lamexp_ipc);
}
/*
*/
const QString &lamexp_temp_folder2(void)
{
- static const char *TEMP_STR = "Temp";
- const QString WRITE_TEST_DATA = lamexp_rand_str();
- const QString SUB_FOLDER = lamexp_rand_str();
+ QReadLocker readLock(&g_lamexp_folder.lock);
//Already initialized?
- if(!g_lamexp_temp_folder.isEmpty())
+ if(!g_lamexp_folder.temp.isEmpty())
{
- if(QDir(g_lamexp_temp_folder).exists())
+ if(QDir(g_lamexp_folder.temp).exists())
{
- return g_lamexp_temp_folder;
- }
- else
- {
- g_lamexp_temp_folder.clear();
+ return g_lamexp_folder.temp;
}
}
+ readLock.unlock();
+ QWriteLocker writeLock(&g_lamexp_folder.lock);
+ g_lamexp_folder.temp.clear();
+
+ static const char *TEMP_STR = "Temp";
+ const QString WRITE_TEST_DATA = lamexp_rand_str();
+ const QString SUB_FOLDER = lamexp_rand_str();
+
//Try the %TMP% or %TEMP% directory first
QDir temp = QDir::temp();
if(temp.exists())
{
if(testFile.write(WRITE_TEST_DATA.toLatin1().constData()) >= strlen(WRITE_TEST_DATA.toLatin1().constData()))
{
- g_lamexp_temp_folder = temp.canonicalPath();
+ g_lamexp_folder.temp = temp.canonicalPath();
}
testFile.remove();
}
}
- if(!g_lamexp_temp_folder.isEmpty())
+ if(!g_lamexp_folder.temp.isEmpty())
{
- return g_lamexp_temp_folder;
+ return g_lamexp_folder.temp;
}
}
{
if(testFile.write(WRITE_TEST_DATA.toLatin1().constData()) >= strlen(WRITE_TEST_DATA.toLatin1().constData()))
{
- g_lamexp_temp_folder = localAppData.canonicalPath();
+ g_lamexp_folder.temp = localAppData.canonicalPath();
}
testFile.remove();
}
}
}
}
- if(!g_lamexp_temp_folder.isEmpty())
+ if(!g_lamexp_folder.temp.isEmpty())
{
- return g_lamexp_temp_folder;
+ return g_lamexp_folder.temp;
}
}
//Failed to create TEMP folder!
qFatal("Temporary directory could not be initialized!\n\nFirst attempt:\n%s\n\nSecond attempt:\n%s", temp.canonicalPath().toUtf8().constData(), localAppData.canonicalPath().toUtf8().constData());
- return g_lamexp_temp_folder;
+ return g_lamexp_folder.temp;
}
/*
*/
void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version)
{
- if(g_lamexp_tool_registry.contains(toolName.toLower()))
+ QWriteLocker writeLock(&g_lamexp_tools.lock);
+
+ if(g_lamexp_tools.registry.contains(toolName.toLower()))
{
throw "lamexp_register_tool: Tool is already registered!";
}
- g_lamexp_tool_registry.insert(toolName.toLower(), file);
- g_lamexp_tool_versions.insert(toolName.toLower(), version);
+ g_lamexp_tools.registry.insert(toolName.toLower(), file);
+ g_lamexp_tools.versions.insert(toolName.toLower(), version);
}
/*
*/
bool lamexp_check_tool(const QString &toolName)
{
- return g_lamexp_tool_registry.contains(toolName.toLower());
+ QReadLocker readLock(&g_lamexp_tools.lock);
+ return g_lamexp_tools.registry.contains(toolName.toLower());
}
/*
*/
const QString lamexp_lookup_tool(const QString &toolName)
{
- if(g_lamexp_tool_registry.contains(toolName.toLower()))
+ QReadLocker readLock(&g_lamexp_tools.lock);
+
+ if(g_lamexp_tools.registry.contains(toolName.toLower()))
{
- return g_lamexp_tool_registry.value(toolName.toLower())->filePath();
+ return g_lamexp_tools.registry.value(toolName.toLower())->filePath();
}
else
{
*/
unsigned int lamexp_tool_version(const QString &toolName)
{
- if(g_lamexp_tool_versions.contains(toolName.toLower()))
+ QReadLocker readLock(&g_lamexp_tools.lock);
+
+ if(g_lamexp_tools.versions.contains(toolName.toLower()))
{
- return g_lamexp_tool_versions.value(toolName.toLower());
+ return g_lamexp_tools.versions.value(toolName.toLower());
}
else
{
*/
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country)
{
+ QWriteLocker writeLockTranslations(&g_lamexp_translation.lock);
+
if(qmFile.isEmpty() || langName.isEmpty() || systemId < 1)
{
return false;
*/
QStringList lamexp_query_translations(void)
{
+ QReadLocker writeLockTranslations(&g_lamexp_translation.lock);
return g_lamexp_translation.files.keys();
}
*/
QString lamexp_translation_name(const QString &langId)
{
+ QReadLocker writeLockTranslations(&g_lamexp_translation.lock);
return g_lamexp_translation.names.value(langId.toLower(), QString());
}
*/
unsigned int lamexp_translation_sysid(const QString &langId)
{
+ QReadLocker writeLockTranslations(&g_lamexp_translation.lock);
return g_lamexp_translation.sysid.value(langId.toLower(), 0);
}
*/
unsigned int lamexp_translation_country(const QString &langId)
{
+ QReadLocker writeLockTranslations(&g_lamexp_translation.lock);
return g_lamexp_translation.cntry.value(langId.toLower(), 0);
}
}
else
{
+ QReadLocker readLock(&g_lamexp_translation.lock);
QString qmFile = g_lamexp_translation.files.value(langId.toLower(), QString());
if(!qmFile.isEmpty())
{
*/
bool lamexp_install_translator_from_file(const QString &qmFile)
{
+ QWriteLocker writeLock(&g_lamexp_currentTranslator.lock);
bool success = false;
- if(!g_lamexp_currentTranslator)
+ if(!g_lamexp_currentTranslator.instance.isValid())
{
- g_lamexp_currentTranslator = new QTranslator();
+ g_lamexp_currentTranslator.instance.setValue<QObject*>(new QTranslator());
}
if(!qmFile.isEmpty())
{
QString qmPath = QFileInfo(qmFile).canonicalFilePath();
- QApplication::removeTranslator(g_lamexp_currentTranslator);
- success = g_lamexp_currentTranslator->load(qmPath);
- QApplication::installTranslator(g_lamexp_currentTranslator);
- if(!success)
+ QTranslator *poTranslator = dynamic_cast<QTranslator*>(g_lamexp_currentTranslator.instance.value<QObject*>());
+ QApplication::removeTranslator(poTranslator);
+ if(success = poTranslator->load(qmPath))
+ {
+ QApplication::installTranslator(poTranslator);
+ }
+ else
{
qWarning("Failed to load translation:\n\"%s\"", qmPath.toLatin1().constData());
}
}
else
{
- QApplication::removeTranslator(g_lamexp_currentTranslator);
+ QApplication::removeTranslator(dynamic_cast<QTranslator*>(g_lamexp_currentTranslator.instance.value<QObject*>()));
success = true;
}
return success;
}
+const QStringList &lamexp_arguments(void)
+{
+ QReadLocker readLock(&g_lamexp_argv.lock);
+
+ if(g_lamexp_argv.list.isEmpty())
+ {
+ readLock.unlock();
+ QWriteLocker writeLock(&g_lamexp_argv.lock);
+
+ int nArgs = 0;
+ LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
+
+ if(NULL != szArglist)
+ {
+ for(int i = 0; i < nArgs; i++)
+ {
+ g_lamexp_argv.list << WCHAR2QSTR(szArglist[i]);
+ }
+ LocalFree(szArglist);
+ }
+ else
+ {
+ qWarning("CommandLineToArgvW() has failed !!!");
+ }
+ }
+
+ return g_lamexp_argv.list;
+}
+
/*
* Locate known folder on local system
*/
static const GUID GUID_PROGRAM_FILES = {0x905e63b6,0xc1bf,0x494e,{0xb2,0x9c,0x65,0xb7,0x32,0xd3,0xd2,0x1a}};
static const GUID GUID_SYSTEM_FOLDER = {0x1AC14E77,0x02E7,0x4E5D,{0xB7,0x44,0x2E,0xB1,0xAE,0x51,0x98,0xB7}};
- static QLibrary *Kernel32Lib = NULL;
- static SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL;
- static SHGetFolderPathFun SHGetFolderPathPtr = NULL;
-
- if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr))
- {
- if(!Kernel32Lib) Kernel32Lib = new QLibrary("shell32.dll");
- SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib->resolve("SHGetKnownFolderPath");
- SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib->resolve("SHGetFolderPathW");
- }
+ QReadLocker readLock(&g_lamexp_folder.lock);
int folderCSIDL = -1;
GUID folderGUID = {0x0000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
+ size_t folderCacheId = size_t(-1);
switch(folder_id)
{
case lamexp_folder_localappdata:
+ folderCacheId = 0;
folderCSIDL = CSIDL_LOCAL_APPDATA;
folderGUID = GUID_LOCAL_APPDATA;
break;
case lamexp_folder_programfiles:
+ folderCacheId = 1;
folderCSIDL = CSIDL_PROGRAM_FILES;
folderGUID = GUID_PROGRAM_FILES;
break;
case lamexp_folder_systemfolder:
+ folderCacheId = 2;
folderCSIDL = CSIDL_SYSTEM_FOLDER;
folderGUID = GUID_SYSTEM_FOLDER;
break;
default:
+ qWarning("Invalid 'known' folder was requested!");
return QString();
break;
}
+ //Already in cache?
+ if(!g_lamexp_folder.knownFolders[folderCacheId].isEmpty())
+ {
+ return g_lamexp_folder.knownFolders[folderCacheId];
+ }
+
+ readLock.unlock();
+ QWriteLocker writeLock(&g_lamexp_folder.lock);
+
+ static SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL;
+ static SHGetFolderPathFun SHGetFolderPathPtr = NULL;
+
+ if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr))
+ {
+ QLibrary kernel32Lib("shell32.dll");
+ if(kernel32Lib.load())
+ {
+ SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) kernel32Lib.resolve("SHGetKnownFolderPath");
+ SHGetFolderPathPtr = (SHGetFolderPathFun) kernel32Lib.resolve("SHGetFolderPathW");
+ }
+ }
+
QString folder;
if(SHGetKnownFolderPathPtr)
delete [] path;
}
+ //Update cache
+ if(!folder.isEmpty())
+ {
+ g_lamexp_folder.knownFolders[folderCacheId] = folder;
+ }
+
return folder;
}
{
typedef int (WINAPI *IsAppThemedFun)(void);
- bool isAppThemed = false;
- QLibrary uxTheme(QString("%1/UxTheme.dll").arg(lamexp_known_folder(lamexp_folder_systemfolder)));
- IsAppThemedFun IsAppThemedPtr = (IsAppThemedFun) uxTheme.resolve("IsAppThemed");
+ static bool isAppThemed = false;
+ static bool isAppThemed_initialized = false;
- if(IsAppThemedPtr)
+ if(!isAppThemed_initialized)
{
- isAppThemed = IsAppThemedPtr();
- if(!isAppThemed)
+ IsAppThemedFun IsAppThemedPtr = NULL;
+ QLibrary uxTheme(QString("%1/UxTheme.dll").arg(lamexp_known_folder(lamexp_folder_systemfolder)));
+ if(uxTheme.load())
{
- qWarning("Theme support is disabled for this process!");
+ IsAppThemedPtr = (IsAppThemedFun) uxTheme.resolve("IsAppThemed");
}
+ if(IsAppThemedPtr)
+ {
+ isAppThemed = IsAppThemedPtr();
+ if(!isAppThemed)
+ {
+ qWarning("Theme support is disabled for this process!");
+ }
+ }
+ isAppThemed_initialized = true;
}
return isAppThemed;
}
/*
- * Check if the session is about to end
+ * Application entry point (runs before static initializers)
*/
-bool lamexp_session_ending(void)
+extern "C"
{
- return g_sessionIsEnding;
+ int WinMainCRTStartup(void);
+
+ int lamexp_entry_point(void)
+ {
+ if((!LAMEXP_DEBUG) && lamexp_check_for_debugger())
+ {
+ FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
+ TerminateProcess(GetCurrentProcess(), -1);
+ }
+ return WinMainCRTStartup();
+ }
}
/*
*/
void lamexp_finalization(void)
{
+ qDebug("lamexp_finalization()");
+
//Free all tools
- if(!g_lamexp_tool_registry.isEmpty())
+ if(!g_lamexp_tools.registry.isEmpty())
{
- QStringList keys = g_lamexp_tool_registry.keys();
+ QStringList keys = g_lamexp_tools.registry.keys();
for(int i = 0; i < keys.count(); i++)
{
- LAMEXP_DELETE(g_lamexp_tool_registry[keys.at(i)]);
+ LAMEXP_DELETE(g_lamexp_tools.registry[keys.at(i)]);
}
- g_lamexp_tool_registry.clear();
- g_lamexp_tool_versions.clear();
+ g_lamexp_tools.registry.clear();
+ g_lamexp_tools.versions.clear();
}
//Delete temporary files
- if(!g_lamexp_temp_folder.isEmpty())
+ if(!g_lamexp_folder.temp.isEmpty())
{
for(int i = 0; i < 100; i++)
{
- if(lamexp_clean_folder(g_lamexp_temp_folder))
+ if(lamexp_clean_folder(g_lamexp_folder.temp))
{
break;
}
Sleep(125);
}
- g_lamexp_temp_folder.clear();
+ g_lamexp_folder.temp.clear();
}
//Clear languages
- if(g_lamexp_currentTranslator)
+ if(g_lamexp_currentTranslator.instance.isValid())
{
- QApplication::removeTranslator(g_lamexp_currentTranslator);
- LAMEXP_DELETE(g_lamexp_currentTranslator);
+ QTranslator *poTranslator = dynamic_cast<QTranslator*>(g_lamexp_currentTranslator.instance.value<QObject*>());
+ g_lamexp_currentTranslator.instance.clear();
+ QApplication::removeTranslator(poTranslator);
+ LAMEXP_DELETE(poTranslator);
}
g_lamexp_translation.files.clear();
g_lamexp_translation.names.clear();
+ g_lamexp_translation.cntry.clear();
+ g_lamexp_translation.sysid.clear();
//Destroy Qt application object
QApplication *application = dynamic_cast<QApplication*>(QApplication::instance());
LAMEXP_DELETE(g_lamexp_ipc_ptr.sharedmem);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read);
LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
+ LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
+
+ //Free STDOUT and STDERR buffers
+ if(g_lamexp_console_attached)
+ {
+ if(std::filebuf *tmp = dynamic_cast<std::filebuf*>(std::cout.rdbuf()))
+ {
+ std::cout.rdbuf(NULL);
+ LAMEXP_DELETE(tmp);
+ }
+ if(std::filebuf *tmp = dynamic_cast<std::filebuf*>(std::cerr.rdbuf()))
+ {
+ std::cerr.rdbuf(NULL);
+ LAMEXP_DELETE(tmp);
+ }
+ }
+
+ //Close log file
+ if(g_lamexp_log_file)
+ {
+ fclose(g_lamexp_log_file);
+ g_lamexp_log_file = NULL;
+ }
+
+ //Free CLI Arguments
+ g_lamexp_argv.list.clear();
}
/*