Shell Custom Folders
Robert Shearman
rob at codeweavers.com
Tue Sep 28 06:34:59 CDT 2004
Hi,
This patch has been tested on the History view in Internet Explorer.
Rob
Changelog:
- Add support for custom shell folders, such as the History folder.
- Always try to initialize folder using IPersistFolder3 interface and
then fall back on IPersistFolder if not supported.
-------------- next part --------------
Index: wine/dlls/shell32/shlfolder.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shlfolder.c,v
retrieving revision 1.89
diff -u -p -r1.89 shlfolder.c
--- wine/dlls/shell32/shlfolder.c 13 Sep 2004 23:25:09 -0000 1.89
+++ wine/dlls/shell32/shlfolder.c 28 Sep 2004 11:26:54 -0000
@@ -64,6 +64,52 @@ WINE_DEFAULT_DEBUG_CHANNEL (shell);
#define _CALL_TRACE
#endif
+static const WCHAR wszDotShellClassInfo[] = {'.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0};
+
+/***************************************************************************
+ * SHELL32_GetCustomFolderAttribute (internal function)
+ *
+ * Gets a value from the folder's desktop.ini file, if one exists.
+ *
+ * PARAMETERS
+ * pidl [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.
+ * cchValue [I] Size in characters including NULL of buffer pointed to
+ * by pwszValue.
+ *
+ * RETURNS
+ * TRUE if returned non-NULL value.
+ * FALSE otherwise.
+ */
+BOOL SHELL32_GetCustomFolderAttribute(
+ LPCITEMIDLIST pidl, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
+ LPWSTR pwszValue, DWORD cchValue)
+{
+#if 0 /* Hack around not having system attribute on non-Windows file systems */
+ DWORD dwAttrib = _ILGetFileAttributes(pidl, NULL, 0);
+#else
+ DWORD dwAttrib = FILE_ATTRIBUTE_SYSTEM;
+#endif
+ if (dwAttrib & FILE_ATTRIBUTE_SYSTEM)
+ {
+ DWORD ret;
+ WCHAR wszDesktopIniPath[MAX_PATH];
+ static const WCHAR wszDesktopIni[] =
+ {'d','e','s','k','t','o','p','.','i','n','i',0};
+ if (!SHGetPathFromIDListW(pidl, wszDesktopIniPath))
+ return FALSE;
+ PathAppendW(wszDesktopIniPath, wszDesktopIni);
+ ret = GetPrivateProfileStringW(pwszHeading, pwszAttribute,
+ NULL, pwszValue, cchValue, wszDesktopIniPath);
+ if (!ret) return FALSE;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
/***************************************************************************
* GetNextElement (internal function)
*
@@ -143,68 +189,31 @@ HRESULT SHELL32_ParseNextElement (IShell
/***********************************************************************
* SHELL32_CoCreateInitSF
*
- * Creates a shell folder and initializes it with a pidl via IPersistFolder.
- * This function is meant for virtual folders not backed by a file system
- * folder.
- */
-HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot,
- LPCITEMIDLIST pidlChild, REFCLSID clsid, REFIID iid, LPVOID * ppvOut)
-{
- HRESULT hr;
-
- TRACE ("%p %p\n", pidlRoot, pidlChild);
-
- if (SUCCEEDED ((hr = SHCoCreateInstance (NULL, clsid, NULL, iid, ppvOut)))) {
- IPersistFolder *pPF;
-
- if (SUCCEEDED ((hr = IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder, (LPVOID *) & pPF)))) {
- LPITEMIDLIST pidlAbsolute;
-
- pidlAbsolute = ILCombine (pidlRoot, pidlChild);
- IPersistFolder_Initialize (pPF, pidlAbsolute);
- IPersistFolder_Release (pPF);
- SHFree (pidlAbsolute);
-
- if (!pidlAbsolute)
- hr = E_OUTOFMEMORY;
- }
- }
-
- TRACE ("-- (%p) ret=0x%08lx\n", *ppvOut, hr);
- return hr;
-}
-
-/***********************************************************************
- * SHELL32_CoCreateInitSFEx
- *
* Creates a shell folder and initializes it with a pidl and a root folder
- * via IPersistFolder3.
- * This function is meant for virtual folders backed by a file system
- * folder.
+ * via IPersistFolder3 or IPersistFolder.
*
* NOTES
* pathRoot can be NULL for Folders beeing a drive.
* In this case the absolute path is build from pidlChild (eg. C:)
*/
-HRESULT SHELL32_CoCreateInitSFEx (LPCITEMIDLIST pidlRoot,
- LPCSTR pathRoot, LPCITEMIDLIST pidlChild, REFCLSID clsid, REFIID riid, LPVOID * ppvOut)
+HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCSTR pathRoot,
+ LPCITEMIDLIST pidlChild, REFCLSID clsid, REFIID riid, LPVOID * ppvOut)
{
HRESULT hr;
- IPersistFolder3 *ppf;
TRACE ("%p %s %p\n", pidlRoot, pathRoot, pidlChild);
- if (SUCCEEDED ((hr = SHCoCreateInstance (NULL, &CLSID_ShellFSFolder, NULL, riid, ppvOut)))) {
+ if (SUCCEEDED ((hr = SHCoCreateInstance (NULL, clsid, NULL, riid, ppvOut)))) {
+ LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
+ IPersistFolder *pPF;
+ IPersistFolder3 *ppf;
+
if (SUCCEEDED (IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder3, (LPVOID *) & ppf))) {
PERSIST_FOLDER_TARGET_INFO ppfti;
- LPITEMIDLIST pidlAbsolute;
char szDestPath[MAX_PATH];
ZeroMemory (&ppfti, sizeof (ppfti));
- /* combine pidls */
- pidlAbsolute = ILCombine (pidlRoot, pidlChild);
-
/* build path */
if (pathRoot) {
lstrcpyA (szDestPath, pathRoot);
@@ -229,8 +238,12 @@ HRESULT SHELL32_CoCreateInitSFEx (LPCITE
IPersistFolder3_InitializeEx (ppf, NULL, pidlAbsolute, &ppfti);
IPersistFolder3_Release (ppf);
- ILFree (pidlAbsolute);
}
+ else if (SUCCEEDED ((hr = IUnknown_QueryInterface ((IUnknown *) * ppvOut, &IID_IPersistFolder, (LPVOID *) & pPF)))) {
+ IPersistFolder_Initialize (pPF, pidlAbsolute);
+ IPersistFolder_Release (pPF);
+ }
+ ILFree (pidlAbsolute);
}
TRACE ("-- (%p) ret=0x%08lx\n", *ppvOut, hr);
return hr;
@@ -259,11 +272,20 @@ HRESULT SHELL32_BindToChild (LPCITEMIDLI
if ((clsid = _ILGetGUIDPointer (pidlChild))) {
/* virtual folder */
- hr = SHELL32_CoCreateInitSF (pidlRoot, pidlChild, clsid, &IID_IShellFolder, (LPVOID *) & pSF);
+ hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, clsid, &IID_IShellFolder, (LPVOID *) & pSF);
} else {
- /* file system folder */
- hr = SHELL32_CoCreateInitSFEx (pidlRoot, pathRoot, pidlChild, &CLSID_ShellFSFolder, &IID_IShellFolder,
- (LPVOID *) & pSF);
+ /* file system folder */
+ CLSID clsidFolder = CLSID_ShellFSFolder;
+ static const WCHAR wszCLSID[] = {'C','L','S','I','D',0};
+ WCHAR wszCLSIDValue[CHARS_IN_GUID];
+ LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
+ /* see if folder CLSID should be overridden by desktop.ini file */
+ if (SHELL32_GetCustomFolderAttribute (pidlAbsolute,
+ wszDotShellClassInfo, wszCLSID, wszCLSIDValue, CHARS_IN_GUID))
+ CLSIDFromString (wszCLSIDValue, &clsidFolder);
+ ILFree (pidlAbsolute);
+ hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild,
+ &clsidFolder, &IID_IShellFolder, (LPVOID *)&pSF);
}
ILFree (pidlChild);
Index: wine/dlls/shell32/shfldr.h
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shfldr.h,v
retrieving revision 1.6
diff -u -p -r1.6 shfldr.h
--- wine/dlls/shell32/shfldr.h 20 Jan 2004 01:26:39 -0000 1.6
+++ wine/dlls/shell32/shfldr.h 28 Sep 2004 11:26:54 -0000
@@ -21,6 +21,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define CHARS_IN_GUID 39
+
typedef struct {
int colnameid;
int pcsFlags;
@@ -31,14 +33,12 @@ 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);
+
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);
HRESULT SHELL32_GetItemAttributes (IShellFolder * psf, LPCITEMIDLIST pidl, LPDWORD pdwAttributes);
-HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCITEMIDLIST pidlChild, REFCLSID clsid, REFIID iid,
- LPVOID * ppvOut);
-HRESULT SHELL32_CoCreateInitSFEx (LPCITEMIDLIST pidlRoot, LPCSTR pathRoot, LPCITEMIDLIST pidlChild, REFCLSID clsid,
- REFIID iid, LPVOID * ppvOut);
HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTR szOut,
DWORD dwOutLen);
More information about the wine-patches
mailing list