Commit 19b1a95e authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

- move CreateMyCompEnumList and CreateDesktopEnumList to their

respective files - rewrite CreateFolderEnumList to only FindFirstFile/FindNextFile once
parent b0047713
...@@ -102,19 +102,18 @@ BOOL AddToEnumList( ...@@ -102,19 +102,18 @@ BOOL AddToEnumList(
/************************************************************************** /**************************************************************************
* CreateFolderEnumList() * CreateFolderEnumList()
*/ */
static BOOL CreateFolderEnumList( BOOL CreateFolderEnumList(
IEnumIDList * iface, IEnumIDList *list,
LPCSTR lpszPath, LPCSTR lpszPath,
DWORD dwFlags) DWORD dwFlags)
{ {
ICOM_THIS(IEnumIDListImpl,iface);
LPITEMIDLIST pidl=NULL; LPITEMIDLIST pidl=NULL;
WIN32_FIND_DATAA stffile; WIN32_FIND_DATAA stffile;
HANDLE hFile; HANDLE hFile;
CHAR szPath[MAX_PATH]; CHAR szPath[MAX_PATH];
BOOL succeeded = TRUE;
TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags); TRACE("(%p)->(path=%s flags=0x%08lx) \n",list,debugstr_a(lpszPath),dwFlags);
if(!lpszPath || !lpszPath[0]) return FALSE; if(!lpszPath || !lpszPath[0]) return FALSE;
...@@ -122,172 +121,44 @@ static BOOL CreateFolderEnumList( ...@@ -122,172 +121,44 @@ static BOOL CreateFolderEnumList(
PathAddBackslashA(szPath); PathAddBackslashA(szPath);
strcat(szPath,"*.*"); strcat(szPath,"*.*");
/*enumerate the folders*/
if(dwFlags & SHCONTF_FOLDERS)
{
TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
hFile = FindFirstFileA(szPath,&stffile); hFile = FindFirstFileA(szPath,&stffile);
if ( hFile != INVALID_HANDLE_VALUE ) if ( hFile != INVALID_HANDLE_VALUE )
{ {
do BOOL findFinished = FALSE;
{
if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
{
pidl = _ILCreateFromFindDataA (&stffile);
if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
{
continue;
}
return FALSE;
}
} while( FindNextFileA(hFile,&stffile));
FindClose (hFile);
}
}
/*enumerate the non-folder items (values) */
if(dwFlags & SHCONTF_NONFOLDERS)
{
TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath));
hFile = FindFirstFileA(szPath,&stffile);
if ( hFile != INVALID_HANDLE_VALUE )
{
do do
{ {
if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue; if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
{
pidl = _ILCreateFromFindDataA(&stffile);
if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
{
continue;
}
return FALSE;
}
} while( FindNextFileA(hFile,&stffile));
FindClose (hFile);
}
}
return TRUE;
}
/**************************************************************************
* CreateDesktopEnumList()
*/
static BOOL CreateDesktopEnumList(
IEnumIDList * iface,
DWORD dwFlags)
{
ICOM_THIS(IEnumIDListImpl,iface);
LPITEMIDLIST pidl=NULL;
HKEY hkey;
char szPath[MAX_PATH];
TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
/*enumerate the root folders */
if(dwFlags & SHCONTF_FOLDERS)
{
/*create the pidl for This item */
pidl = _ILCreateMyComputer();
if(pidl)
{ {
if(!AddToEnumList((IEnumIDList*)This, pidl)) if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
return FALSE; dwFlags & SHCONTF_FOLDERS &&
} strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
{ {
char iid[50]; pidl = _ILCreateFromFindDataA(&stffile);
int i=0; succeeded = succeeded && AddToEnumList(list, pidl);
while (1)
{
DWORD size = sizeof (iid);
if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
break;
pidl = _ILCreateGuidFromStrA(iid);
if(pidl)
AddToEnumList((IEnumIDList*)This, pidl);
i++;
}
RegCloseKey(hkey);
}
} }
else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
/*enumerate the elements in %windir%\desktop */ && dwFlags & SHCONTF_NONFOLDERS)
SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
return TRUE;
}
/**************************************************************************
* CreateMyCompEnumList()
*/
static BOOL CreateMyCompEnumList(
IEnumIDList * iface,
DWORD dwFlags)
{
ICOM_THIS(IEnumIDListImpl,iface);
LPITEMIDLIST pidl=NULL;
DWORD dwDrivemap;
CHAR szDriveName[4];
HKEY hkey;
TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
/*enumerate the folders*/
if(dwFlags & SHCONTF_FOLDERS)
{
dwDrivemap = GetLogicalDrives();
strcpy (szDriveName,"A:\\");
while (szDriveName[0]<='Z')
{
if(dwDrivemap & 0x00000001L)
{ {
pidl = _ILCreateDrive(szDriveName); pidl = _ILCreateFromFindDataA(&stffile);
if(pidl) succeeded = succeeded && AddToEnumList(list, pidl);
{
if(!AddToEnumList((IEnumIDList*)This, pidl))
return FALSE;
}
} }
szDriveName[0]++;
dwDrivemap = dwDrivemap >> 1;
} }
if (succeeded)
TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
{ {
char iid[50]; if (!FindNextFileA(hFile, &stffile))
int i=0;
while (1)
{ {
DWORD size = sizeof (iid); if (GetLastError() == ERROR_NO_MORE_FILES)
findFinished = TRUE;
if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL)) else
break; succeeded = FALSE;
pidl = _ILCreateGuidFromStrA(iid);
if(pidl)
AddToEnumList((IEnumIDList*)This, pidl);
i++;
} }
RegCloseKey(hkey);
} }
} while (succeeded && !findFinished);
FindClose(hFile);
} }
return TRUE; return succeeded;
} }
/************************************************************************** /**************************************************************************
...@@ -332,46 +203,6 @@ IEnumIDList * IEnumIDList_Constructor(void) ...@@ -332,46 +203,6 @@ IEnumIDList * IEnumIDList_Constructor(void)
return (IEnumIDList*)lpeidl; return (IEnumIDList*)lpeidl;
} }
IEnumIDList * IEnumIDList_BadConstructor(
LPCSTR lpszPath,
DWORD dwFlags,
DWORD dwKind)
{
IEnumIDListImpl* lpeidl;
BOOL ret = FALSE;
TRACE("()->(%s flags=0x%08lx kind=0x%08lx)\n",debugstr_a(lpszPath),dwFlags, dwKind);
lpeidl = (IEnumIDListImpl *)IEnumIDList_Constructor();
if (lpeidl)
{
switch (dwKind)
{
case EIDL_DESK:
ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
break;
case EIDL_MYCOMP:
ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
break;
case EIDL_FILE:
ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
break;
}
if(!ret) {
HeapFree(GetProcessHeap(),0,lpeidl);
lpeidl = NULL;
}
}
TRACE("-- (%p)->()\n",lpeidl);
return (IEnumIDList*)lpeidl;
}
/************************************************************************** /**************************************************************************
* EnumIDList_QueryInterface * EnumIDList_QueryInterface
*/ */
......
...@@ -18,16 +18,13 @@ ...@@ -18,16 +18,13 @@
#include "shlobj.h" #include "shlobj.h"
/* Creates an IEnumIDList; add LPITEMIDLISTs to it with AddToEnumList. */
LPENUMIDLIST IEnumIDList_Constructor(void); LPENUMIDLIST IEnumIDList_Constructor(void);
BOOL AddToEnumList(IEnumIDList * iface, LPITEMIDLIST pidl); BOOL AddToEnumList(IEnumIDList *list, LPITEMIDLIST pidl);
/* old interface that's going away soon: */ /* Enumerates the folders and/or files (depending on dwFlags) in lpszPath and
/* kind of enumidlist */ * adds them to the already-created list.
#define EIDL_DESK 0 */
#define EIDL_MYCOMP 1 BOOL CreateFolderEnumList(IEnumIDList *list, LPCSTR lpszPath, DWORD dwFlags);
#define EIDL_FILE 2
IEnumIDList * IEnumIDList_BadConstructor(LPCSTR lpszPath, DWORD dwFlags,
DWORD dwKind);
#endif /* ndef __ENUMIDLIST_H__ */ #endif /* ndef __ENUMIDLIST_H__ */
...@@ -261,6 +261,59 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface, ...@@ -261,6 +261,59 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
} }
/************************************************************************** /**************************************************************************
* CreateDesktopEnumList()
*/
static BOOL CreateDesktopEnumList(IEnumIDList *list, DWORD dwFlags)
{
BOOL ret = TRUE;
char szPath[MAX_PATH];
TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
/*enumerate the root folders */
if(dwFlags & SHCONTF_FOLDERS)
{
HKEY hkey;
/*create the pidl for This item */
ret = AddToEnumList(list, _ILCreateMyComputer());
if (ret && !RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace",
0, KEY_READ, &hkey))
{
char iid[50];
int i=0;
BOOL moreKeys = TRUE;
while (ret && moreKeys)
{
DWORD size = sizeof (iid);
LONG apiRet = RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL,
NULL);
if (ERROR_SUCCESS == apiRet)
{
ret = AddToEnumList(list, _ILCreateGuidFromStrA(iid));
i++;
}
else if (ERROR_NO_MORE_ITEMS == apiRet)
moreKeys = FALSE;
else
ret = FALSE;
}
RegCloseKey(hkey);
}
}
/*enumerate the elements in %windir%\desktop */
SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
ret = ret && CreateFolderEnumList(list, szPath, dwFlags);
return ret;
}
/**************************************************************************
* ISF_Desktop_fnEnumObjects * ISF_Desktop_fnEnumObjects
*/ */
static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface, static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
...@@ -270,7 +323,9 @@ static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface, ...@@ -270,7 +323,9 @@ static HRESULT WINAPI ISF_Desktop_fnEnumObjects (IShellFolder2 * iface,
TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList); TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
*ppEnumIDList = IEnumIDList_BadConstructor (NULL, dwFlags, EIDL_DESK); *ppEnumIDList = IEnumIDList_Constructor();
if (*ppEnumIDList)
CreateDesktopEnumList(*ppEnumIDList, dwFlags);
TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList); TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
......
...@@ -392,7 +392,9 @@ IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags ...@@ -392,7 +392,9 @@ IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags
TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList); TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
*ppEnumIDList = IEnumIDList_BadConstructor (This->sPathTarget, dwFlags, EIDL_FILE); *ppEnumIDList = IEnumIDList_Constructor();
if (*ppEnumIDList)
CreateFolderEnumList(*ppEnumIDList, This->sPathTarget, dwFlags);
TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList); TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
......
...@@ -238,6 +238,62 @@ ISF_MyComputer_fnParseDisplayName (IShellFolder2 * iface, ...@@ -238,6 +238,62 @@ ISF_MyComputer_fnParseDisplayName (IShellFolder2 * iface,
} }
/************************************************************************** /**************************************************************************
* CreateMyCompEnumList()
*/
static BOOL CreateMyCompEnumList(IEnumIDList *list, DWORD dwFlags)
{
BOOL ret = TRUE;
TRACE("(%p)->(flags=0x%08lx) \n",list,dwFlags);
/*enumerate the folders*/
if(dwFlags & SHCONTF_FOLDERS)
{
CHAR szDriveName[] = "A:\\";
DWORD dwDrivemap = GetLogicalDrives();
HKEY hkey;
while (ret && szDriveName[0]<='Z')
{
if(dwDrivemap & 0x00000001L)
ret = AddToEnumList(list, _ILCreateDrive(szDriveName));
szDriveName[0]++;
dwDrivemap = dwDrivemap >> 1;
}
TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",list);
if (ret && !RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace",
0, KEY_READ, &hkey))
{
char iid[50];
int i=0;
while (ret)
{
DWORD size = sizeof (iid);
LONG apiRet = RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL,
NULL);
if (ERROR_SUCCESS == apiRet)
{
/* FIXME: shell extensions, shouldn't the type be
* PT_SHELLEXT? */
ret = AddToEnumList(list, _ILCreateGuidFromStrA(iid));
i++;
}
else if (ERROR_NO_MORE_ITEMS == apiRet)
break;
else
ret = FALSE;
}
RegCloseKey(hkey);
}
}
return ret;
}
/**************************************************************************
* ISF_MyComputer_fnEnumObjects * ISF_MyComputer_fnEnumObjects
*/ */
static HRESULT WINAPI static HRESULT WINAPI
...@@ -247,7 +303,9 @@ ISF_MyComputer_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFla ...@@ -247,7 +303,9 @@ ISF_MyComputer_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner, DWORD dwFla
TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList); TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
*ppEnumIDList = IEnumIDList_BadConstructor (NULL, dwFlags, EIDL_MYCOMP); *ppEnumIDList = IEnumIDList_Constructor();
if (*ppEnumIDList)
CreateMyCompEnumList(*ppEnumIDList, dwFlags);
TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList); TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment