Commit bbdd20d5 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

Correct some PIDL types and eliminate some magic numbers in PIDL

allocation; correct a copy-pasto from a previous patch.
parent 77beaca7
......@@ -239,7 +239,7 @@ static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
int size = size0;
int l;
tmp.type = 0;
tmp.type = PT_CPLAPPLET;
tmp.u.cpanel.dummy = 0;
tmp.u.cpanel.iconIdx = iconIdx;
......@@ -281,7 +281,7 @@ static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
{
LPPIDLDATA pdata = _ILGetDataPointer(pidl);
if (pdata && pdata->type==0)
if (pdata && pdata->type==PT_CPLAPPLET)
return (PIDLCPanelStruct*)&(pdata->u.cpanel);
return NULL;
......
......@@ -200,9 +200,7 @@ void pdump (LPCITEMIDLIST pidl)
char szName[MAX_PATH];
_dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
if( PT_FOLDER == type)
dwAttrib = pData->u.folder.uFileAttribs;
else if( PT_VALUE == type)
if( PT_FOLDER == type || PT_VALUE == type)
dwAttrib = pData->u.file.uFileAttribs;
MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
......@@ -229,7 +227,7 @@ BOOL pcheck (LPCITEMIDLIST pidl)
{ do
{ type = _dbg_ILGetDataPointer(pidltemp)->type;
switch (type)
{ case PT_DESKTOP:
{ case PT_CPLAPPLET:
case PT_GUID:
case PT_SHELLEXT:
case PT_DRIVE:
......
......@@ -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()
{ TRACE("()\n");
return _ILCreateWithTypeAndSize(PT_DESKTOP, 0);
{
LPITEMIDLIST ret;
TRACE("()\n");
ret = SHAlloc(2);
if (ret)
ret->mkid.cb = 0;
return ret;
}
LPITEMIDLIST _ILCreateMyComputer()
......@@ -1481,7 +1510,7 @@ LPITEMIDLIST _ILCreatePrinters()
TRACE("()\n");
if (parent)
{
LPITEMIDLIST printers = _ILCreateGuid(PT_GUID, &CLSID_ControlPanel);
LPITEMIDLIST printers = _ILCreateGuid(PT_GUID, &CLSID_Printers);
if (printers)
{
......@@ -1509,7 +1538,7 @@ LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
if (type == PT_SHELLEXT || type == PT_GUID)
{
pidlOut = _ILCreateWithTypeAndSize(type, 2 + 2 + sizeof(GUID));
pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
if (pidlOut)
{
LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
......@@ -1539,30 +1568,11 @@ LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
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 )
{
char buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
char * pbuff = buff;
ULONG len, len1;
size_t len, len1;
LPITEMIDLIST pidl;
PIDLTYPE type;
......@@ -1581,8 +1591,10 @@ LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER :
PT_VALUE;
/* FIXME: magic #s! */
if ((pidl = _ILCreateWithTypeAndSize(type, 2 + 12 + len + len1)))
/* FileStruct already has one byte for the first name, so use len - 1 in
* size calculation
*/
if ((pidl = _ILAlloc(type, sizeof(FileStruct) + (len - 1) + len1)))
{
LPPIDLDATA pData;
LPSTR pszDest;
......@@ -1591,9 +1603,9 @@ LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
if ((pData = _ILGetDataPointer(pidl)))
{
pData->type = type;
FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
pData->u.folder.dwFileSize = stffile->nFileSizeLow;
pData->u.folder.uFileAttribs = (WORD)stffile->dwFileAttributes;
FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.file.uFileDate,&pData->u.file.uFileTime);
pData->u.file.dwFileSize = stffile->nFileSizeLow;
pData->u.file.uFileAttribs = (WORD)stffile->dwFileAttributes;
}
if ((pszDest = _ILGetTextPointer(pidl)))
{
......@@ -1630,8 +1642,7 @@ LPITEMIDLIST _ILCreateDrive( LPCSTR lpszNew)
sTemp[3]=0x00;
TRACE("(%s)\n",sTemp);
/* FIXME: magic #s! */
if ((pidlOut = _ILCreateWithTypeAndSize(PT_DRIVE, 25)))
if ((pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct))))
{
LPSTR pszDest;
......@@ -1971,8 +1982,6 @@ BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
switch (pdata->type)
{
case PT_FOLDER:
DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
break;
case PT_VALUE:
DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
break;
......@@ -2130,8 +2139,6 @@ DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
switch(pData->type)
{
case PT_FOLDER:
wAttrib = pData->u.folder.uFileAttribs;
break;
case PT_VALUE:
wAttrib = pData->u.file.uFileAttribs;
break;
......
......@@ -2,6 +2,7 @@
* internal pidl functions
*
* Copyright 1998 Juergen Schmied
* Copyright 2004 Juan Lang
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -85,7 +86,7 @@
* GUID 871C5380-42A0-1069-A2EA-08002B30309D
*/
#define PT_DESKTOP 0x00 /* internal */
#define PT_CPLAPPLET 0x00
#define PT_GUID 0x1F
#define PT_DRIVE 0x23
#define PT_DRIVE2 0x25
......@@ -116,21 +117,21 @@ typedef struct tagPIDLCPanelStruct
CHAR szName[1]; /*10*/ /* terminated by 0x00, followed by display name and comment string */
} PIDLCPanelStruct;
typedef struct tagPIDLDATA
{ PIDLTYPE type; /*00*/
union
{ struct
{ BYTE dummy; /*01*/
GUID guid; /*02*/
BYTE dummy1; /*18*/
} 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 */
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*/
......@@ -138,7 +139,15 @@ typedef struct tagPIDLDATA
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;
} FileStruct;
typedef struct tagPIDLDATA
{ PIDLTYPE type; /*00*/
union
{
struct tagGUIDStruct guid;
struct tagDriveStruct drive;
struct tagFileStruct file;
struct
{ WORD dummy; /*01*/
CHAR szNames[1]; /*03*/
......@@ -183,10 +192,13 @@ BOOL _ILIsCPanelStruct (LPCITEMIDLIST pidl);
* simple pidls
*/
/* Basic PIDL constructor. Allocates size + 2 bytes (to include space for the
* NULL PIDL terminator), and sets type to type.
/* Basic PIDL constructor. Allocates size + 5 bytes, where:
* - 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
* or PT_SHELLEXT.
......
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