diff options
author | KLee1248 <tjmcsaxy@gmail.com> | 2019-04-18 02:43:33 +0000 |
---|---|---|
committer | Kenneth <dev@kennethlee.rocks> | 2019-04-18 06:45:04 -0700 |
commit | 3d908f57d8c8b6a72ee38cefca7628dc5a3ddc6b (patch) | |
tree | edd6408b68cfac609e530382edf5c5e0ca7784f1 /platform/windows | |
parent | 6697fd9a05859914fc320b4b4321fd9fb6170f71 (diff) |
Use SHGetKnownFolderPath instead of SHGetFolderPathW.
When getting system directories for Windows, we currently use
SHGetFolderPathW. This is a deprecated function and doesn't support
"Downloads" folders.
As a replacement, this commit uses the newer SHGetKnownFolderPath
function, which is supported since Windows Vista. Godot 3.0 only
supports Windows 7+, so we don't need to use SHGetFolderPathW for
backwards compatibility.
Fixes #26876
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/os_windows.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 1a5050a15a..5e12106639 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2870,39 +2870,41 @@ String OS_Windows::get_godot_dir_name() const { String OS_Windows::get_system_dir(SystemDir p_dir) const { - int id; + KNOWNFOLDERID id; switch (p_dir) { case SYSTEM_DIR_DESKTOP: { - id = CSIDL_DESKTOPDIRECTORY; + id = FOLDERID_Desktop; } break; case SYSTEM_DIR_DCIM: { - id = CSIDL_MYPICTURES; + id = FOLDERID_Pictures; } break; case SYSTEM_DIR_DOCUMENTS: { - id = CSIDL_PERSONAL; + id = FOLDERID_Documents; } break; case SYSTEM_DIR_DOWNLOADS: { - id = 0x000C; + id = FOLDERID_Downloads; } break; case SYSTEM_DIR_MOVIES: { - id = CSIDL_MYVIDEO; + id = FOLDERID_Videos; } break; case SYSTEM_DIR_MUSIC: { - id = CSIDL_MYMUSIC; + id = FOLDERID_Music; } break; case SYSTEM_DIR_PICTURES: { - id = CSIDL_MYPICTURES; + id = FOLDERID_Pictures; } break; case SYSTEM_DIR_RINGTONES: { - id = CSIDL_MYMUSIC; + id = FOLDERID_Music; } break; } - WCHAR szPath[MAX_PATH]; - HRESULT res = SHGetFolderPathW(NULL, id, NULL, 0, szPath); + PWSTR szPath; + HRESULT res = SHGetKnownFolderPath(id, 0, NULL, &szPath); ERR_FAIL_COND_V(res != S_OK, String()); - return String(szPath); + String path = String(szPath); + CoTaskMemFree(szPath); + return path; } String OS_Windows::get_user_data_dir() const { |