Correct some PIDL types and eliminate some magic numbers in PIDL

allocation; correct a copy-pasto from a previous patch.
This commit is contained in:
Juan Lang 2004-04-14 19:33:07 +00:00 committed by Alexandre Julliard
parent 77beaca78f
commit bbdd20d536
4 changed files with 82 additions and 65 deletions

View File

@ -239,7 +239,7 @@ static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
int size = size0; int size = size0;
int l; int l;
tmp.type = 0; tmp.type = PT_CPLAPPLET;
tmp.u.cpanel.dummy = 0; tmp.u.cpanel.dummy = 0;
tmp.u.cpanel.iconIdx = iconIdx; tmp.u.cpanel.iconIdx = iconIdx;
@ -281,7 +281,7 @@ static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
{ {
LPPIDLDATA pdata = _ILGetDataPointer(pidl); LPPIDLDATA pdata = _ILGetDataPointer(pidl);
if (pdata && pdata->type==0) if (pdata && pdata->type==PT_CPLAPPLET)
return (PIDLCPanelStruct*)&(pdata->u.cpanel); return (PIDLCPanelStruct*)&(pdata->u.cpanel);
return NULL; return NULL;

View File

@ -200,9 +200,7 @@ void pdump (LPCITEMIDLIST pidl)
char szName[MAX_PATH]; char szName[MAX_PATH];
_dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH); _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
if( PT_FOLDER == type) if( PT_FOLDER == type || PT_VALUE == type)
dwAttrib = pData->u.folder.uFileAttribs;
else if( PT_VALUE == type)
dwAttrib = pData->u.file.uFileAttribs; dwAttrib = pData->u.file.uFileAttribs;
MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n", MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
@ -229,7 +227,7 @@ BOOL pcheck (LPCITEMIDLIST pidl)
{ do { do
{ type = _dbg_ILGetDataPointer(pidltemp)->type; { type = _dbg_ILGetDataPointer(pidltemp)->type;
switch (type) switch (type)
{ case PT_DESKTOP: { case PT_CPLAPPLET:
case PT_GUID: case PT_GUID:
case PT_SHELLEXT: case PT_SHELLEXT:
case PT_DRIVE: case PT_DRIVE:

View File

@ -1440,9 +1440,38 @@ HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCI
* *
************************************************************************* *************************************************************************
*/ */
LPITEMIDLIST _ILAlloc(PIDLTYPE type, size_t size)
{
LPITEMIDLIST pidlOut = NULL;
if((pidlOut = SHAlloc(size + 5)))
{
LPPIDLDATA pData;
LPITEMIDLIST pidlNext;
ZeroMemory(pidlOut, size + 5);
pidlOut->mkid.cb = size + 3;
if ((pData = _ILGetDataPointer(pidlOut)))
pData->type = type;
if ((pidlNext = ILGetNext(pidlOut)))
pidlNext->mkid.cb = 0x00;
TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
}
return pidlOut;
}
LPITEMIDLIST _ILCreateDesktop() LPITEMIDLIST _ILCreateDesktop()
{ TRACE("()\n"); {
return _ILCreateWithTypeAndSize(PT_DESKTOP, 0); LPITEMIDLIST ret;
TRACE("()\n");
ret = SHAlloc(2);
if (ret)
ret->mkid.cb = 0;
return ret;
} }
LPITEMIDLIST _ILCreateMyComputer() LPITEMIDLIST _ILCreateMyComputer()
@ -1481,7 +1510,7 @@ LPITEMIDLIST _ILCreatePrinters()
TRACE("()\n"); TRACE("()\n");
if (parent) if (parent)
{ {
LPITEMIDLIST printers = _ILCreateGuid(PT_GUID, &CLSID_ControlPanel); LPITEMIDLIST printers = _ILCreateGuid(PT_GUID, &CLSID_Printers);
if (printers) if (printers)
{ {
@ -1509,7 +1538,7 @@ LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
if (type == PT_SHELLEXT || type == PT_GUID) if (type == PT_SHELLEXT || type == PT_GUID)
{ {
pidlOut = _ILCreateWithTypeAndSize(type, 2 + 2 + sizeof(GUID)); pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
if (pidlOut) if (pidlOut)
{ {
LPPIDLDATA pData = _ILGetDataPointer(pidlOut); LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
@ -1539,30 +1568,11 @@ LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
return _ILCreateGuid(PT_GUID, &iid); return _ILCreateGuid(PT_GUID, &iid);
} }
LPITEMIDLIST _ILCreateWithTypeAndSize(PIDLTYPE type, UINT size)
{
LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
LPPIDLDATA pData;
if(!(pidlOut = SHAlloc(size + 2))) return NULL;
ZeroMemory(pidlOut, size + 2);
pidlOut->mkid.cb = size;
if ((pData = _ILGetDataPointer(pidlOut)))
pData->type = type;
if ((pidlTemp = ILGetNext(pidlOut)))
pidlTemp->mkid.cb = 0x00;
TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
return pidlOut;
}
LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile ) LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
{ {
char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */ char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
char * pbuff = buff; char * pbuff = buff;
ULONG len, len1; size_t len, len1;
LPITEMIDLIST pidl; LPITEMIDLIST pidl;
PIDLTYPE type; PIDLTYPE type;
@ -1581,8 +1591,10 @@ LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER :
PT_VALUE; PT_VALUE;
/* FIXME: magic #s! */ /* FileStruct already has one byte for the first name, so use len - 1 in
if ((pidl = _ILCreateWithTypeAndSize(type, 2 + 12 + len + len1))) * size calculation
*/
if ((pidl = _ILAlloc(type, sizeof(FileStruct) + (len - 1) + len1)))
{ {
LPPIDLDATA pData; LPPIDLDATA pData;
LPSTR pszDest; LPSTR pszDest;
@ -1591,9 +1603,9 @@ LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
if ((pData = _ILGetDataPointer(pidl))) if ((pData = _ILGetDataPointer(pidl)))
{ {
pData->type = type; pData->type = type;
FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime); FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.file.uFileDate,&pData->u.file.uFileTime);
pData->u.folder.dwFileSize = stffile->nFileSizeLow; pData->u.file.dwFileSize = stffile->nFileSizeLow;
pData->u.folder.uFileAttribs = (WORD)stffile->dwFileAttributes; pData->u.file.uFileAttribs = (WORD)stffile->dwFileAttributes;
} }
if ((pszDest = _ILGetTextPointer(pidl))) if ((pszDest = _ILGetTextPointer(pidl)))
{ {
@ -1630,8 +1642,7 @@ LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
sTemp[3]=0x00; sTemp[3]=0x00;
TRACE("(%s)\n",sTemp); TRACE("(%s)\n",sTemp);
/* FIXME: magic #s! */ if ((pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct))))
if ((pidlOut = _ILCreateWithTypeAndSize(PT_DRIVE, 25)))
{ {
LPSTR pszDest; LPSTR pszDest;
@ -1971,8 +1982,6 @@ BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
switch (pdata->type) switch (pdata->type)
{ {
case PT_FOLDER: case PT_FOLDER:
DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
break;
case PT_VALUE: case PT_VALUE:
DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt); DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
break; break;
@ -2130,8 +2139,6 @@ DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
switch(pData->type) switch(pData->type)
{ {
case PT_FOLDER: case PT_FOLDER:
wAttrib = pData->u.folder.uFileAttribs;
break;
case PT_VALUE: case PT_VALUE:
wAttrib = pData->u.file.uFileAttribs; wAttrib = pData->u.file.uFileAttribs;
break; break;

View File

@ -2,6 +2,7 @@
* internal pidl functions * internal pidl functions
* *
* Copyright 1998 Juergen Schmied * Copyright 1998 Juergen Schmied
* Copyright 2004 Juan Lang
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -85,7 +86,7 @@
* GUID 871C5380-42A0-1069-A2EA-08002B30309D * GUID 871C5380-42A0-1069-A2EA-08002B30309D
*/ */
#define PT_DESKTOP 0x00 /* internal */ #define PT_CPLAPPLET 0x00
#define PT_GUID 0x1F #define PT_GUID 0x1F
#define PT_DRIVE 0x23 #define PT_DRIVE 0x23
#define PT_DRIVE2 0x25 #define PT_DRIVE2 0x25
@ -116,29 +117,37 @@ typedef struct tagPIDLCPanelStruct
CHAR szName[1]; /*10*/ /* terminated by 0x00, followed by display name and comment string */ CHAR szName[1]; /*10*/ /* terminated by 0x00, followed by display name and comment string */
} PIDLCPanelStruct; } PIDLCPanelStruct;
typedef struct tagGUIDStruct
{
BYTE dummy; /* offset 01 is unknown */
GUID guid; /* offset 02 */
} GUIDStruct;
typedef struct tagDriveStruct
{
CHAR szDriveName[20]; /*01*/
WORD unknown; /*21*/
} DriveStruct;
typedef struct tagFileStruct
{
BYTE dummy; /*01 is 0x00 for files or dirs */
DWORD dwFileSize; /*02*/
WORD uFileDate; /*06*/
WORD uFileTime; /*08*/
WORD uFileAttribs; /*10*/
CHAR szNames[1]; /*12*/
/* Here are coming two strings. The first is the long name.
The second the dos name when needed or just 0x00 */
} FileStruct;
typedef struct tagPIDLDATA typedef struct tagPIDLDATA
{ PIDLTYPE type; /*00*/ { PIDLTYPE type; /*00*/
union union
{ struct {
{ BYTE dummy; /*01*/ struct tagGUIDStruct guid;
GUID guid; /*02*/ struct tagDriveStruct drive;
BYTE dummy1; /*18*/ struct tagFileStruct file;
} guid;
struct
{ CHAR szDriveName[20]; /*01*/
DWORD dwUnknown; /*21*/
/* the drive seems to be 25 bytes every time */
} drive;
struct
{ BYTE dummy; /*01 is 0x00 for files or dirs */
DWORD dwFileSize; /*02*/
WORD uFileDate; /*06*/
WORD uFileTime; /*08*/
WORD uFileAttribs; /*10*/
CHAR szNames[1]; /*12*/
/* Here are coming two strings. The first is the long name.
The second the dos name when needed or just 0x00 */
} file, folder, generic;
struct struct
{ WORD dummy; /*01*/ { WORD dummy; /*01*/
CHAR szNames[1]; /*03*/ CHAR szNames[1]; /*03*/
@ -183,10 +192,13 @@ BOOL _ILIsCPanelStruct (LPCITEMIDLIST pidl);
* simple pidls * simple pidls
*/ */
/* Basic PIDL constructor. Allocates size + 2 bytes (to include space for the /* Basic PIDL constructor. Allocates size + 5 bytes, where:
* NULL PIDL terminator), and sets type to type. * - two bytes are SHITEMID.cb
* - one byte is PIDLDATA.type
* - two bytes are the NULL PIDL terminator
* Sets type of the returned PIDL to type.
*/ */
LPITEMIDLIST _ILCreateWithTypeAndSize(PIDLTYPE type, UINT size); LPITEMIDLIST _ILAlloc(PIDLTYPE type, size_t size);
/* Creates a PIDL with guid format and type type, which must be either PT_GUID /* Creates a PIDL with guid format and type type, which must be either PT_GUID
* or PT_SHELLEXT. * or PT_SHELLEXT.