- move CreateMyCompEnumList and CreateDesktopEnumList to their
respective files - rewrite CreateFolderEnumList to only FindFirstFile/FindNextFile once
This commit is contained in:
parent
b004771314
commit
19b1a95ec1
|
@ -102,192 +102,63 @@ BOOL AddToEnumList(
|
|||
/**************************************************************************
|
||||
* CreateFolderEnumList()
|
||||
*/
|
||||
static BOOL CreateFolderEnumList(
|
||||
IEnumIDList * iface,
|
||||
BOOL CreateFolderEnumList(
|
||||
IEnumIDList *list,
|
||||
LPCSTR lpszPath,
|
||||
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;
|
||||
WIN32_FIND_DATAA stffile;
|
||||
HANDLE hFile;
|
||||
CHAR szPath[MAX_PATH];
|
||||
TRACE("(%p)->(path=%s flags=0x%08lx) \n",list,debugstr_a(lpszPath),dwFlags);
|
||||
|
||||
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);
|
||||
PathAddBackslashA(szPath);
|
||||
strcat(szPath,"*.*");
|
||||
hFile = FindFirstFileA(szPath,&stffile);
|
||||
if ( hFile != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
BOOL findFinished = FALSE;
|
||||
|
||||
/*enumerate the folders*/
|
||||
if(dwFlags & SHCONTF_FOLDERS)
|
||||
{
|
||||
TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
|
||||
hFile = FindFirstFileA(szPath,&stffile);
|
||||
if ( hFile != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
do
|
||||
{
|
||||
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
|
||||
{
|
||||
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;
|
||||
do
|
||||
{
|
||||
if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
|
||||
|| (dwFlags & SHCONTF_INCLUDEHIDDEN) )
|
||||
{
|
||||
if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||
dwFlags & SHCONTF_FOLDERS &&
|
||||
strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
|
||||
{
|
||||
pidl = _ILCreateFromFindDataA(&stffile);
|
||||
succeeded = succeeded && AddToEnumList(list, pidl);
|
||||
}
|
||||
else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
&& dwFlags & SHCONTF_NONFOLDERS)
|
||||
{
|
||||
pidl = _ILCreateFromFindDataA(&stffile);
|
||||
succeeded = succeeded && AddToEnumList(list, pidl);
|
||||
}
|
||||
}
|
||||
if (succeeded)
|
||||
{
|
||||
if (!FindNextFileA(hFile, &stffile))
|
||||
{
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
findFinished = TRUE;
|
||||
else
|
||||
succeeded = FALSE;
|
||||
}
|
||||
}
|
||||
} while (succeeded && !findFinished);
|
||||
FindClose(hFile);
|
||||
}
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -332,46 +203,6 @@ IEnumIDList * IEnumIDList_Constructor(void)
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -18,16 +18,13 @@
|
|||
|
||||
#include "shlobj.h"
|
||||
|
||||
/* Creates an IEnumIDList; add LPITEMIDLISTs to it with AddToEnumList. */
|
||||
LPENUMIDLIST IEnumIDList_Constructor(void);
|
||||
BOOL AddToEnumList(IEnumIDList * iface, LPITEMIDLIST pidl);
|
||||
BOOL AddToEnumList(IEnumIDList *list, LPITEMIDLIST pidl);
|
||||
|
||||
/* old interface that's going away soon: */
|
||||
/* kind of enumidlist */
|
||||
#define EIDL_DESK 0
|
||||
#define EIDL_MYCOMP 1
|
||||
#define EIDL_FILE 2
|
||||
|
||||
IEnumIDList * IEnumIDList_BadConstructor(LPCSTR lpszPath, DWORD dwFlags,
|
||||
DWORD dwKind);
|
||||
/* Enumerates the folders and/or files (depending on dwFlags) in lpszPath and
|
||||
* adds them to the already-created list.
|
||||
*/
|
||||
BOOL CreateFolderEnumList(IEnumIDList *list, LPCSTR lpszPath, DWORD dwFlags);
|
||||
|
||||
#endif /* ndef __ENUMIDLIST_H__ */
|
||||
|
|
|
@ -260,6 +260,59 @@ static HRESULT WINAPI ISF_Desktop_fnParseDisplayName (IShellFolder2 * iface,
|
|||
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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
*ppEnumIDList = IEnumIDList_BadConstructor (NULL, dwFlags, EIDL_DESK);
|
||||
*ppEnumIDList = IEnumIDList_Constructor();
|
||||
if (*ppEnumIDList)
|
||||
CreateDesktopEnumList(*ppEnumIDList, dwFlags);
|
||||
|
||||
TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
*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);
|
||||
|
||||
|
|
|
@ -237,6 +237,62 @@ ISF_MyComputer_fnParseDisplayName (IShellFolder2 * iface,
|
|||
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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
*ppEnumIDList = IEnumIDList_BadConstructor (NULL, dwFlags, EIDL_MYCOMP);
|
||||
*ppEnumIDList = IEnumIDList_Constructor();
|
||||
if (*ppEnumIDList)
|
||||
CreateMyCompEnumList(*ppEnumIDList, dwFlags);
|
||||
|
||||
TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
|
||||
|
||||
|
|
Loading…
Reference in New Issue