-static HRESULT getIconLocationForFolder(IShellFolder * psf, LPCITEMIDLIST pidl, UINT uFlags,
- LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
-{
- static const WCHAR shellClassInfo[] = { '.', 'S', 'h', 'e', 'l', 'l', 'C', 'l', 'a', 's', 's', 'I', 'n', 'f', 'o', 0 };
- static const WCHAR iconFile[] = { 'I', 'c', 'o', 'n', 'F', 'i', 'l', 'e', 0 };
- static const WCHAR clsid[] = { 'C', 'L', 'S', 'I', 'D', 0 };
- static const WCHAR clsid2[] = { 'C', 'L', 'S', 'I', 'D', '2', 0 };
- static const WCHAR iconIndex[] = { 'I', 'c', 'o', 'n', 'I', 'n', 'd', 'e', 'x', 0 };
- static const WCHAR wszDesktopIni[] = { 'd','e','s','k','t','o','p','.','i','n','i',0 };
- int icon_idx;
-
- if (!(uFlags & GIL_DEFAULTICON) && (_ILGetFileAttributes(ILFindLastID(pidl), NULL, 0) & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)) != 0 )
- {
- WCHAR wszFolderPath[MAX_PATH];
-
- if (!ILGetDisplayNameExW(psf, pidl, wszFolderPath, 0))
- return FALSE;
-
- PathAppendW(wszFolderPath, wszDesktopIni);
-
- if (PathFileExistsW(wszFolderPath))
- {
- WCHAR wszPath[MAX_PATH];
- WCHAR wszCLSIDValue[CHARS_IN_GUID];
-
- if (GetPrivateProfileStringW(shellClassInfo, iconFile, NULL, wszPath, MAX_PATH, wszFolderPath))
- {
- ExpandEnvironmentStringsW(wszPath, szIconFile, cchMax);
-
- *piIndex = GetPrivateProfileIntW(shellClassInfo, iconIndex, 0, wszFolderPath);
- return S_OK;
- }
- else if (GetPrivateProfileStringW(shellClassInfo, clsid, NULL, wszCLSIDValue, CHARS_IN_GUID, wszFolderPath) &&
- HCR_GetIconW(wszCLSIDValue, szIconFile, NULL, cchMax, &icon_idx))
- {
- *piIndex = icon_idx;
- return S_OK;
- }
- else if (GetPrivateProfileStringW(shellClassInfo, clsid2, NULL, wszCLSIDValue, CHARS_IN_GUID, wszFolderPath) &&
- HCR_GetIconW(wszCLSIDValue, szIconFile, NULL, cchMax, &icon_idx))
- {
- *piIndex = icon_idx;
- return S_OK;
- }
- }
- }
-
- static const WCHAR folder[] = { 'F', 'o', 'l', 'd', 'e', 'r', 0 };
-
- if (!HCR_GetIconW(folder, szIconFile, NULL, cchMax, &icon_idx))
- {
- lstrcpynW(szIconFile, swShell32Name, cchMax);
- icon_idx = -IDI_SHELL_FOLDER;
- }
-
- if (uFlags & GIL_OPENICON)
- *piIndex = icon_idx < 0 ? icon_idx - 1 : icon_idx + 1;
- else
- *piIndex = icon_idx;
-
- return S_OK;
-}
-