diff options
author | michi_cc <michi_cc@openttd.org> | 2013-04-06 18:36:49 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2013-04-06 18:36:49 +0000 |
commit | 2d67f0797569b4ebe56e11544706fdcd7f4a3bcb (patch) | |
tree | 2e349ac265602b8a2051c3962ccb5155da74afa4 /src | |
parent | 3349cb3347ca566ecd42ae0a29a91fb7dbfb9220 (diff) | |
download | openttd-2d67f0797569b4ebe56e11544706fdcd7f4a3bcb.tar.xz |
(svn r25155) -Codechange: [Win32] Improve SHGetFolderPath emulation.
Diffstat (limited to 'src')
-rw-r--r-- | src/os/windows/win32.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 62f7894d5..3bb22288f 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -17,6 +17,7 @@ #include "../../fios.h" #include <windows.h> #include <fcntl.h> +#include <regstr.h> #include <shlobj.h> /* SHGetFolderPath */ #include <Shellapi.h> #include "win32.h" @@ -732,8 +733,11 @@ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, #else # define W(x) x "A" #endif - if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { - DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from SHFolder.dll"); + /* The function lives in shell32.dll for all current Windows versions, but it first started to appear in SHFolder.dll. */ + if (!LoadLibraryList((Function*)&SHGetFolderPath, "shell32.dll\0" W("SHGetFolderPath") "\0\0")) { + if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { + DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from either shell32.dll or SHFolder.dll"); + } } #undef W first_time = false; @@ -758,6 +762,17 @@ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, return (HRESULT)0; + case CSIDL_PERSONAL: + case CSIDL_COMMON_DOCUMENTS: { + HKEY key; + if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break; + DWORD len = MAX_PATH; + ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), NULL, NULL, (LPBYTE)pszPath, &len); + RegCloseKey(key); + if (ret == ERROR_SUCCESS) return (HRESULT)0; + break; + } + /* XXX - other types to go here when needed... */ } } |