Fix T85689: Replace SHGetFileInfoW for Drive Name

Win32: Replace SHGetFileInfoW as means to get friendly display names
for volumes because it causes long pauses for disconnected remote
drives.

See D14305 for more details.

Differential Revision: https://developer.blender.org/D14305

Reviewed by Brecht Van Lommel
This commit is contained in:
Harley Acheson 2022-03-11 09:25:45 -08:00
parent 5c86f0369c
commit ae3c8bc9f0
Notes: blender-bot 2023-02-14 02:22:07 +01:00
Referenced by issue #85689, Start up hangs when a disconnected mapped network drive is present on Windows
1 changed files with 22 additions and 6 deletions

View File

@ -29,6 +29,7 @@
* because 'near' is disabled through BLI_windstuff. */
# include "BLI_winstuff.h"
# include <shlobj.h>
# include <shlwapi.h>
#endif
#include "UI_interface_icons.h"
@ -642,14 +643,29 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
tmps[3] = '\0';
name = NULL;
/* Flee from horrible win querying hover floppy drives! */
/* Skip over floppy disks A & B. */
if (i > 1) {
/* Try to get a friendly drive description. */
SHFILEINFOW shFile = {0};
/* Friendly volume descriptions without using SHGetFileInfoW (T85689). */
BLI_strncpy_wchar_from_utf8(wline, tmps, 4);
if (SHGetFileInfoW(wline, 0, &shFile, sizeof(SHFILEINFOW), SHGFI_DISPLAYNAME)) {
BLI_strncpy_wchar_as_utf8(line, shFile.szDisplayName, FILE_MAXDIR);
name = line;
IShellFolder *desktop;
if (SHGetDesktopFolder(&desktop) == S_OK) {
PIDLIST_RELATIVE volume;
if (desktop->lpVtbl->ParseDisplayName(
desktop, NULL, NULL, wline, NULL, &volume, NULL) == S_OK) {
STRRET volume_name;
volume_name.uType = STRRET_WSTR;
if (desktop->lpVtbl->GetDisplayNameOf(
desktop, volume, SHGDN_FORADDRESSBAR, &volume_name) == S_OK) {
wchar_t *volume_name_wchar;
if (StrRetToStrW(&volume_name, volume, &volume_name_wchar) == S_OK) {
BLI_strncpy_wchar_as_utf8(line, volume_name_wchar, FILE_MAXDIR);
name = line;
CoTaskMemFree(volume_name_wchar);
}
}
CoTaskMemFree(volume);
}
desktop->lpVtbl->Release(desktop);
}
}
if (name == NULL) {