Implement a method that will detect the TEMP folder independent from the %TMP% environment variable on Windows XP (and probably also 2000) too.
This commit is contained in:
parent
6a12462e50
commit
e163a80467
@ -608,32 +608,35 @@ QString lamexp_rand_str(void)
|
||||
*/
|
||||
const QString &lamexp_temp_folder(void)
|
||||
{
|
||||
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);
|
||||
|
||||
const char *TEMP_STR = "Temp";
|
||||
const int CSIDL_LOCAL_APPDATA = 0x001c;
|
||||
const GUID LocalAppDataID={0xF1B32785,0x6FBA,0x4FCF,{0x9D,0x55,0x7B,0x8E,0x7F,0x15,0x70,0x91}};
|
||||
const GUID LocalAppDataLowID={0xA520A1A4,0x1780,0x4FF6,{0xBD,0x18,0x16,0x73,0x43,0xC5,0xAF,0x16}};
|
||||
|
||||
typedef HANDLE (WINAPI *SHGetKnownFolderPathFun)(__in const GUID &rfid, __in DWORD dwFlags, __in HANDLE hToken, __out PWSTR *ppszPath);
|
||||
|
||||
if(g_lamexp_temp_folder.isEmpty())
|
||||
{
|
||||
QDir temp = QDir::temp();
|
||||
|
||||
QLibrary Kernel32Lib("shell32.dll");
|
||||
SHGetKnownFolderPathFun SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) Kernel32Lib.resolve("SHGetKnownFolderPath");
|
||||
SHGetFolderPathFun SHGetFolderPathPtr = (SHGetFolderPathFun) Kernel32Lib.resolve("SHGetFolderPathW");
|
||||
|
||||
if(SHGetKnownFolderPathPtr)
|
||||
{
|
||||
WCHAR *localAppDataPath = NULL;
|
||||
if(SHGetKnownFolderPathPtr(LocalAppDataID, 0x00008000, NULL, &localAppDataPath) == S_OK)
|
||||
{
|
||||
MessageBoxW(NULL, localAppDataPath, L"LocalAppData", MB_TOPMOST);
|
||||
QDir localAppData = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast<const unsigned short*>(localAppDataPath))));
|
||||
if(localAppData.exists())
|
||||
{
|
||||
if(!localAppData.entryList(QDir::AllDirs).contains("Temp"))
|
||||
if(!localAppData.entryList(QDir::AllDirs).contains(TEMP_STR))
|
||||
{
|
||||
localAppData.mkdir("Temp");
|
||||
localAppData.mkdir(TEMP_STR);
|
||||
}
|
||||
if(localAppData.cd("Temp"))
|
||||
if(localAppData.cd(TEMP_STR))
|
||||
{
|
||||
temp.setPath(localAppData.canonicalPath());
|
||||
}
|
||||
@ -641,6 +644,26 @@ const QString &lamexp_temp_folder(void)
|
||||
CoTaskMemFree(localAppDataPath);
|
||||
}
|
||||
}
|
||||
else if(SHGetFolderPathPtr)
|
||||
{
|
||||
WCHAR *localAppDataPath = new WCHAR[4096];
|
||||
if(SHGetFolderPathPtr(NULL, CSIDL_LOCAL_APPDATA, NULL, NULL, localAppDataPath) == S_OK)
|
||||
{
|
||||
QDir localAppData = QDir(QDir::fromNativeSeparators(QString::fromUtf16(reinterpret_cast<const unsigned short*>(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] localAppDataPath;
|
||||
}
|
||||
|
||||
if(!temp.exists())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user