- move CreateMyCompEnumList and CreateDesktopEnumList to their

respective files
- rewrite CreateFolderEnumList to only FindFirstFile/FindNextFile once
This commit is contained in:
Juan Lang 2004-04-08 19:50:17 +00:00 committed by Alexandre Julliard
parent b004771314
commit 19b1a95ec1
5 changed files with 173 additions and 230 deletions

View File

@ -102,192 +102,63 @@ 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;
WIN32_FIND_DATAA stffile;
HANDLE hFile;
CHAR szPath[MAX_PATH];
BOOL succeeded = TRUE;
LPITEMIDLIST pidl=NULL; TRACE("(%p)->(path=%s flags=0x%08lx) \n",list,debugstr_a(lpszPath),dwFlags);
WIN32_FIND_DATAA stffile;
HANDLE hFile;
CHAR szPath[MAX_PATH];
TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags); if(!lpszPath || !lpszPath[0]) return FALSE;
if(!lpszPath || !lpszPath[0]) return FALSE; strcpy(szPath, lpszPath);
PathAddBackslashA(szPath);
strcat(szPath,"*.*");
strcpy(szPath, lpszPath); hFile = FindFirstFileA(szPath,&stffile);
PathAddBackslashA(szPath); if ( hFile != INVALID_HANDLE_VALUE )
strcat(szPath,"*.*"); {
BOOL findFinished = FALSE;
/*enumerate the folders*/ do
if(dwFlags & SHCONTF_FOLDERS) {
{ if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath)); || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
hFile = FindFirstFileA(szPath,&stffile); {
if ( hFile != INVALID_HANDLE_VALUE ) if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
{ dwFlags & SHCONTF_FOLDERS &&
do strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
{ {
if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue; pidl = _ILCreateFromFindDataA(&stffile);
if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, "..")) succeeded = succeeded && AddToEnumList(list, pidl);
{ }
pidl = _ILCreateFromFindDataA (&stffile); else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
if(pidl && AddToEnumList((IEnumIDList*)This, pidl)) && dwFlags & SHCONTF_NONFOLDERS)
{ {
continue; pidl = _ILCreateFromFindDataA(&stffile);
} succeeded = succeeded && AddToEnumList(list, pidl);
return FALSE; }
} }
} while( FindNextFileA(hFile,&stffile)); if (succeeded)
FindClose (hFile); {
} if (!FindNextFileA(hFile, &stffile))
} {
if (GetLastError() == ERROR_NO_MORE_FILES)
/*enumerate the non-folder items (values) */ findFinished = TRUE;
if(dwFlags & SHCONTF_NONFOLDERS) else
{ succeeded = FALSE;
TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath)); }
hFile = FindFirstFileA(szPath,&stffile); }
if ( hFile != INVALID_HANDLE_VALUE ) } while (succeeded && !findFinished);
{ FindClose(hFile);
do }
{ return succeeded;
if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
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))
return FALSE;
}
if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
{
char iid[50];
int i=0;
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);
}
}
/*enumerate the elements in %windir%\desktop */
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);
if(pidl)
{
if(!AddToEnumList((IEnumIDList*)This, pidl))
return FALSE;
}
}
szDriveName[0]++;
dwDrivemap = dwDrivemap >> 1;
}
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];
int i=0;
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);
}
}
return TRUE;
} }
/************************************************************************** /**************************************************************************
@ -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
*/ */

View File

@ -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__ */

View File

@ -260,6 +260,59 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
return hr; return hr;
} }
/**************************************************************************
* 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
*/ */
@ -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);

View File

@ -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);

View File

@ -237,6 +237,62 @@ ISF_MyComputer_fnParseDisplayName (IShellFolder2 * iface,
return hr; return hr;
} }
/**************************************************************************
* 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
*/ */
@ -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);