From cdf300cd22076223cc18eecf5875230520b9c1f8 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 5 Apr 2012 13:40:52 +0200 Subject: [PATCH] Some more Wine workarounds: Disable x64 binaries, as it seems they fail to load under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64). --- src/Config.h | 2 +- src/Global.cpp | 57 ++++++++++++++++++++++++----------- src/Global.h | 1 + src/Model_FileSystem.cpp | 11 ++++--- src/Thread_Initialization.cpp | 21 +++++++------ 5 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/Config.h b/src/Config.h index 250ff967..86ff98f7 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 12 -#define VER_LAMEXP_BUILD 950 +#define VER_LAMEXP_BUILD 951 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Global.cpp b/src/Global.cpp index 0494a3a7..bcaf941a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -342,21 +342,48 @@ const QDate &lamexp_version_date(void) */ 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!"; + } + osVersion = (DWORD)((osVerInfo.dwMajorVersion << 16) | (osVerInfo.dwMinorVersion & 0xffff)); } - version = (DWORD)((osVerInfo.dwMajorVersion << 16) | (osVerInfo.dwMinorVersion & 0xffff)); } - return version; + 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(); + } + isWine_initialized = true; + } + + return isWine; } /* @@ -978,7 +1005,6 @@ static bool lamexp_check_elevation(void) bool lamexp_init_qt(int argc, char* argv[]) { static bool qt_initialized = false; - bool isWine = false; typedef BOOL (WINAPI *SetDllDirectoryProc)(WCHAR *lpPathName); //Don't initialized again, if done already @@ -1053,15 +1079,12 @@ bool lamexp_init_qt(int argc, char* argv[]) } //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 QApplication *application = new QApplication(argc, argv); application->setApplicationName("LameXP - Audio Encoder Front-End"); @@ -1103,7 +1126,7 @@ bool lamexp_init_qt(int argc, char* argv[]) } //Update console icon, if a console is attached - if(g_lamexp_console_attached && !isWine) + if(g_lamexp_console_attached && (!lamexp_detect_wine())) { typedef DWORD (__stdcall *SetConsoleIconFun)(HICON); QLibrary kernel32("kernel32.dll"); diff --git a/src/Global.h b/src/Global.h index c502ccc3..a80fab1c 100644 --- a/src/Global.h +++ b/src/Global.h @@ -98,6 +98,7 @@ unsigned int lamexp_toolver_coreaudio(void); const char *lamexp_website_url(void); const char *lamexp_support_url(void); DWORD lamexp_get_os_version(void); +bool lamexp_detect_wine(void); //Public functions void lamexp_init_console(int argc, char* argv[]); diff --git a/src/Model_FileSystem.cpp b/src/Model_FileSystem.cpp index 99462e86..e5e8a643 100644 --- a/src/Model_FileSystem.cpp +++ b/src/Model_FileSystem.cpp @@ -240,10 +240,13 @@ bool QFileSystemModelEx::hasSubfolders(const QString &path) { if(!FindFirstFileExInitialized) { - QLibrary Kernel32Lib("kernel32.dll"); - FindFirstFileExPtr = Kernel32Lib.resolve("FindFirstFileExW"); - DWORD osVersionNo = lamexp_get_os_version(); - FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1); + QLibrary kernel32Lib("kernel32.dll"); + if(kernel32Lib.load()) + { + FindFirstFileExPtr = kernel32Lib.resolve("FindFirstFileExW"); + DWORD osVersionNo = lamexp_get_os_version(); + FindFirstFileExInfoBasicOK = LAMEXP_MIN_OS_VER(osVersionNo, 6, 1); + } FindFirstFileExInitialized = true; } diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index 938c84cf..fe91df70 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -75,16 +75,17 @@ void InitializationThread::run() cpuSupport = m_cpuFeatures.x64 ? CPU_TYPE_X64_GEN : CPU_TYPE_X86_GEN; } - //Hack to disable x64 on the Windows 8 Developer Preview (not required anymore) - //if(cpuSupport & CPU_TYPE_X64_ALL) - //{ - // DWORD osVerNo = lamexp_get_os_version(); - // if((HIWORD(osVerNo) == 6) && (LOWORD(osVerNo) == 2)) - // { - // qWarning("Windows 8 (x64) developer preview detected. Going to disable all x64 support!\n"); - // cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN; - // } - //} + //Hack to disable x64 on Wine, as x64 binaries won't run under Wine (tested with Wine 1.4 under Ubuntu 12.04 x64) + if(cpuSupport & CPU_TYPE_X64_ALL) + { + //DWORD osVerNo = lamexp_get_os_version(); + //if((HIWORD(osVerNo) == 6) && (LOWORD(osVerNo) == 2)) + if(lamexp_detect_wine()) + { + qWarning("Running under Wine on a 64-Bit system. Going to disable all x64 support!\n"); + cpuSupport = (cpuSupport == CPU_TYPE_X64_SSE) ? CPU_TYPE_X86_SSE : CPU_TYPE_X86_GEN; + } + } //Print selected CPU type switch(cpuSupport)