| 1 | /* $Id: iconcache.cpp,v 1.8 2000-05-18 14:16:02 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 SHELL32 for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | * shell icon cache (SIC)
|
|---|
| 10 | *
|
|---|
| 11 | * Corel WINE 20000324 level
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | /*****************************************************************************
|
|---|
| 16 | * Includes *
|
|---|
| 17 | *****************************************************************************/
|
|---|
| 18 |
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <odin.h>
|
|---|
| 21 | #include <odinwrap.h>
|
|---|
| 22 | #include <os2sel.h>
|
|---|
| 23 |
|
|---|
| 24 | #define ICOM_CINTERFACE 1
|
|---|
| 25 | #define CINTERFACE 1
|
|---|
| 26 |
|
|---|
| 27 | #include "winbase.h"
|
|---|
| 28 | #include "winuser.h"
|
|---|
| 29 | #include "wingdi.h"
|
|---|
| 30 | //#include "neexe.h"
|
|---|
| 31 | #include "cursoricon.h"
|
|---|
| 32 | #include "module.h"
|
|---|
| 33 | #include "heap.h"
|
|---|
| 34 | #include "debugtools.h"
|
|---|
| 35 | #include "winversion.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "shellapi.h"
|
|---|
| 38 | #include "pidl.h"
|
|---|
| 39 | #include "shell32_main.h"
|
|---|
| 40 |
|
|---|
| 41 | #include <heapstring.h>
|
|---|
| 42 | #include <misc.h>
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | ODINDEBUGCHANNEL(SHELL32-ICONCACHE)
|
|---|
| 46 |
|
|---|
| 47 | #include "pshpack1.h"
|
|---|
| 48 | #include "poppack.h"
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | /*****************************************************************************
|
|---|
| 52 | * Structures *
|
|---|
| 53 | *****************************************************************************/
|
|---|
| 54 |
|
|---|
| 55 | typedef struct
|
|---|
| 56 | {
|
|---|
| 57 | BYTE bWidth; /* Width, in pixels, of the image */
|
|---|
| 58 | BYTE bHeight; /* Height, in pixels, of the image */
|
|---|
| 59 | BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
|
|---|
| 60 | BYTE bReserved; /* Reserved ( must be 0) */
|
|---|
| 61 | WORD wPlanes; /* Color Planes */
|
|---|
| 62 | WORD wBitCount; /* Bits per pixel */
|
|---|
| 63 | DWORD dwBytesInRes; /* How many bytes in this resource? */
|
|---|
| 64 | DWORD dwImageOffset; /* Where in the file is this image? */
|
|---|
| 65 | } icoICONDIRENTRY, *LPicoICONDIRENTRY;
|
|---|
| 66 |
|
|---|
| 67 | typedef struct
|
|---|
| 68 | {
|
|---|
| 69 | WORD idReserved; /* Reserved (must be 0) */
|
|---|
| 70 | WORD idType; /* Resource Type (RES_ICON or RES_CURSOR) */
|
|---|
| 71 | WORD idCount; /* How many images */
|
|---|
| 72 | icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
|
|---|
| 73 | } icoICONDIR, *LPicoICONDIR;
|
|---|
| 74 |
|
|---|
| 75 | #if 0
|
|---|
| 76 | static void dumpIcoDirEnty ( LPICONDIRENTRY entry )
|
|---|
| 77 | {
|
|---|
| 78 | dprintf(("SHELL32:Iconcache width = 0x%08x height = 0x%08x\n", entry->bWidth, entry->bHeight));
|
|---|
| 79 | dprintf(("SHELL32:Iconcache colors = 0x%08x planes = 0x%08x\n", entry->bColorCount, entry->wPlanes));
|
|---|
| 80 | dprintf(("SHELL32:Iconcache bitcount = 0x%08x bytesinres = 0x%08lx offset = 0x%08lx\n",
|
|---|
| 81 | entry->wBitCount, entry->dwBytesInRes, entry->dwImageOffset));
|
|---|
| 82 | }
|
|---|
| 83 | static void dumpIcoDir ( LPICONDIR entry )
|
|---|
| 84 | {
|
|---|
| 85 | dprintf(("SHELL32:Iconcache type = 0x%08x count = 0x%08x\n", entry->idType, entry->idCount));
|
|---|
| 86 | }
|
|---|
| 87 | #endif
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | HDPA sic_hdpa = 0;
|
|---|
| 91 | static CRITICAL_SECTION SHELL32_SicCS;
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | /*************************************************************************
|
|---|
| 96 | * SHELL_GetResourceTable
|
|---|
| 97 | */
|
|---|
| 98 | static DWORD SHELL_GetResourceTable(HFILE hFile, LPBYTE *retptr)
|
|---|
| 99 | { IMAGE_DOS_HEADER mz_header;
|
|---|
| 100 | char magic[4];
|
|---|
| 101 | int size;
|
|---|
| 102 |
|
|---|
| 103 | dprintf(("SHELL32:Iconcache 0x%08x SHELL_GetResourceTable %p\n", hFile, retptr));
|
|---|
| 104 |
|
|---|
| 105 | *retptr = NULL;
|
|---|
| 106 | _llseek( hFile, 0, SEEK_SET );
|
|---|
| 107 | if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
|
|---|
| 108 | { if (mz_header.e_cblp == 1) /* .ICO file ? */
|
|---|
| 109 | { *retptr = (LPBYTE)-1; /* ICONHEADER.idType, must be 1 */
|
|---|
| 110 | return 1;
|
|---|
| 111 | }
|
|---|
| 112 | else
|
|---|
| 113 | return 0; /* failed */
|
|---|
| 114 | }
|
|---|
| 115 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET );
|
|---|
| 116 |
|
|---|
| 117 | if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic))
|
|---|
| 118 | return 0;
|
|---|
| 119 |
|
|---|
| 120 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET);
|
|---|
| 121 |
|
|---|
| 122 | if (*(DWORD*)magic == IMAGE_NT_SIGNATURE)
|
|---|
| 123 | return IMAGE_NT_SIGNATURE;
|
|---|
| 124 |
|
|---|
| 125 | if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
|
|---|
| 126 | { IMAGE_OS2_HEADER ne_header;
|
|---|
| 127 | LPBYTE pTypeInfo = (LPBYTE)-1;
|
|---|
| 128 |
|
|---|
| 129 | if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
|
|---|
| 130 | return 0;
|
|---|
| 131 |
|
|---|
| 132 | if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
|
|---|
| 133 | return 0;
|
|---|
| 134 |
|
|---|
| 135 | size = ne_header.rname_tab_offset - ne_header.resource_tab_offset;
|
|---|
| 136 |
|
|---|
| 137 | if( size > sizeof(NE_TYPEINFO) )
|
|---|
| 138 | { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
|
|---|
| 139 | if( pTypeInfo )
|
|---|
| 140 | { _llseek(hFile, mz_header.e_lfanew+ne_header.resource_tab_offset, SEEK_SET);
|
|---|
| 141 | if( _lread( hFile, (char*)pTypeInfo, size) != size )
|
|---|
| 142 | { HeapFree( GetProcessHeap(), 0, pTypeInfo);
|
|---|
| 143 | pTypeInfo = NULL;
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | *retptr = pTypeInfo;
|
|---|
| 149 | return IMAGE_OS2_SIGNATURE;
|
|---|
| 150 | }
|
|---|
| 151 | return 0; /* failed */
|
|---|
| 152 | }
|
|---|
| 153 | /*************************************************************************
|
|---|
| 154 | * SHELL_LoadResource
|
|---|
| 155 | */
|
|---|
| 156 | static BYTE * SHELL_LoadResource( HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift, ULONG *uSize)
|
|---|
| 157 | { BYTE* ptr;
|
|---|
| 158 |
|
|---|
| 159 | dprintf(("SHELL32:Iconcache SHELL_LoadResource 0x%08x %p 0x%08x\n", hFile, pNInfo, sizeShift));
|
|---|
| 160 |
|
|---|
| 161 | *uSize = (DWORD)pNInfo->length << sizeShift;
|
|---|
| 162 | ptr = (BYTE*)HeapAlloc(GetProcessHeap(),0, *uSize);
|
|---|
| 163 | if(ptr)
|
|---|
| 164 | { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
|
|---|
| 165 | _lread( hFile, (char*)ptr, pNInfo->length << sizeShift);
|
|---|
| 166 | return ptr;
|
|---|
| 167 | }
|
|---|
| 168 | return 0;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | /*************************************************************************
|
|---|
| 172 | * ICO_LoadIcon
|
|---|
| 173 | */
|
|---|
| 174 | static BYTE * ICO_LoadIcon( HFILE hFile, LPicoICONDIRENTRY lpiIDE, ULONG *uSize)
|
|---|
| 175 | { BYTE* ptr;
|
|---|
| 176 |
|
|---|
| 177 | dprintf(("SHELL32:Iconcache ICO_LoadIcon 0x%08x %p\n", hFile, lpiIDE));
|
|---|
| 178 |
|
|---|
| 179 | *uSize = lpiIDE->dwBytesInRes;
|
|---|
| 180 | ptr = (BYTE*)HeapAlloc(GetProcessHeap(),0, *uSize);
|
|---|
| 181 | if(ptr)
|
|---|
| 182 | { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
|
|---|
| 183 | _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
|
|---|
| 184 | return ptr;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | return 0;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | /*************************************************************************
|
|---|
| 191 | * ICO_GetIconDirectory
|
|---|
| 192 | *
|
|---|
| 193 | * Reads .ico file and build phony ICONDIR struct
|
|---|
| 194 | * see http://www.microsoft.com/win32dev/ui/icons.htm
|
|---|
| 195 | */
|
|---|
| 196 | #define HEADER_SIZE (sizeof(CURSORICONDIR) - sizeof (CURSORICONDIRENTRY))
|
|---|
| 197 | #define HEADER_SIZE_FILE (sizeof(icoICONDIR) - sizeof (icoICONDIRENTRY))
|
|---|
| 198 |
|
|---|
| 199 | static BYTE * ICO_GetIconDirectory( HFILE hFile, LPicoICONDIR* lplpiID, ULONG *uSize )
|
|---|
| 200 | { CURSORICONDIR lpcid; /* icon resource in resource-dir format */
|
|---|
| 201 | LPicoICONDIR lpiID; /* icon resource in file format */
|
|---|
| 202 | int i;
|
|---|
| 203 |
|
|---|
| 204 | dprintf(("SHELL32:Iconcache ICO_GetIconDirectory 0x%08x %p\n", hFile, lplpiID));
|
|---|
| 205 |
|
|---|
| 206 | _llseek( hFile, 0, SEEK_SET );
|
|---|
| 207 | if( _lread(hFile,(char*)&lpcid, HEADER_SIZE_FILE) != HEADER_SIZE_FILE )
|
|---|
| 208 | return 0;
|
|---|
| 209 |
|
|---|
| 210 | if( lpcid.idReserved || (lpcid.idType != 1) || (!lpcid.idCount) )
|
|---|
| 211 | return 0;
|
|---|
| 212 |
|
|---|
| 213 | i = lpcid.idCount * sizeof(icoICONDIRENTRY);
|
|---|
| 214 | lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, HEADER_SIZE_FILE + i);
|
|---|
| 215 |
|
|---|
| 216 | if( _lread(hFile,(char*)lpiID->idEntries,i) == i )
|
|---|
| 217 | { CURSORICONDIR * lpID; /* icon resource in resource format */
|
|---|
| 218 | *uSize = lpcid.idCount * sizeof(CURSORICONDIRENTRY) + HEADER_SIZE;
|
|---|
| 219 | lpID = (CURSORICONDIR*)HeapAlloc(GetProcessHeap(),0, *uSize);
|
|---|
| 220 | if(lpID)
|
|---|
| 221 | {
|
|---|
| 222 | /* copy the header */
|
|---|
| 223 | lpID->idReserved = lpiID->idReserved = 0;
|
|---|
| 224 | lpID->idType = lpiID->idType = 1;
|
|---|
| 225 | lpID->idCount = lpiID->idCount = lpcid.idCount;
|
|---|
| 226 |
|
|---|
| 227 | /* copy the entrys */
|
|---|
| 228 | for( i=0; i < lpiID->idCount; i++ )
|
|---|
| 229 | { memcpy((void*)&(lpID->idEntries[i]),(void*)&(lpiID->idEntries[i]), sizeof(CURSORICONDIRENTRY) - 2);
|
|---|
| 230 | lpID->idEntries[i].wResId = i;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | *lplpiID = lpiID;
|
|---|
| 234 | return (BYTE *)lpID;
|
|---|
| 235 | }
|
|---|
| 236 | }
|
|---|
| 237 | /* fail */
|
|---|
| 238 |
|
|---|
| 239 | HeapFree( GetProcessHeap(), 0, lpiID);
|
|---|
| 240 | return 0;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | /*************************************************************************
|
|---|
| 244 | * InternalExtractIcon [SHELL.39]
|
|---|
| 245 | *
|
|---|
| 246 | * This abortion is called directly by Progman
|
|---|
| 247 | * fixme: the icon section is broken (don't have a handle for
|
|---|
| 248 | * ICO_GetIconDirectory....)
|
|---|
| 249 | *
|
|---|
| 250 | */
|
|---|
| 251 | HGLOBAL WINAPI ICO_ExtractIconEx(LPCSTR lpszExeFileName, HICON * RetPtr, UINT nIconIndex, UINT n, UINT cxDesired, UINT cyDesired )
|
|---|
| 252 | { HGLOBAL hRet = 0;
|
|---|
| 253 | LPBYTE pData;
|
|---|
| 254 | OFSTRUCT ofs;
|
|---|
| 255 | DWORD sig;
|
|---|
| 256 | HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
|
|---|
| 257 | UINT iconDirCount = 0,iconCount = 0;
|
|---|
| 258 | LPBYTE peimage;
|
|---|
| 259 | HANDLE fmapping;
|
|---|
| 260 | ULONG uSize;
|
|---|
| 261 |
|
|---|
| 262 | dprintf(("SHELL32:Iconcache ICO_ExtractIconEx (file %s,start %d,extract %d\n", lpszExeFileName, nIconIndex, n));
|
|---|
| 263 |
|
|---|
| 264 | if( hFile == HFILE_ERROR || !n )
|
|---|
| 265 | return hRet;
|
|---|
| 266 |
|
|---|
| 267 | sig = SHELL_GetResourceTable(hFile,&pData);
|
|---|
| 268 |
|
|---|
| 269 | /* ico file */
|
|---|
| 270 | if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
|
|---|
| 271 | { BYTE *pCIDir = 0;
|
|---|
| 272 | NE_TYPEINFO *pTInfo = (NE_TYPEINFO*)(pData + 2);
|
|---|
| 273 | NE_NAMEINFO *pIconStorage = NULL;
|
|---|
| 274 | NE_NAMEINFO *pIconDir = NULL;
|
|---|
| 275 | LPicoICONDIR lpiID = NULL;
|
|---|
| 276 |
|
|---|
| 277 | dprintf(("SHELL32:Iconcache -- OS2/icon Signature (0x%08lx)\n", sig));
|
|---|
| 278 |
|
|---|
| 279 | if( pData == (BYTE*)-1 )
|
|---|
| 280 | { pCIDir = ICO_GetIconDirectory(hFile, &lpiID, &uSize); /* check for .ICO file */
|
|---|
| 281 | if( pCIDir )
|
|---|
| 282 | { iconDirCount = 1; iconCount = lpiID->idCount;
|
|---|
| 283 | dprintf(("SHELL32:Iconcache -- icon found %p 0x%08lx 0x%08x 0x%08x\n", pCIDir, uSize, iconDirCount, iconCount));
|
|---|
| 284 | }
|
|---|
| 285 | }
|
|---|
| 286 | else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
|
|---|
| 287 | { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
|
|---|
| 288 | { iconDirCount = pTInfo->count;
|
|---|
| 289 | pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
|
|---|
| 290 | dprintf(("SHELL32:Iconcache \tfound directory - %i icon families\n", iconDirCount));
|
|---|
| 291 | }
|
|---|
| 292 | if( pTInfo->type_id == NE_RSCTYPE_ICON )
|
|---|
| 293 | { iconCount = pTInfo->count;
|
|---|
| 294 | pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
|
|---|
| 295 | dprintf(("SHELL32:Iconcache \ttotal icons - %i\n", iconCount));
|
|---|
| 296 | }
|
|---|
| 297 | pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | if( (pIconStorage && pIconDir) || lpiID ) /* load resources and create icons */
|
|---|
| 301 | { if( nIconIndex == (UINT16)-1 )
|
|---|
| 302 | { RetPtr[0] = iconDirCount;
|
|---|
| 303 | }
|
|---|
| 304 | else if( nIconIndex < iconDirCount )
|
|---|
| 305 | { UINT i, icon;
|
|---|
| 306 | if( n > iconDirCount - nIconIndex )
|
|---|
| 307 | n = iconDirCount - nIconIndex;
|
|---|
| 308 |
|
|---|
| 309 | for( i = nIconIndex; i < nIconIndex + n; i++ )
|
|---|
| 310 | { /* .ICO files have only one icon directory */
|
|---|
| 311 |
|
|---|
| 312 | if( lpiID == NULL ) /* *.ico */
|
|---|
| 313 | pCIDir = SHELL_LoadResource( hFile, pIconDir + i, *(WORD*)pData, &uSize );
|
|---|
| 314 | RetPtr[i-nIconIndex] = pLookupIconIdFromDirectoryEx( pCIDir, TRUE, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
|
|---|
| 315 | HeapFree(GetProcessHeap(), 0, pCIDir);
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
|
|---|
| 319 | { pCIDir = NULL;
|
|---|
| 320 | if( lpiID )
|
|---|
| 321 | { pCIDir = ICO_LoadIcon( hFile, lpiID->idEntries + RetPtr[icon-nIconIndex], &uSize);
|
|---|
| 322 | }
|
|---|
| 323 | else
|
|---|
| 324 | { for( i = 0; i < iconCount; i++ )
|
|---|
| 325 | { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
|
|---|
| 326 | { pCIDir = SHELL_LoadResource( hFile, pIconStorage + i,*(WORD*)pData, &uSize );
|
|---|
| 327 | }
|
|---|
| 328 | }
|
|---|
| 329 | }
|
|---|
| 330 | if( pCIDir )
|
|---|
| 331 | { RetPtr[icon-nIconIndex] = (HICON) pCreateIconFromResourceEx(pCIDir,uSize,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
|---|
| 332 | }
|
|---|
| 333 | else
|
|---|
| 334 | { RetPtr[icon-nIconIndex] = 0;
|
|---|
| 335 | }
|
|---|
| 336 | }
|
|---|
| 337 | }
|
|---|
| 338 | }
|
|---|
| 339 | if( lpiID )
|
|---|
| 340 | HeapFree( GetProcessHeap(), 0, lpiID);
|
|---|
| 341 | else
|
|---|
| 342 | HeapFree( GetProcessHeap(), 0, pData);
|
|---|
| 343 | }
|
|---|
| 344 | /* end ico file */
|
|---|
| 345 |
|
|---|
| 346 | /* exe/dll */
|
|---|
| 347 | if( sig == IMAGE_NT_SIGNATURE)
|
|---|
| 348 | { LPBYTE idata,igdata;
|
|---|
| 349 | PIMAGE_DOS_HEADER dheader;
|
|---|
| 350 | PIMAGE_NT_HEADERS pe_header;
|
|---|
| 351 | PIMAGE_SECTION_HEADER pe_sections;
|
|---|
| 352 | PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
|
|---|
| 353 | PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
|
|---|
| 354 | PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
|
|---|
| 355 | int i,j;
|
|---|
| 356 |
|
|---|
| 357 | if ( !(fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
|
|---|
| 358 | { WARN("failed to create filemap.\n"); /* FIXME, INVALID_HANDLE_VALUE? */
|
|---|
| 359 | goto end_2; /* failure */
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | if ( !(peimage = (BYTE*)MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0)))
|
|---|
| 363 | { WARN("failed to mmap filemap.\n");
|
|---|
| 364 | goto end_2; /* failure */
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | dheader = (PIMAGE_DOS_HEADER)peimage;
|
|---|
| 368 | pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, SHELL_GetResourceTable checked that */
|
|---|
| 369 | pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
|
|---|
| 370 | rootresdir = NULL;
|
|---|
| 371 |
|
|---|
| 372 | for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
|
|---|
| 373 | { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
|
|---|
| 374 | continue;
|
|---|
| 375 | /* FIXME: doesn't work when the resources are not in a seperate section */
|
|---|
| 376 | if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
|
|---|
| 377 | { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
|
|---|
| 378 | break;
|
|---|
| 379 | }
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | if (!rootresdir)
|
|---|
| 383 | { WARN("haven't found section for resource directory.\n");
|
|---|
| 384 | goto end_3; /* failure */
|
|---|
| 385 | }
|
|---|
| 386 | /* search the group icon dir*/
|
|---|
| 387 | if (!(icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE)))
|
|---|
| 388 | { WARN("No Icongroupresourcedirectory!\n");
|
|---|
| 389 | goto end_3; /* failure */
|
|---|
| 390 | }
|
|---|
| 391 | iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
|
|---|
| 392 |
|
|---|
| 393 | /* number of icons requested */
|
|---|
| 394 | if( nIconIndex == -1 )
|
|---|
| 395 | { hRet = iconDirCount;
|
|---|
| 396 | goto end_3; /* success */
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | /* if nIconIndex is negative we have to extract the icon whose resource
|
|---|
| 400 | id is equal to the absolute value of nIconIndex */
|
|---|
| 401 | if( nIconIndex < 0 )
|
|---|
| 402 | {
|
|---|
| 403 | int n = 0;
|
|---|
| 404 | int iId = abs(nIconIndex);
|
|---|
| 405 | PIMAGE_RESOURCE_DIRECTORY_ENTRY xprdeTmp = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
|
|---|
| 406 | nIconIndex = iconDirCount + 1; /* Initialise to get an error at
|
|---|
| 407 | the condition nIconIndex >= iconDirCount
|
|---|
| 408 | below if nothing is found */
|
|---|
| 409 | while(i<iconDirCount && xprdeTmp)
|
|---|
| 410 | {
|
|---|
| 411 | if(xprdeTmp->u1.Id == iId)
|
|---|
| 412 | {
|
|---|
| 413 | nIconIndex = n;
|
|---|
| 414 | break;
|
|---|
| 415 | }
|
|---|
| 416 | n++;
|
|---|
| 417 | xprdeTmp++;
|
|---|
| 418 | }
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | if (nIconIndex >= iconDirCount)
|
|---|
| 422 | { WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
|
|---|
| 423 | goto end_3; /* failure */
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1); /* caller just wanted the number of entries */
|
|---|
| 427 |
|
|---|
| 428 | if( n > iconDirCount - nIconIndex ) /* assure we don't get too much ... */
|
|---|
| 429 | { n = iconDirCount - nIconIndex;
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | xresent = xresent+nIconIndex; /* starting from specified index ... */
|
|---|
| 433 |
|
|---|
| 434 | for (i=0;i<n;i++,xresent++)
|
|---|
| 435 | { PIMAGE_RESOURCE_DIRECTORY resdir;
|
|---|
| 436 |
|
|---|
| 437 | /* go down this resource entry, name */
|
|---|
| 438 | resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
|
|---|
| 439 |
|
|---|
| 440 | /* default language (0) */
|
|---|
| 441 | resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
|---|
| 442 | igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
|
|---|
| 443 |
|
|---|
| 444 | /* lookup address in mapped image for virtual address */
|
|---|
| 445 | igdata = NULL;
|
|---|
| 446 |
|
|---|
| 447 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
|---|
| 448 | { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|---|
| 449 | continue;
|
|---|
| 450 | if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
|---|
| 451 | continue;
|
|---|
| 452 | igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | if (!igdata)
|
|---|
| 456 | { WARN("no matching real address for icongroup!\n");
|
|---|
| 457 | goto end_3; /* failure */
|
|---|
| 458 | }
|
|---|
| 459 | RetPtr[i] = (HICON)pLookupIconIdFromDirectoryEx(igdata, TRUE, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | if (!(iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE)))
|
|---|
| 463 | { WARN("No Iconresourcedirectory!\n");
|
|---|
| 464 | goto end_3; /* failure */
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | for (i=0;i<n;i++)
|
|---|
| 468 | { PIMAGE_RESOURCE_DIRECTORY xresdir;
|
|---|
| 469 | xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
|
|---|
| 470 | xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
|
|---|
| 471 | idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
|
|---|
| 472 | idata = NULL;
|
|---|
| 473 |
|
|---|
| 474 | /* map virtual to address in image */
|
|---|
| 475 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
|
|---|
| 476 | { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
|
|---|
| 477 | continue;
|
|---|
| 478 | if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
|
|---|
| 479 | continue;
|
|---|
| 480 | idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
|
|---|
| 481 | }
|
|---|
| 482 | if (!idata)
|
|---|
| 483 | { WARN("no matching real address found for icondata!\n");
|
|---|
| 484 | RetPtr[i]=0;
|
|---|
| 485 | continue;
|
|---|
| 486 | }
|
|---|
| 487 | //CB: bug in Open32 USER32.CreateIconFromResourceEx: returns 0
|
|---|
| 488 | // anyway, the Odin (Open32) icon handling is too far away from Win32
|
|---|
| 489 | RetPtr[i] = (HICON) pCreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
|---|
| 490 | }
|
|---|
| 491 | hRet = RetPtr[0]; /* return first icon */
|
|---|
| 492 | goto end_3; /* sucess */
|
|---|
| 493 | }
|
|---|
| 494 | goto end_1; /* unknown filetype */
|
|---|
| 495 |
|
|---|
| 496 | /* cleaning up (try & catch would be nicer:-) ) */
|
|---|
| 497 | end_3: UnmapViewOfFile(peimage); /* success */
|
|---|
| 498 | end_2: CloseHandle(fmapping);
|
|---|
| 499 | end_1: _lclose( hFile);
|
|---|
| 500 | return hRet;
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | /********************** THE ICON CACHE ********************************/
|
|---|
| 504 |
|
|---|
| 505 | #define INVALID_INDEX -1
|
|---|
| 506 |
|
|---|
| 507 | typedef struct
|
|---|
| 508 | { LPCSTR sSourceFile; /* file (not path!) containing the icon */
|
|---|
| 509 | DWORD dwSourceIndex; /* index within the file, if it is a resoure ID it will be negated */
|
|---|
| 510 | DWORD dwListIndex; /* index within the iconlist */
|
|---|
| 511 | DWORD dwFlags; /* GIL_* flags */
|
|---|
| 512 | DWORD dwAccessTime;
|
|---|
| 513 | } SIC_ENTRY, * LPSIC_ENTRY;
|
|---|
| 514 |
|
|---|
| 515 | /*****************************************************************************
|
|---|
| 516 | * SIC_CompareEntrys [called by comctl32.dll]
|
|---|
| 517 | *
|
|---|
| 518 | * NOTES
|
|---|
| 519 | * Callback for DPA_Search
|
|---|
| 520 | */
|
|---|
| 521 | INT CALLBACK SIC_CompareEntrys( LPVOID p1, LPVOID p2, LPARAM lparam)
|
|---|
| 522 | { dprintf(("SHELL32:Iconcache SIC_CompareEntrys %p %p\n", p1, p2));
|
|---|
| 523 |
|
|---|
| 524 | if (((LPSIC_ENTRY)p1)->dwSourceIndex != ((LPSIC_ENTRY)p2)->dwSourceIndex) /* first the faster one*/
|
|---|
| 525 | return 1;
|
|---|
| 526 |
|
|---|
| 527 | if (strcmp(((LPSIC_ENTRY)p1)->sSourceFile,((LPSIC_ENTRY)p2)->sSourceFile))
|
|---|
| 528 | return 1;
|
|---|
| 529 |
|
|---|
| 530 | return 0;
|
|---|
| 531 | }
|
|---|
| 532 | /*****************************************************************************
|
|---|
| 533 | * SIC_IconAppend [internal]
|
|---|
| 534 | *
|
|---|
| 535 | * NOTES
|
|---|
| 536 | * appends a icon pair to the end of the cache
|
|---|
| 537 | */
|
|---|
| 538 | static INT SIC_IconAppend (LPCSTR sSourceFile, INT dwSourceIndex, HICON hSmallIcon, HICON hBigIcon)
|
|---|
| 539 | { LPSIC_ENTRY lpsice;
|
|---|
| 540 | INT ret, index, index1;
|
|---|
| 541 |
|
|---|
| 542 | dprintf(("SHELL32:Iconcache SIC_IconAppend %s %i %x %x\n", sSourceFile, dwSourceIndex, hSmallIcon ,hBigIcon));
|
|---|
| 543 |
|
|---|
| 544 | lpsice = (LPSIC_ENTRY) SHAlloc (sizeof (SIC_ENTRY));
|
|---|
| 545 |
|
|---|
| 546 | lpsice->sSourceFile = HEAP_strdupA (GetProcessHeap(), 0, PathFindFileNameA(sSourceFile));
|
|---|
| 547 | lpsice->dwSourceIndex = dwSourceIndex;
|
|---|
| 548 |
|
|---|
| 549 | EnterCriticalSection(&SHELL32_SicCS);
|
|---|
| 550 |
|
|---|
| 551 | index = pDPA_InsertPtr(sic_hdpa, 0x7fff, lpsice);
|
|---|
| 552 | if ( INVALID_INDEX == index )
|
|---|
| 553 | {
|
|---|
| 554 | SHFree(lpsice);
|
|---|
| 555 | ret = INVALID_INDEX;
|
|---|
| 556 | }
|
|---|
| 557 | else
|
|---|
| 558 | {
|
|---|
| 559 | index = pImageList_AddIcon (ShellSmallIconList, hSmallIcon);
|
|---|
| 560 | index1= pImageList_AddIcon (ShellBigIconList, hBigIcon);
|
|---|
| 561 |
|
|---|
| 562 | if (index!=index1)
|
|---|
| 563 | {
|
|---|
| 564 | dprintf(("iconlists out of sync 0x%x 0x%x\n", index, index1));
|
|---|
| 565 | }
|
|---|
| 566 | lpsice->dwListIndex = index;
|
|---|
| 567 | ret = lpsice->dwListIndex;
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | LeaveCriticalSection(&SHELL32_SicCS);
|
|---|
| 571 | return ret;
|
|---|
| 572 | }
|
|---|
| 573 | /****************************************************************************
|
|---|
| 574 | * SIC_LoadIcon [internal]
|
|---|
| 575 | *
|
|---|
| 576 | * NOTES
|
|---|
| 577 | * gets small/big icon by number from a file
|
|---|
| 578 | */
|
|---|
| 579 | static INT SIC_LoadIcon (LPCSTR sSourceFile, INT dwSourceIndex)
|
|---|
| 580 | { HICON hiconLarge=0;
|
|---|
| 581 | HICON hiconSmall=0;
|
|---|
| 582 |
|
|---|
| 583 | ICO_ExtractIconEx(sSourceFile, &hiconLarge, dwSourceIndex, 1, 32, 32 );
|
|---|
| 584 | ICO_ExtractIconEx(sSourceFile, &hiconSmall, dwSourceIndex, 1, 16, 16 );
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 | if ( !hiconLarge || !hiconSmall)
|
|---|
| 588 | {
|
|---|
| 589 | dprintf(("failure loading icon %i from %s (%x %x)\n", dwSourceIndex, sSourceFile, hiconLarge, hiconSmall));
|
|---|
| 590 | return -1;
|
|---|
| 591 | }
|
|---|
| 592 | return SIC_IconAppend (sSourceFile, dwSourceIndex, hiconSmall, hiconLarge);
|
|---|
| 593 | }
|
|---|
| 594 | /*****************************************************************************
|
|---|
| 595 | * SIC_GetIconIndex [internal]
|
|---|
| 596 | *
|
|---|
| 597 | * Parameters
|
|---|
| 598 | * sSourceFile [IN] filename of file containing the icon
|
|---|
| 599 | * index [IN] index/resID (negated) in this file
|
|---|
| 600 | *
|
|---|
| 601 | * NOTES
|
|---|
| 602 | * look in the cache for a proper icon. if not available the icon is taken
|
|---|
| 603 | * from the file and cached
|
|---|
| 604 | */
|
|---|
| 605 | INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
|
|---|
| 606 | { SIC_ENTRY sice;
|
|---|
| 607 | INT ret, index = INVALID_INDEX;
|
|---|
| 608 |
|
|---|
| 609 | dprintf(("SHELL32:Iconcache SIC_GetIconIndex %s %i\n", sSourceFile, dwSourceIndex));
|
|---|
| 610 |
|
|---|
| 611 | sice.sSourceFile = PathFindFileNameA(sSourceFile);
|
|---|
| 612 | sice.dwSourceIndex = dwSourceIndex;
|
|---|
| 613 |
|
|---|
| 614 | EnterCriticalSection(&SHELL32_SicCS);
|
|---|
| 615 |
|
|---|
| 616 | if (NULL != pDPA_GetPtr (sic_hdpa, 0))
|
|---|
| 617 | {
|
|---|
| 618 | index = pDPA_Search (sic_hdpa, &sice, -1L, (PFNDPACOMPARE)SIC_CompareEntrys, 0, 0);
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | if ( INVALID_INDEX == index )
|
|---|
| 622 | {
|
|---|
| 623 | if (strcmp(sSourceFile,"shell32.dll") == 0)
|
|---|
| 624 | ret = -1; //icon not in cache -> set to default
|
|---|
| 625 | else
|
|---|
| 626 | ret = SIC_LoadIcon (sSourceFile, dwSourceIndex);
|
|---|
| 627 | }
|
|---|
| 628 | else
|
|---|
| 629 | {
|
|---|
| 630 | dprintf(("SHELL32:Iconcache -- found\n"));
|
|---|
| 631 | ret = ((LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, index))->dwListIndex;
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | LeaveCriticalSection(&SHELL32_SicCS);
|
|---|
| 635 | return ret;
|
|---|
| 636 | }
|
|---|
| 637 | /****************************************************************************
|
|---|
| 638 | * SIC_LoadIcon [internal]
|
|---|
| 639 | *
|
|---|
| 640 | * NOTES
|
|---|
| 641 | * retrives the specified icon from the iconcache. if not found try's to load the icon
|
|---|
| 642 | */
|
|---|
| 643 | static HICON WINE_UNUSED SIC_GetIcon (LPCSTR sSourceFile, INT dwSourceIndex, BOOL bSmallIcon )
|
|---|
| 644 | { INT index;
|
|---|
| 645 |
|
|---|
| 646 | dprintf(("SHELL32:Iconcache SIC_GetIcon %s %i\n", sSourceFile, dwSourceIndex));
|
|---|
| 647 |
|
|---|
| 648 | index = SIC_GetIconIndex(sSourceFile, dwSourceIndex);
|
|---|
| 649 |
|
|---|
| 650 | if (INVALID_INDEX == index)
|
|---|
| 651 | {
|
|---|
| 652 | return INVALID_INDEX;
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | if (bSmallIcon)
|
|---|
| 656 | return pImageList_GetIcon(ShellSmallIconList, index, ILD_NORMAL);
|
|---|
| 657 | return pImageList_GetIcon(ShellBigIconList, index, ILD_NORMAL);
|
|---|
| 658 |
|
|---|
| 659 | }
|
|---|
| 660 | /*****************************************************************************
|
|---|
| 661 | * SIC_Initialize [internal]
|
|---|
| 662 | *
|
|---|
| 663 | * NOTES
|
|---|
| 664 | * hack to load the resources from the shell32.dll under a different dll name
|
|---|
| 665 | * will be removed when the resource-compiler is ready
|
|---|
| 666 | */
|
|---|
| 667 | BOOL SIC_Initialize(void)
|
|---|
| 668 | {
|
|---|
| 669 | HICON hSm, hLg;
|
|---|
| 670 | UINT index;
|
|---|
| 671 |
|
|---|
| 672 | dprintf(("SHELL32:Iconcache SIC_Initialize\n"));
|
|---|
| 673 |
|
|---|
| 674 | if (sic_hdpa) /* already initialized?*/
|
|---|
| 675 | return TRUE;
|
|---|
| 676 |
|
|---|
| 677 | InitializeCriticalSection(&SHELL32_SicCS);
|
|---|
| 678 |
|
|---|
| 679 | sic_hdpa = pDPA_Create(16);
|
|---|
| 680 |
|
|---|
| 681 | if (!sic_hdpa)
|
|---|
| 682 | {
|
|---|
| 683 | return(FALSE);
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | ShellSmallIconList = pImageList_Create(16,16,ILC_COLORDDB | ILC_MASK,0,0x20);
|
|---|
| 687 | ShellBigIconList = pImageList_Create(32,32,ILC_COLORDDB | ILC_MASK,0,0x20);
|
|---|
| 688 |
|
|---|
| 689 | pImageList_SetBkColor(ShellSmallIconList, GetSysColor(COLOR_WINDOW));
|
|---|
| 690 | pImageList_SetBkColor(ShellBigIconList, GetSysColor(COLOR_WINDOW));
|
|---|
| 691 |
|
|---|
| 692 | for (index=1; index<39; index++)
|
|---|
| 693 | {
|
|---|
| 694 | hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 16, 16,LR_SHARED);
|
|---|
| 695 | hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 32, 32,LR_SHARED);
|
|---|
| 696 |
|
|---|
| 697 | if(!hSm)
|
|---|
| 698 | {
|
|---|
| 699 | hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 16, 16,LR_SHARED);
|
|---|
| 700 | hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 32, 32,LR_SHARED);
|
|---|
| 701 | }
|
|---|
| 702 | SIC_IconAppend ("shell32.dll", index, hSm, hLg);
|
|---|
| 703 | }
|
|---|
| 704 |
|
|---|
| 705 | dprintf(("SHELL32:Iconcache hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList));
|
|---|
| 706 |
|
|---|
| 707 | return TRUE;
|
|---|
| 708 | }
|
|---|
| 709 | /*************************************************************************
|
|---|
| 710 | * SIC_Destroy
|
|---|
| 711 | *
|
|---|
| 712 | * frees the cache
|
|---|
| 713 | */
|
|---|
| 714 | void SIC_Destroy(void)
|
|---|
| 715 | {
|
|---|
| 716 | LPSIC_ENTRY lpsice;
|
|---|
| 717 | int i;
|
|---|
| 718 |
|
|---|
| 719 | dprintf(("SHELL32:Iconcache SIC_Destroy\n"));
|
|---|
| 720 |
|
|---|
| 721 | EnterCriticalSection(&SHELL32_SicCS);
|
|---|
| 722 |
|
|---|
| 723 | if (sic_hdpa && NULL != pDPA_GetPtr (sic_hdpa, 0))
|
|---|
| 724 | {
|
|---|
| 725 | for (i=0; i < pDPA_GetPtrCount(sic_hdpa); ++i)
|
|---|
| 726 | {
|
|---|
| 727 | lpsice = (LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, i);
|
|---|
| 728 | SHFree(lpsice);
|
|---|
| 729 | }
|
|---|
| 730 | pDPA_Destroy(sic_hdpa);
|
|---|
| 731 | }
|
|---|
| 732 |
|
|---|
| 733 | sic_hdpa = NULL;
|
|---|
| 734 |
|
|---|
| 735 | LeaveCriticalSection(&SHELL32_SicCS);
|
|---|
| 736 | }
|
|---|
| 737 | /*************************************************************************
|
|---|
| 738 | * Shell_GetImageList [SHELL32.71]
|
|---|
| 739 | *
|
|---|
| 740 | * PARAMETERS
|
|---|
| 741 | * imglist[1|2] [OUT] pointer which recive imagelist handles
|
|---|
| 742 | *
|
|---|
| 743 | */
|
|---|
| 744 |
|
|---|
| 745 | ODINFUNCTION2(BOOL,Shell_GetImageList,HIMAGELIST*, lpBigList,
|
|---|
| 746 | HIMAGELIST*, lpSmallList)
|
|---|
| 747 | {
|
|---|
| 748 | if (lpBigList)
|
|---|
| 749 | { *lpBigList = ShellBigIconList;
|
|---|
| 750 | }
|
|---|
| 751 | if (lpSmallList)
|
|---|
| 752 | { *lpSmallList = ShellSmallIconList;
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | return TRUE;
|
|---|
| 756 | }
|
|---|
| 757 | /*************************************************************************
|
|---|
| 758 | * PidlToSicIndex [INTERNAL]
|
|---|
| 759 | *
|
|---|
| 760 | * PARAMETERS
|
|---|
| 761 | * sh [IN] IShellFolder
|
|---|
| 762 | * pidl [IN]
|
|---|
| 763 | * bBigIcon [IN]
|
|---|
| 764 | * pIndex [OUT] index within the SIC
|
|---|
| 765 | *
|
|---|
| 766 | */
|
|---|
| 767 | BOOL PidlToSicIndex (IShellFolder * sh, LPITEMIDLIST pidl, BOOL bBigIcon, UINT * pIndex)
|
|---|
| 768 | {
|
|---|
| 769 | IExtractIcon *ei;
|
|---|
| 770 | char szIconFile[MAX_PATH]; /* file containing the icon */
|
|---|
| 771 | INT iSourceIndex; /* index or resID(negated) in this file */
|
|---|
| 772 | BOOL ret = FALSE;
|
|---|
| 773 | UINT dwFlags = 0;
|
|---|
| 774 |
|
|---|
| 775 | dprintf(("SHELL32:Iconcache PidlToSicIndex sf=%p pidl=%p\n", sh, pidl));
|
|---|
| 776 |
|
|---|
| 777 | if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh, 0, 1, &pidl, &IID_IExtractIconA, 0, (void **)&ei)))
|
|---|
| 778 | {
|
|---|
| 779 | if (NOERROR==IExtractIconA_GetIconLocation(ei, 0, szIconFile, MAX_PATH, &iSourceIndex, &dwFlags))
|
|---|
| 780 | { *pIndex = SIC_GetIconIndex(szIconFile, iSourceIndex);
|
|---|
| 781 | ret = TRUE;
|
|---|
| 782 | }
|
|---|
| 783 | IExtractIconA_Release(ei);
|
|---|
| 784 | }
|
|---|
| 785 |
|
|---|
| 786 | if (INVALID_INDEX == *pIndex) /* default icon when failed */
|
|---|
| 787 | *pIndex = 1;
|
|---|
| 788 |
|
|---|
| 789 | return ret;
|
|---|
| 790 |
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | /*************************************************************************
|
|---|
| 794 | * SHMapPIDLToSystemImageListIndex [SHELL32.77]
|
|---|
| 795 | *
|
|---|
| 796 | * PARAMETERS
|
|---|
| 797 | * sh [IN] pointer to an instance of IShellFolder
|
|---|
| 798 | * pidl [IN]
|
|---|
| 799 | * pIndex [OUT][OPTIONAL] SIC index for big icon
|
|---|
| 800 | *
|
|---|
| 801 | */
|
|---|
| 802 |
|
|---|
| 803 | ODINFUNCTION3(UINT,SHMapPIDLToSystemImageListIndex,LPSHELLFOLDER, sh,
|
|---|
| 804 | LPITEMIDLIST, pidl,
|
|---|
| 805 | UINT*, pIndex)
|
|---|
| 806 | {
|
|---|
| 807 | UINT Index;
|
|---|
| 808 |
|
|---|
| 809 | pdump(pidl);
|
|---|
| 810 |
|
|---|
| 811 | if (pIndex)
|
|---|
| 812 | PidlToSicIndex ( sh, pidl, 1, pIndex);
|
|---|
| 813 | PidlToSicIndex ( sh, pidl, 0, &Index);
|
|---|
| 814 | return Index;
|
|---|
| 815 | }
|
|---|
| 816 |
|
|---|
| 817 | /*************************************************************************
|
|---|
| 818 | * Shell_GetCachedImageIndex [SHELL32.72]
|
|---|
| 819 | *
|
|---|
| 820 | */
|
|---|
| 821 | ODINFUNCTION3(INT,Shell_GetCachedImageIndexA,LPCSTR,szPath,
|
|---|
| 822 | INT, nIndex,
|
|---|
| 823 | BOOL, bSimulateDoc)
|
|---|
| 824 | {
|
|---|
| 825 | dprintf(("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath), nIndex, bSimulateDoc));
|
|---|
| 826 | return SIC_GetIconIndex(szPath, nIndex);
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 | ODINFUNCTION3(INT,Shell_GetCachedImageIndexW,LPCWSTR, szPath,
|
|---|
| 830 | INT, nIndex,
|
|---|
| 831 | BOOL, bSimulateDoc)
|
|---|
| 832 | { INT ret;
|
|---|
| 833 | LPSTR sTemp = HEAP_strdupWtoA (GetProcessHeap(),0,szPath);
|
|---|
| 834 |
|
|---|
| 835 | dprintf(("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath), nIndex, bSimulateDoc));
|
|---|
| 836 |
|
|---|
| 837 | ret = SIC_GetIconIndex(sTemp, nIndex);
|
|---|
| 838 | HeapFree(GetProcessHeap(),0,sTemp);
|
|---|
| 839 | return ret;
|
|---|
| 840 | }
|
|---|
| 841 |
|
|---|
| 842 | ODINFUNCTION3(INT,Shell_GetCachedImageIndexAW,LPCVOID, szPath,
|
|---|
| 843 | INT, nIndex,
|
|---|
| 844 | BOOL, bSimulateDoc)
|
|---|
| 845 | { if( VERSION_OsIsUnicode())
|
|---|
| 846 | return Shell_GetCachedImageIndexW((LPWSTR)szPath, nIndex, bSimulateDoc);
|
|---|
| 847 | return Shell_GetCachedImageIndexA((LPSTR)szPath, nIndex, bSimulateDoc);
|
|---|
| 848 | }
|
|---|
| 849 |
|
|---|
| 850 | /*************************************************************************
|
|---|
| 851 | * ExtracticonExAW [shell32.189]
|
|---|
| 852 | */
|
|---|
| 853 |
|
|---|
| 854 | ODINFUNCTION5(HICON,ExtractIconExAW,LPCVOID, lpszFile,
|
|---|
| 855 | INT, nIconIndex,
|
|---|
| 856 | HICON*, phiconLarge,
|
|---|
| 857 | HICON*, phiconSmall,
|
|---|
| 858 | UINT, nIcons)
|
|---|
| 859 | { if (VERSION_OsIsUnicode())
|
|---|
| 860 | return ExtractIconExW ( (LPWSTR)lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
|---|
| 861 | return ExtractIconExA ( (LPSTR)lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
|---|
| 862 | }
|
|---|
| 863 | /*************************************************************************
|
|---|
| 864 | * ExtracticonExA [shell32.190]
|
|---|
| 865 | * RETURNS
|
|---|
| 866 | * 0 no icon found
|
|---|
| 867 | * 1 file is not valid
|
|---|
| 868 | * HICON handle of a icon (phiconLarge/Small == NULL)
|
|---|
| 869 | */
|
|---|
| 870 |
|
|---|
| 871 | ODINFUNCTION5(HICON,ExtractIconExA, LPCSTR, lpszFile,
|
|---|
| 872 | INT, nIconIndex,
|
|---|
| 873 | HICON*, phiconLarge,
|
|---|
| 874 | HICON*, phiconSmall,
|
|---|
| 875 | UINT, nIcons)
|
|---|
| 876 | { HICON ret=0;
|
|---|
| 877 |
|
|---|
| 878 | dprintf(("SHELL32:Iconcache file=%s idx=%i %p %p num=%i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons ));
|
|---|
| 879 |
|
|---|
| 880 | if (nIconIndex==-1) /* Number of icons requested */
|
|---|
| 881 | return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0 );
|
|---|
| 882 |
|
|---|
| 883 |
|
|---|
| 884 | if (phiconLarge)
|
|---|
| 885 | { ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32 );
|
|---|
| 886 | if ( nIcons==1)
|
|---|
| 887 | { ret = phiconLarge[0];
|
|---|
| 888 | }
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 | /* if no pointers given and one icon expected, return the handle directly*/
|
|---|
| 892 | if (!phiconLarge && ! phiconSmall && nIcons==1 )
|
|---|
| 893 | phiconSmall = &ret;
|
|---|
| 894 |
|
|---|
| 895 | if (phiconSmall)
|
|---|
| 896 | { ret = ICO_ExtractIconEx(lpszFile, phiconSmall, nIconIndex, nIcons, 16, 16 );
|
|---|
| 897 | if ( nIcons==1 )
|
|---|
| 898 | { ret = phiconSmall[0];
|
|---|
| 899 | }
|
|---|
| 900 | }
|
|---|
| 901 |
|
|---|
| 902 | return ret;
|
|---|
| 903 | }
|
|---|
| 904 | /*************************************************************************
|
|---|
| 905 | * ExtracticonExW [shell32.191]
|
|---|
| 906 | */
|
|---|
| 907 | ODINFUNCTION5(HICON,ExtractIconExW,LPCWSTR, lpszFile,
|
|---|
| 908 | INT, nIconIndex,
|
|---|
| 909 | HICON*, phiconLarge,
|
|---|
| 910 | HICON*, phiconSmall,
|
|---|
| 911 | UINT, nIcons)
|
|---|
| 912 | { LPSTR sFile;
|
|---|
| 913 | DWORD ret;
|
|---|
| 914 |
|
|---|
| 915 | dprintf(("SHELL32:Iconcache file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile), nIconIndex, phiconLarge, phiconSmall, nIcons ));
|
|---|
| 916 |
|
|---|
| 917 | sFile = HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile);
|
|---|
| 918 | ret = ExtractIconExA ( sFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
|---|
| 919 | HeapFree(GetProcessHeap(),0,sFile);
|
|---|
| 920 | return ret;
|
|---|
| 921 | }
|
|---|
| 922 |
|
|---|
| 923 | /*
|
|---|
| 924 | * PE (Portable Execute) File Resources
|
|---|
| 925 | *
|
|---|
| 926 | * Copyright 1995 Thomas Sandford
|
|---|
| 927 | * Copyright 1996 Martin von Loewis
|
|---|
| 928 | *
|
|---|
| 929 | * Based on the Win16 resource handling code in loader/resource.c
|
|---|
| 930 | * Copyright 1993 Robert J. Amstadt
|
|---|
| 931 | * Copyright 1995 Alexandre Julliard
|
|---|
| 932 | * Copyright 1997 Marcus Meissner
|
|---|
| 933 | */
|
|---|
| 934 |
|
|---|
| 935 | //CB: from loader/pe_resource.c
|
|---|
| 936 |
|
|---|
| 937 | /**********************************************************************
|
|---|
| 938 | * GetResDirEntryW
|
|---|
| 939 | *
|
|---|
| 940 | * Helper function - goes down one level of PE resource tree
|
|---|
| 941 | *
|
|---|
| 942 | */
|
|---|
| 943 | PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
|
|---|
| 944 | LPCWSTR name,DWORD root,
|
|---|
| 945 | BOOL allowdefault)
|
|---|
| 946 | {
|
|---|
| 947 | int entrynum;
|
|---|
| 948 | PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
|
|---|
| 949 | int namelen;
|
|---|
| 950 |
|
|---|
| 951 | if (HIWORD(name)) {
|
|---|
| 952 | if (name[0]=='#') {
|
|---|
| 953 | char buf[10];
|
|---|
| 954 |
|
|---|
| 955 | lstrcpynWtoA(buf,name+1,10);
|
|---|
| 956 | return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
|
|---|
| 957 | }
|
|---|
| 958 | entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
|---|
| 959 | (BYTE *) resdirptr +
|
|---|
| 960 | sizeof(IMAGE_RESOURCE_DIRECTORY));
|
|---|
| 961 | namelen = lstrlenW(name);
|
|---|
| 962 | for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
|
|---|
| 963 | {
|
|---|
| 964 | PIMAGE_RESOURCE_DIR_STRING_U str =
|
|---|
| 965 | (PIMAGE_RESOURCE_DIR_STRING_U) (root +
|
|---|
| 966 | entryTable[entrynum].u1.s.NameOffset);
|
|---|
| 967 | if(namelen != str->Length)
|
|---|
| 968 | continue;
|
|---|
| 969 | if(lstrncmpiW(name,str->NameString,str->Length)==0)
|
|---|
| 970 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
|---|
| 971 | root +
|
|---|
| 972 | entryTable[entrynum].u2.s.OffsetToDirectory);
|
|---|
| 973 | }
|
|---|
| 974 | return NULL;
|
|---|
| 975 | } else {
|
|---|
| 976 | entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
|---|
| 977 | (BYTE *) resdirptr +
|
|---|
| 978 | sizeof(IMAGE_RESOURCE_DIRECTORY) +
|
|---|
| 979 | resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
|
|---|
| 980 | for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
|
|---|
| 981 | if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
|
|---|
| 982 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
|---|
| 983 | root +
|
|---|
| 984 | entryTable[entrynum].u2.s.OffsetToDirectory);
|
|---|
| 985 | /* just use first entry if no default can be found */
|
|---|
| 986 | if (allowdefault && !name && resdirptr->NumberOfIdEntries)
|
|---|
| 987 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
|---|
| 988 | root +
|
|---|
| 989 | entryTable[0].u2.s.OffsetToDirectory);
|
|---|
| 990 | return NULL;
|
|---|
| 991 | }
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|