From b4e29c9de95dedcfaa325b4bd89418ce506890bc Mon Sep 17 00:00:00 2001 From: David Quintana Date: Wed, 26 Aug 2015 17:31:42 +0000 Subject: [PATCH] [SHELL32] * Fix loading icon info from dekstop.ini. Also took the chance to remove some unnecessary convolution. The old code tried to load the info, but didn't actually make use of the returned string at all. CORE-9002 #resolve #comment Icon loading should work now. Adding the default desktop.ini files in the right folders will be a followup issue. svn path=/trunk/; revision=68828 --- reactos/dll/win32/shell32/folders.cpp | 70 +++++++++++-------------- reactos/dll/win32/shell32/shfldr.h | 3 -- reactos/dll/win32/shell32/shlfolder.cpp | 58 ++------------------ 3 files changed, 37 insertions(+), 94 deletions(-) diff --git a/reactos/dll/win32/shell32/folders.cpp b/reactos/dll/win32/shell32/folders.cpp index 913d657a5cb..ec9818b9ee5 100644 --- a/reactos/dll/win32/shell32/folders.cpp +++ b/reactos/dll/win32/shell32/folders.cpp @@ -27,65 +27,59 @@ IShellIconOverlayIdentifier ** Handlers = NULL; static HRESULT getIconLocationForFolder(LPCITEMIDLIST pidl, UINT uFlags, LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags) { - int icon_idx; - bool cont=TRUE; - WCHAR wszPath[MAX_PATH]; - WCHAR wszCLSIDValue[CHARS_IN_GUID]; 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; + WCHAR wszFolderPath[MAX_PATH]; - /* - Optimisation. GetCustomFolderAttribute has a critical lock on it, and isn't fast. - Test the water (i.e., see if the attribute exists) before questioning it three times - when most folders don't use it at all. - */ - WCHAR wszBigToe[3]; - if (!(uFlags & GIL_DEFAULTICON) && SHELL32_GetCustomFolderAttributes(pidl, shellClassInfo, - wszBigToe, 3)) + if (!SHGetPathFromIDListW(pidl, wszFolderPath)) + return FALSE; + + PathAppendW(wszFolderPath, wszDesktopIni); + + if (!(uFlags & GIL_DEFAULTICON) && PathFileExistsW(wszFolderPath)) { - if (SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, iconFile, - wszPath, MAX_PATH)) + WCHAR wszPath[MAX_PATH]; + WCHAR wszCLSIDValue[CHARS_IN_GUID]; + + if (GetPrivateProfileStringW(shellClassInfo, iconFile, NULL, wszPath, MAX_PATH, wszFolderPath)) { - WCHAR wszIconIndex[10]; - SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, iconIndex, - wszIconIndex, 10); - *piIndex = _wtoi(wszIconIndex); - cont=FALSE; + ExpandEnvironmentStringsW(wszPath, szIconFile, cchMax); + + *piIndex = GetPrivateProfileIntW(shellClassInfo, iconIndex, 0, wszFolderPath); + return S_OK; } - else if (SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, clsid, - wszCLSIDValue, CHARS_IN_GUID) && + else if (GetPrivateProfileStringW(shellClassInfo, clsid, NULL, wszCLSIDValue, CHARS_IN_GUID, wszFolderPath) && HCR_GetIconW(wszCLSIDValue, szIconFile, NULL, cchMax, &icon_idx)) { *piIndex = icon_idx; - cont=FALSE; + return S_OK; } - else if (SHELL32_GetCustomFolderAttribute(pidl, shellClassInfo, clsid2, - wszCLSIDValue, CHARS_IN_GUID) && + else if (GetPrivateProfileStringW(shellClassInfo, clsid2, NULL, wszCLSIDValue, CHARS_IN_GUID, wszFolderPath) && HCR_GetIconW(wszCLSIDValue, szIconFile, NULL, cchMax, &icon_idx)) { *piIndex = icon_idx; - cont=FALSE; + return S_OK; } } - if (cont) + + static const WCHAR folder[] = { 'F', 'o', 'l', 'd', 'e', 'r', 0 }; + + if (!HCR_GetIconW(folder, szIconFile, NULL, cchMax, &icon_idx)) { - 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; + 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; } diff --git a/reactos/dll/win32/shell32/shfldr.h b/reactos/dll/win32/shell32/shfldr.h index 8e22242a20b..b470a0e8600 100644 --- a/reactos/dll/win32/shell32/shfldr.h +++ b/reactos/dll/win32/shell32/shfldr.h @@ -36,9 +36,6 @@ typedef struct { #define GET_SHGDN_FOR(dwFlags) ((DWORD)dwFlags & (DWORD)0x0000FF00) #define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF) -BOOL SHELL32_GetCustomFolderAttribute (LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPCWSTR pwszAttribute, LPWSTR pwszValue, DWORD cchValue); -BOOL SHELL32_GetCustomFolderAttributes (LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPWSTR pwszValue, DWORD cchValue); - LPCWSTR GetNextElementW (LPCWSTR pszNext, LPWSTR pszOut, DWORD dwOut); HRESULT SHELL32_ParseNextElement (IShellFolder2 * psf, HWND hwndOwner, LPBC pbc, LPITEMIDLIST * pidlInOut, LPOLESTR szNext, DWORD * pEaten, DWORD * pdwAttributes); diff --git a/reactos/dll/win32/shell32/shlfolder.cpp b/reactos/dll/win32/shell32/shlfolder.cpp index 26c2d3e2f41..ef2dbfd2590 100644 --- a/reactos/dll/win32/shell32/shlfolder.cpp +++ b/reactos/dll/win32/shell32/shlfolder.cpp @@ -25,16 +25,13 @@ WINE_DEFAULT_DEBUG_CHANNEL(shell); -static const WCHAR wszDotShellClassInfo[] = { - '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0}; - /*************************************************************************** - * SHELL32_GetCustomFolderAttribute (internal function) + * SHELL32_GetCustomFolderAttributeFromPath (internal function) * * Gets a value from the folder's desktop.ini file, if one exists. * * PARAMETERS - * pidl [I] Folder containing the desktop.ini file. + * pwszFolderPath[I] Folder containing the desktop.ini file. * pwszHeading [I] Heading in .ini file. * pwszAttribute [I] Attribute in .ini file. * pwszValue [O] Buffer to store value into. @@ -59,54 +56,6 @@ static BOOL __inline SHELL32_GetCustomFolderAttributeFromPath( pwszValue, cchValue, pwszFolderPath); } -BOOL SHELL32_GetCustomFolderAttribute( - LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPCWSTR pwszAttribute, - LPWSTR pwszValue, DWORD cchValue) -{ - DWORD dwAttrib = FILE_ATTRIBUTE_SYSTEM; - WCHAR wszFolderPath[MAX_PATH]; - - /* Hack around not having system attribute on non-Windows file systems */ - if (0) - dwAttrib = _ILGetFileAttributes(pidl, NULL, 0); - - if (dwAttrib & FILE_ATTRIBUTE_SYSTEM) - { - if (!SHGetPathFromIDListW(pidl, wszFolderPath)) - return FALSE; - - return SHELL32_GetCustomFolderAttributeFromPath(wszFolderPath, pwszHeading, - pwszAttribute, pwszValue, cchValue); - } - return FALSE; -} - -BOOL SHELL32_GetCustomFolderAttributes( - LPCITEMIDLIST pidl, LPCWSTR pwszHeading, - LPWSTR pwszValue, DWORD cchValue) -{ - DWORD dwAttrib = FILE_ATTRIBUTE_SYSTEM; - WCHAR wszFolderPath[MAX_PATH]; - - /* Hack around not having system attribute on non-Windows file systems */ - dwAttrib = _ILGetFileAttributes(pidl, NULL, 0); - - if (dwAttrib & FILE_ATTRIBUTE_SYSTEM) - { - if (!SHGetPathFromIDListW(pidl, wszFolderPath)) - return FALSE; - - static const WCHAR wszDesktopIni[] = - {'d','e','s','k','t','o','p','.','i','n','i',0}; - - PathAddBackslashW(wszFolderPath); - PathAppendW(wszFolderPath, wszDesktopIni); - return GetPrivateProfileSectionW(pwszHeading, pwszValue, cchValue, wszFolderPath); - } - return FALSE; -} - - /*************************************************************************** * GetNextElement (internal function) * @@ -276,6 +225,9 @@ static HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, HRESULT SHELL32_BindToChild (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut) { + static const WCHAR wszDotShellClassInfo[] = { + '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 }; + GUID const *clsid; CComPtr pSF; HRESULT hr;