diff --git a/src/Config.h b/src/Config.h index 4ed9e3c0..3024e0a6 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 153 +#define VER_LAMEXP_BUILD 155 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Global.cpp b/src/Global.cpp index 0b3218a4..a75d33fc 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -619,50 +619,18 @@ const QString &lamexp_temp_folder(void) if(g_lamexp_temp_folder.isEmpty()) { QDir temp = QDir::temp(); + QDir localAppData = QDir(lamexp_known_folder(lamexp_folder_localappdata)); - QLibrary Kernel32Lib("shell32.dll"); - SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib.resolve("SHGetKnownFolderPath"); - SHGetFolderPathFun SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib.resolve("SHGetFolderPathW"); - - if(SHGetKnownFolderPathPtr) + if(!localAppData.path().isEmpty() && localAppData.exists()) { - WCHAR *localAppDataPath = NULL; - if(SHGetKnownFolderPathPtr(LocalAppDataID, 0x00008000, NULL, &localAppDataPath) == S_OK) + if(!localAppData.entryList(QDir::AllDirs).contains(TEMP_STR, Qt::CaseInsensitive)) { - QDir localAppData = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(localAppDataPath)))); - if(localAppData.exists()) - { - if(!localAppData.entryList(QDir::AllDirs).contains(TEMP_STR)) - { - localAppData.mkdir(TEMP_STR); - } - if(localAppData.cd(TEMP_STR)) - { - temp.setPath(localAppData.canonicalPath()); - } - } - CoTaskMemFree(localAppDataPath); + localAppData.mkdir(TEMP_STR); } - } - else if(SHGetFolderPathPtr) - { - WCHAR *localAppDataPath = new WCHAR[4096]; - if(SHGetFolderPathPtr(NULL, CSIDL_LOCAL_APPDATA, NULL, NULL, localAppDataPath) == S_OK) + if(localAppData.cd(TEMP_STR)) { - QDir localAppData = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(localAppDataPath)))); - if(localAppData.exists()) - { - if(!localAppData.entryList(QDir::AllDirs).contains(TEMP_STR)) - { - localAppData.mkdir(TEMP_STR); - } - if(localAppData.cd(TEMP_STR)) - { - temp.setPath(localAppData.canonicalPath()); - } - } + temp.setPath(localAppData.absolutePath()); } - delete [] localAppDataPath; } if(!temp.exists()) @@ -849,6 +817,89 @@ const QString lamexp_version2string(const QString &pattern, unsigned int version return result; } +/* + * Locate known folder on local system + */ +QString lamexp_known_folder(lamexp_known_folder_t folder_id) +{ + typedef HRESULT (WINAPI *SHGetKnownFolderPathFun)(__in const GUID &rfid, __in DWORD dwFlags, __in HANDLE hToken, __out PWSTR *ppszPath); + typedef HRESULT (WINAPI *SHGetFolderPathFun)(__in HWND hwndOwner, __in int nFolder, __in HANDLE hToken, __in DWORD dwFlags, __out LPWSTR pszPath); + + static const int CSIDL_LOCAL_APPDATA = 0x001c; + static const int CSIDL_PROGRAM_FILES = 0x0026; + static const GUID GUID_LOCAL_APPDATA = {0xF1B32785,0x6FBA,0x4FCF,{0x9D,0x55,0x7B,0x8E,0x7F,0x15,0x70,0x91}}; + static const GUID GUID_LOCAL_APPDATA_LOW = {0xA520A1A4,0x1780,0x4FF6,{0xBD,0x18,0x16,0x73,0x43,0xC5,0xAF,0x16}}; + static const GUID GUID_PROGRAM_FILES = {0x905e63b6,0xc1bf,0x494e,{0xb2,0x9c,0x65,0xb7,0x32,0xd3,0xd2,0x1a}}; + + static SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = NULL; + static SHGetFolderPathFun SHGetFolderPathPtr = NULL; + + if((!SHGetKnownFolderPathPtr) && (!SHGetFolderPathPtr)) + { + QLibrary Kernel32Lib("shell32.dll"); + SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib.resolve("SHGetKnownFolderPath"); + SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib.resolve("SHGetFolderPathW"); + } + + int folderCSIDL = -1; + GUID folderGUID = {0x0000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; + + switch(folder_id) + { + case lamexp_folder_localappdata: + folderCSIDL = CSIDL_LOCAL_APPDATA; + folderGUID = GUID_LOCAL_APPDATA; + break; + case lamexp_folder_programfiles: + folderCSIDL = CSIDL_PROGRAM_FILES; + folderGUID = GUID_PROGRAM_FILES; + break; + default: + return QString(); + break; + } + + QString folder; + + if(SHGetKnownFolderPathPtr) + { + WCHAR *path = NULL; + if(SHGetKnownFolderPathPtr(folderGUID, 0x00008000, NULL, &path) == S_OK) + { + MessageBoxW(0, path, L"SHGetKnownFolderPathPtr", MB_TOPMOST); + QDir folderTemp = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(path)))); + if(!folderTemp.exists()) + { + folderTemp.mkpath("."); + } + if(folderTemp.exists()) + { + folder = folderTemp.canonicalPath(); + } + CoTaskMemFree(path); + } + } + else if(SHGetFolderPathPtr) + { + WCHAR *path = new WCHAR[4096]; + if(SHGetFolderPathPtr(NULL, folderCSIDL, NULL, NULL, path) == S_OK) + { + MessageBoxW(0, path, L"SHGetFolderPathPtr", MB_TOPMOST); + QDir folderTemp = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(path)))); + if(!folderTemp.exists()) + { + folderTemp.mkpath("."); + } + if(folderTemp.exists()) + { + folder = folderTemp.canonicalPath(); + } + } + delete [] path; + } + + return folder; +} /* * Get number private bytes [debug only] diff --git a/src/Global.h b/src/Global.h index 6e23847c..aa706ffe 100644 --- a/src/Global.h +++ b/src/Global.h @@ -56,6 +56,14 @@ typedef struct } lamexp_cpu_t; +//Known folders +typedef enum +{ + lamexp_folder_localappdata = 0, + lamexp_folder_programfiles = 1 +} +lamexp_known_folder_t; + //LameXP version info unsigned int lamexp_version_major(void); unsigned int lamexp_version_minor(void); @@ -85,6 +93,7 @@ lamexp_cpu_t lamexp_detect_cpu_features(void); //Auxiliary functions bool lamexp_clean_folder(const QString folderPath); const QString lamexp_version2string(const QString &pattern, unsigned int version); +QString lamexp_known_folder(lamexp_known_folder_t folder_id); //Debug-only functions SIZE_T lamexp_dbg_private_bytes(void); diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index 0e237c72..20ba2b6a 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -269,25 +269,10 @@ void InitializationThread::initNeroAac(void) void InitializationThread::initWmaDec(void) { - typedef HRESULT (WINAPI *SHGetFolderPathFun)(__in HWND hwndOwner, __in int nFolder, __in HANDLE hToken, __in DWORD dwFlags, __out LPWSTR pszPath); static const char* wmaDecoderComponentPath = "NCH Software/Components/wmawav/wmawav.exe"; - static const int CSIDL_PROGRAM_FILES = 0x0026; - - QLibrary Kernel32Lib("shell32.dll"); - SHGetFolderPathFun SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib.resolve("SHGetFolderPathW"); - QDir programFilesDir = QDir::temp(); - - if(SHGetFolderPathPtr) - { - WCHAR *programFilesPath = new WCHAR[4096]; - if(SHGetFolderPathPtr(NULL, CSIDL_PROGRAM_FILES, NULL, NULL, programFilesPath) == S_OK) - { - programFilesDir.setPath(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast(programFilesPath)))); - } - } LockedFile *wmaFileBin = NULL; - QFileInfo wmaFileInfo = QFileInfo(QString("%1/%2").arg(programFilesDir.absolutePath(), wmaDecoderComponentPath)); + QFileInfo wmaFileInfo = QFileInfo(QString("%1/%2").arg(lamexp_known_folder(lamexp_folder_programfiles), wmaDecoderComponentPath)); if(!wmaFileInfo.exists()) {