1 | /* $Id: iconcache.cpp,v 1.5 2000-03-27 15:09:20 cbratschi 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 | RetPtr[i] = (HICON) pCreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000, cxDesired, cyDesired, LR_DEFAULTCOLOR);
|
---|
488 | }
|
---|
489 | hRet = RetPtr[0]; /* return first icon */
|
---|
490 | goto end_3; /* sucess */
|
---|
491 | }
|
---|
492 | goto end_1; /* unknown filetype */
|
---|
493 |
|
---|
494 | /* cleaning up (try & catch would be nicer:-) ) */
|
---|
495 | end_3: UnmapViewOfFile(peimage); /* success */
|
---|
496 | end_2: CloseHandle(fmapping);
|
---|
497 | end_1: _lclose( hFile);
|
---|
498 | return hRet;
|
---|
499 | }
|
---|
500 |
|
---|
501 | /********************** THE ICON CACHE ********************************/
|
---|
502 |
|
---|
503 | #define INVALID_INDEX -1
|
---|
504 |
|
---|
505 | typedef struct
|
---|
506 | { LPCSTR sSourceFile; /* file (not path!) containing the icon */
|
---|
507 | DWORD dwSourceIndex; /* index within the file, if it is a resoure ID it will be negated */
|
---|
508 | DWORD dwListIndex; /* index within the iconlist */
|
---|
509 | DWORD dwFlags; /* GIL_* flags */
|
---|
510 | DWORD dwAccessTime;
|
---|
511 | } SIC_ENTRY, * LPSIC_ENTRY;
|
---|
512 |
|
---|
513 | /*****************************************************************************
|
---|
514 | * SIC_CompareEntrys [called by comctl32.dll]
|
---|
515 | *
|
---|
516 | * NOTES
|
---|
517 | * Callback for DPA_Search
|
---|
518 | */
|
---|
519 | INT CALLBACK SIC_CompareEntrys( LPVOID p1, LPVOID p2, LPARAM lparam)
|
---|
520 | { dprintf(("SHELL32:Iconcache SIC_CompareEntrys %p %p\n", p1, p2));
|
---|
521 |
|
---|
522 | if (((LPSIC_ENTRY)p1)->dwSourceIndex != ((LPSIC_ENTRY)p2)->dwSourceIndex) /* first the faster one*/
|
---|
523 | return 1;
|
---|
524 |
|
---|
525 | if (strcmp(((LPSIC_ENTRY)p1)->sSourceFile,((LPSIC_ENTRY)p2)->sSourceFile))
|
---|
526 | return 1;
|
---|
527 |
|
---|
528 | return 0;
|
---|
529 | }
|
---|
530 | /*****************************************************************************
|
---|
531 | * SIC_IconAppend [internal]
|
---|
532 | *
|
---|
533 | * NOTES
|
---|
534 | * appends a icon pair to the end of the cache
|
---|
535 | */
|
---|
536 | static INT SIC_IconAppend (LPCSTR sSourceFile, INT dwSourceIndex, HICON hSmallIcon, HICON hBigIcon)
|
---|
537 | { LPSIC_ENTRY lpsice;
|
---|
538 | INT ret, index, index1;
|
---|
539 |
|
---|
540 | dprintf(("SHELL32:Iconcache SIC_IconAppend %s %i %x %x\n", sSourceFile, dwSourceIndex, hSmallIcon ,hBigIcon));
|
---|
541 |
|
---|
542 | lpsice = (LPSIC_ENTRY) SHAlloc (sizeof (SIC_ENTRY));
|
---|
543 |
|
---|
544 | lpsice->sSourceFile = HEAP_strdupA (GetProcessHeap(), 0, PathFindFilenameA(sSourceFile));
|
---|
545 | lpsice->dwSourceIndex = dwSourceIndex;
|
---|
546 |
|
---|
547 | EnterCriticalSection(&SHELL32_SicCS);
|
---|
548 |
|
---|
549 | index = pDPA_InsertPtr(sic_hdpa, 0x7fff, lpsice);
|
---|
550 | if ( INVALID_INDEX == index )
|
---|
551 | {
|
---|
552 | SHFree(lpsice);
|
---|
553 | ret = INVALID_INDEX;
|
---|
554 | }
|
---|
555 | else
|
---|
556 | {
|
---|
557 | index = pImageList_AddIcon (ShellSmallIconList, hSmallIcon);
|
---|
558 | index1= pImageList_AddIcon (ShellBigIconList, hBigIcon);
|
---|
559 |
|
---|
560 | if (index!=index1)
|
---|
561 | {
|
---|
562 | dprintf(("iconlists out of sync 0x%x 0x%x\n", index, index1));
|
---|
563 | }
|
---|
564 | lpsice->dwListIndex = index;
|
---|
565 | ret = lpsice->dwListIndex;
|
---|
566 | }
|
---|
567 |
|
---|
568 | LeaveCriticalSection(&SHELL32_SicCS);
|
---|
569 | return ret;
|
---|
570 | }
|
---|
571 | /****************************************************************************
|
---|
572 | * SIC_LoadIcon [internal]
|
---|
573 | *
|
---|
574 | * NOTES
|
---|
575 | * gets small/big icon by number from a file
|
---|
576 | */
|
---|
577 | static INT SIC_LoadIcon (LPCSTR sSourceFile, INT dwSourceIndex)
|
---|
578 | { HICON hiconLarge=0;
|
---|
579 | HICON hiconSmall=0;
|
---|
580 |
|
---|
581 | ICO_ExtractIconEx(sSourceFile, &hiconLarge, dwSourceIndex, 1, 32, 32 );
|
---|
582 | ICO_ExtractIconEx(sSourceFile, &hiconSmall, dwSourceIndex, 1, 16, 16 );
|
---|
583 |
|
---|
584 |
|
---|
585 | if ( !hiconLarge || !hiconSmall)
|
---|
586 | {
|
---|
587 | dprintf(("failure loading icon %i from %s (%x %x)\n", dwSourceIndex, sSourceFile, hiconLarge, hiconSmall));
|
---|
588 | return -1;
|
---|
589 | }
|
---|
590 | return SIC_IconAppend (sSourceFile, dwSourceIndex, hiconSmall, hiconLarge);
|
---|
591 | }
|
---|
592 | /*****************************************************************************
|
---|
593 | * SIC_GetIconIndex [internal]
|
---|
594 | *
|
---|
595 | * Parameters
|
---|
596 | * sSourceFile [IN] filename of file containing the icon
|
---|
597 | * index [IN] index/resID (negated) in this file
|
---|
598 | *
|
---|
599 | * NOTES
|
---|
600 | * look in the cache for a proper icon. if not available the icon is taken
|
---|
601 | * from the file and cached
|
---|
602 | */
|
---|
603 | INT SIC_GetIconIndex (LPCSTR sSourceFile, INT dwSourceIndex )
|
---|
604 | { SIC_ENTRY sice;
|
---|
605 | INT ret, index = INVALID_INDEX;
|
---|
606 |
|
---|
607 | dprintf(("SHELL32:Iconcache SIC_GetIconIndex %s %i\n", sSourceFile, dwSourceIndex));
|
---|
608 |
|
---|
609 | sice.sSourceFile = PathFindFilenameA(sSourceFile);
|
---|
610 | sice.dwSourceIndex = dwSourceIndex;
|
---|
611 |
|
---|
612 | EnterCriticalSection(&SHELL32_SicCS);
|
---|
613 |
|
---|
614 | if (NULL != pDPA_GetPtr (sic_hdpa, 0))
|
---|
615 | {
|
---|
616 | index = pDPA_Search (sic_hdpa, &sice, -1L, (PFNDPACOMPARE)SIC_CompareEntrys, 0, 0);
|
---|
617 | }
|
---|
618 |
|
---|
619 | if ( INVALID_INDEX == index )
|
---|
620 | {
|
---|
621 | ret = SIC_LoadIcon (sSourceFile, dwSourceIndex);
|
---|
622 | }
|
---|
623 | else
|
---|
624 | {
|
---|
625 | dprintf(("SHELL32:Iconcache -- found\n"));
|
---|
626 | ret = ((LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, index))->dwListIndex;
|
---|
627 | }
|
---|
628 |
|
---|
629 | LeaveCriticalSection(&SHELL32_SicCS);
|
---|
630 | return ret;
|
---|
631 | }
|
---|
632 | /****************************************************************************
|
---|
633 | * SIC_LoadIcon [internal]
|
---|
634 | *
|
---|
635 | * NOTES
|
---|
636 | * retrives the specified icon from the iconcache. if not found try's to load the icon
|
---|
637 | */
|
---|
638 | static HICON WINE_UNUSED SIC_GetIcon (LPCSTR sSourceFile, INT dwSourceIndex, BOOL bSmallIcon )
|
---|
639 | { INT index;
|
---|
640 |
|
---|
641 | dprintf(("SHELL32:Iconcache SIC_GetIcon %s %i\n", sSourceFile, dwSourceIndex));
|
---|
642 |
|
---|
643 | index = SIC_GetIconIndex(sSourceFile, dwSourceIndex);
|
---|
644 |
|
---|
645 | if (INVALID_INDEX == index)
|
---|
646 | {
|
---|
647 | return INVALID_INDEX;
|
---|
648 | }
|
---|
649 |
|
---|
650 | if (bSmallIcon)
|
---|
651 | return pImageList_GetIcon(ShellSmallIconList, index, ILD_NORMAL);
|
---|
652 | return pImageList_GetIcon(ShellBigIconList, index, ILD_NORMAL);
|
---|
653 |
|
---|
654 | }
|
---|
655 | /*****************************************************************************
|
---|
656 | * SIC_Initialize [internal]
|
---|
657 | *
|
---|
658 | * NOTES
|
---|
659 | * hack to load the resources from the shell32.dll under a different dll name
|
---|
660 | * will be removed when the resource-compiler is ready
|
---|
661 | */
|
---|
662 | BOOL SIC_Initialize(void)
|
---|
663 | {
|
---|
664 | HICON hSm, hLg;
|
---|
665 | UINT index;
|
---|
666 |
|
---|
667 | dprintf(("SHELL32:Iconcache SIC_Initialize\n"));
|
---|
668 |
|
---|
669 | if (sic_hdpa) /* already initialized?*/
|
---|
670 | return TRUE;
|
---|
671 |
|
---|
672 | InitializeCriticalSection(&SHELL32_SicCS);
|
---|
673 |
|
---|
674 | sic_hdpa = pDPA_Create(16);
|
---|
675 |
|
---|
676 | if (!sic_hdpa)
|
---|
677 | {
|
---|
678 | return(FALSE);
|
---|
679 | }
|
---|
680 |
|
---|
681 | ShellSmallIconList = pImageList_Create(16,16,ILC_COLORDDB | ILC_MASK,0,0x20);
|
---|
682 | ShellBigIconList = pImageList_Create(32,32,ILC_COLORDDB | ILC_MASK,0,0x20);
|
---|
683 |
|
---|
684 | pImageList_SetBkColor(ShellSmallIconList, GetSysColor(COLOR_WINDOW));
|
---|
685 | pImageList_SetBkColor(ShellBigIconList, GetSysColor(COLOR_WINDOW));
|
---|
686 |
|
---|
687 | for (index=1; index<39; index++)
|
---|
688 | {
|
---|
689 | hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 16, 16,LR_SHARED);
|
---|
690 | hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(index), IMAGE_ICON, 32, 32,LR_SHARED);
|
---|
691 |
|
---|
692 | if(!hSm)
|
---|
693 | {
|
---|
694 | hSm = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 16, 16,LR_SHARED);
|
---|
695 | hLg = LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(0), IMAGE_ICON, 32, 32,LR_SHARED);
|
---|
696 | }
|
---|
697 | SIC_IconAppend ("shell32.dll", index, hSm, hLg);
|
---|
698 | }
|
---|
699 |
|
---|
700 | dprintf(("SHELL32:Iconcache hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList));
|
---|
701 |
|
---|
702 | return TRUE;
|
---|
703 | }
|
---|
704 | /*************************************************************************
|
---|
705 | * SIC_Destroy
|
---|
706 | *
|
---|
707 | * frees the cache
|
---|
708 | */
|
---|
709 | void SIC_Destroy(void)
|
---|
710 | {
|
---|
711 | LPSIC_ENTRY lpsice;
|
---|
712 | int i;
|
---|
713 |
|
---|
714 | dprintf(("SHELL32:Iconcache SIC_Destroy\n"));
|
---|
715 |
|
---|
716 | EnterCriticalSection(&SHELL32_SicCS);
|
---|
717 |
|
---|
718 | if (sic_hdpa && NULL != pDPA_GetPtr (sic_hdpa, 0))
|
---|
719 | {
|
---|
720 | for (i=0; i < pDPA_GetPtrCount(sic_hdpa); ++i)
|
---|
721 | {
|
---|
722 | lpsice = (LPSIC_ENTRY)pDPA_GetPtr(sic_hdpa, i);
|
---|
723 | SHFree(lpsice);
|
---|
724 | }
|
---|
725 | pDPA_Destroy(sic_hdpa);
|
---|
726 | }
|
---|
727 |
|
---|
728 | sic_hdpa = NULL;
|
---|
729 |
|
---|
730 | LeaveCriticalSection(&SHELL32_SicCS);
|
---|
731 | }
|
---|
732 | /*************************************************************************
|
---|
733 | * Shell_GetImageList [SHELL32.71]
|
---|
734 | *
|
---|
735 | * PARAMETERS
|
---|
736 | * imglist[1|2] [OUT] pointer which recive imagelist handles
|
---|
737 | *
|
---|
738 | */
|
---|
739 |
|
---|
740 | ODINFUNCTION2(BOOL,Shell_GetImageList,HIMAGELIST*, lpBigList,
|
---|
741 | HIMAGELIST*, lpSmallList)
|
---|
742 | {
|
---|
743 | if (lpBigList)
|
---|
744 | { *lpBigList = ShellBigIconList;
|
---|
745 | }
|
---|
746 | if (lpSmallList)
|
---|
747 | { *lpSmallList = ShellSmallIconList;
|
---|
748 | }
|
---|
749 |
|
---|
750 | return TRUE;
|
---|
751 | }
|
---|
752 | /*************************************************************************
|
---|
753 | * PidlToSicIndex [INTERNAL]
|
---|
754 | *
|
---|
755 | * PARAMETERS
|
---|
756 | * sh [IN] IShellFolder
|
---|
757 | * pidl [IN]
|
---|
758 | * bBigIcon [IN]
|
---|
759 | * pIndex [OUT] index within the SIC
|
---|
760 | *
|
---|
761 | */
|
---|
762 | BOOL PidlToSicIndex (IShellFolder * sh, LPITEMIDLIST pidl, BOOL bBigIcon, UINT * pIndex)
|
---|
763 | {
|
---|
764 | IExtractIcon *ei;
|
---|
765 | char szIconFile[MAX_PATH]; /* file containing the icon */
|
---|
766 | INT iSourceIndex; /* index or resID(negated) in this file */
|
---|
767 | BOOL ret = FALSE;
|
---|
768 | UINT dwFlags = 0;
|
---|
769 |
|
---|
770 | dprintf(("SHELL32:Iconcache PidlToSicIndex sf=%p pidl=%p\n", sh, pidl));
|
---|
771 |
|
---|
772 | if (SUCCEEDED (IShellFolder_GetUIObjectOf(sh, 0, 1, &pidl, &IID_IExtractIconA, 0, (void **)&ei)))
|
---|
773 | {
|
---|
774 | if (NOERROR==IExtractIconA_GetIconLocation(ei, 0, szIconFile, MAX_PATH, &iSourceIndex, &dwFlags))
|
---|
775 | { *pIndex = SIC_GetIconIndex(szIconFile, iSourceIndex);
|
---|
776 | ret = TRUE;
|
---|
777 | }
|
---|
778 | IExtractIconA_Release(ei);
|
---|
779 | }
|
---|
780 |
|
---|
781 | if (INVALID_INDEX == *pIndex) /* default icon when failed */
|
---|
782 | *pIndex = 1;
|
---|
783 |
|
---|
784 | return ret;
|
---|
785 |
|
---|
786 | }
|
---|
787 |
|
---|
788 | /*************************************************************************
|
---|
789 | * SHMapPIDLToSystemImageListIndex [SHELL32.77]
|
---|
790 | *
|
---|
791 | * PARAMETERS
|
---|
792 | * sh [IN] pointer to an instance of IShellFolder
|
---|
793 | * pidl [IN]
|
---|
794 | * pIndex [OUT][OPTIONAL] SIC index for big icon
|
---|
795 | *
|
---|
796 | */
|
---|
797 |
|
---|
798 | ODINFUNCTION3(UINT,SHMapPIDLToSystemImageListIndex,LPSHELLFOLDER, sh,
|
---|
799 | LPITEMIDLIST, pidl,
|
---|
800 | UINT*, pIndex)
|
---|
801 | {
|
---|
802 | UINT Index;
|
---|
803 |
|
---|
804 | pdump(pidl);
|
---|
805 |
|
---|
806 | if (pIndex)
|
---|
807 | PidlToSicIndex ( sh, pidl, 1, pIndex);
|
---|
808 | PidlToSicIndex ( sh, pidl, 0, &Index);
|
---|
809 | return Index;
|
---|
810 | }
|
---|
811 |
|
---|
812 | /*************************************************************************
|
---|
813 | * Shell_GetCachedImageIndex [SHELL32.72]
|
---|
814 | *
|
---|
815 | */
|
---|
816 | ODINFUNCTION3(INT,Shell_GetCachedImageIndexA,LPCSTR,szPath,
|
---|
817 | INT, nIndex,
|
---|
818 | BOOL, bSimulateDoc)
|
---|
819 | {
|
---|
820 | dprintf(("(%s,%08x,%08x) semi-stub.\n",debugstr_a(szPath), nIndex, bSimulateDoc));
|
---|
821 | return SIC_GetIconIndex(szPath, nIndex);
|
---|
822 | }
|
---|
823 |
|
---|
824 | ODINFUNCTION3(INT,Shell_GetCachedImageIndexW,LPCWSTR, szPath,
|
---|
825 | INT, nIndex,
|
---|
826 | BOOL, bSimulateDoc)
|
---|
827 | { INT ret;
|
---|
828 | LPSTR sTemp = HEAP_strdupWtoA (GetProcessHeap(),0,szPath);
|
---|
829 |
|
---|
830 | dprintf(("(%s,%08x,%08x) semi-stub.\n",debugstr_w(szPath), nIndex, bSimulateDoc));
|
---|
831 |
|
---|
832 | ret = SIC_GetIconIndex(sTemp, nIndex);
|
---|
833 | HeapFree(GetProcessHeap(),0,sTemp);
|
---|
834 | return ret;
|
---|
835 | }
|
---|
836 |
|
---|
837 | ODINFUNCTION3(INT,Shell_GetCachedImageIndexAW,LPCVOID, szPath,
|
---|
838 | INT, nIndex,
|
---|
839 | BOOL, bSimulateDoc)
|
---|
840 | { if( VERSION_OsIsUnicode())
|
---|
841 | return Shell_GetCachedImageIndexW((LPWSTR)szPath, nIndex, bSimulateDoc);
|
---|
842 | return Shell_GetCachedImageIndexA((LPSTR)szPath, nIndex, bSimulateDoc);
|
---|
843 | }
|
---|
844 |
|
---|
845 | /*************************************************************************
|
---|
846 | * ExtracticonExAW [shell32.189]
|
---|
847 | */
|
---|
848 |
|
---|
849 | ODINFUNCTION5(HICON,ExtractIconExAW,LPCVOID, lpszFile,
|
---|
850 | INT, nIconIndex,
|
---|
851 | HICON*, phiconLarge,
|
---|
852 | HICON*, phiconSmall,
|
---|
853 | UINT, nIcons)
|
---|
854 | { if (VERSION_OsIsUnicode())
|
---|
855 | return ExtractIconExW ( (LPWSTR)lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
856 | return ExtractIconExA ( (LPSTR)lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
857 | }
|
---|
858 | /*************************************************************************
|
---|
859 | * ExtracticonExA [shell32.190]
|
---|
860 | * RETURNS
|
---|
861 | * 0 no icon found
|
---|
862 | * 1 file is not valid
|
---|
863 | * HICON handle of a icon (phiconLarge/Small == NULL)
|
---|
864 | */
|
---|
865 |
|
---|
866 | ODINFUNCTION5(HICON,ExtractIconExA, LPCSTR, lpszFile,
|
---|
867 | INT, nIconIndex,
|
---|
868 | HICON*, phiconLarge,
|
---|
869 | HICON*, phiconSmall,
|
---|
870 | UINT, nIcons)
|
---|
871 | { HICON ret=0;
|
---|
872 |
|
---|
873 | dprintf(("SHELL32:Iconcache file=%s idx=%i %p %p num=%i\n", lpszFile, nIconIndex, phiconLarge, phiconSmall, nIcons ));
|
---|
874 |
|
---|
875 | if (nIconIndex==-1) /* Number of icons requested */
|
---|
876 | return ICO_ExtractIconEx(lpszFile, NULL, -1, 0, 0, 0 );
|
---|
877 |
|
---|
878 |
|
---|
879 | if (phiconLarge)
|
---|
880 | { ret = ICO_ExtractIconEx(lpszFile, phiconLarge, nIconIndex, nIcons, 32, 32 );
|
---|
881 | if ( nIcons==1)
|
---|
882 | { ret = phiconLarge[0];
|
---|
883 | }
|
---|
884 | }
|
---|
885 |
|
---|
886 | /* if no pointers given and one icon expected, return the handle directly*/
|
---|
887 | if (!phiconLarge && ! phiconSmall && nIcons==1 )
|
---|
888 | phiconSmall = &ret;
|
---|
889 |
|
---|
890 | if (phiconSmall)
|
---|
891 | { ret = ICO_ExtractIconEx(lpszFile, phiconSmall, nIconIndex, nIcons, 16, 16 );
|
---|
892 | if ( nIcons==1 )
|
---|
893 | { ret = phiconSmall[0];
|
---|
894 | }
|
---|
895 | }
|
---|
896 |
|
---|
897 | return ret;
|
---|
898 | }
|
---|
899 | /*************************************************************************
|
---|
900 | * ExtracticonExW [shell32.191]
|
---|
901 | */
|
---|
902 | ODINFUNCTION5(HICON,ExtractIconExW,LPCWSTR, lpszFile,
|
---|
903 | INT, nIconIndex,
|
---|
904 | HICON*, phiconLarge,
|
---|
905 | HICON*, phiconSmall,
|
---|
906 | UINT, nIcons)
|
---|
907 | { LPSTR sFile;
|
---|
908 | DWORD ret;
|
---|
909 |
|
---|
910 | dprintf(("SHELL32:Iconcache file=%s idx=%i %p %p num=%i\n", debugstr_w(lpszFile), nIconIndex, phiconLarge, phiconSmall, nIcons ));
|
---|
911 |
|
---|
912 | sFile = HEAP_strdupWtoA (GetProcessHeap(),0,lpszFile);
|
---|
913 | ret = ExtractIconExA ( sFile, nIconIndex, phiconLarge, phiconSmall, nIcons);
|
---|
914 | HeapFree(GetProcessHeap(),0,sFile);
|
---|
915 | return ret;
|
---|
916 | }
|
---|
917 |
|
---|
918 | /*
|
---|
919 | * PE (Portable Execute) File Resources
|
---|
920 | *
|
---|
921 | * Copyright 1995 Thomas Sandford
|
---|
922 | * Copyright 1996 Martin von Loewis
|
---|
923 | *
|
---|
924 | * Based on the Win16 resource handling code in loader/resource.c
|
---|
925 | * Copyright 1993 Robert J. Amstadt
|
---|
926 | * Copyright 1995 Alexandre Julliard
|
---|
927 | * Copyright 1997 Marcus Meissner
|
---|
928 | */
|
---|
929 |
|
---|
930 | //CB: from loader/pe_resource.c
|
---|
931 |
|
---|
932 | /**********************************************************************
|
---|
933 | * GetResDirEntryW
|
---|
934 | *
|
---|
935 | * Helper function - goes down one level of PE resource tree
|
---|
936 | *
|
---|
937 | */
|
---|
938 | PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
|
---|
939 | LPCWSTR name,DWORD root,
|
---|
940 | BOOL allowdefault)
|
---|
941 | {
|
---|
942 | int entrynum;
|
---|
943 | PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
|
---|
944 | int namelen;
|
---|
945 |
|
---|
946 | if (HIWORD(name)) {
|
---|
947 | if (name[0]=='#') {
|
---|
948 | char buf[10];
|
---|
949 |
|
---|
950 | lstrcpynWtoA(buf,name+1,10);
|
---|
951 | return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
|
---|
952 | }
|
---|
953 | entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
---|
954 | (BYTE *) resdirptr +
|
---|
955 | sizeof(IMAGE_RESOURCE_DIRECTORY));
|
---|
956 | namelen = lstrlenW(name);
|
---|
957 | for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
|
---|
958 | {
|
---|
959 | PIMAGE_RESOURCE_DIR_STRING_U str =
|
---|
960 | (PIMAGE_RESOURCE_DIR_STRING_U) (root +
|
---|
961 | entryTable[entrynum].u1.s.NameOffset);
|
---|
962 | if(namelen != str->Length)
|
---|
963 | continue;
|
---|
964 | if(lstrncmpiW(name,str->NameString,str->Length)==0)
|
---|
965 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
---|
966 | root +
|
---|
967 | entryTable[entrynum].u2.s.OffsetToDirectory);
|
---|
968 | }
|
---|
969 | return NULL;
|
---|
970 | } else {
|
---|
971 | entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
|
---|
972 | (BYTE *) resdirptr +
|
---|
973 | sizeof(IMAGE_RESOURCE_DIRECTORY) +
|
---|
974 | resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
|
---|
975 | for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
|
---|
976 | if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
|
---|
977 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
---|
978 | root +
|
---|
979 | entryTable[entrynum].u2.s.OffsetToDirectory);
|
---|
980 | /* just use first entry if no default can be found */
|
---|
981 | if (allowdefault && !name && resdirptr->NumberOfIdEntries)
|
---|
982 | return (PIMAGE_RESOURCE_DIRECTORY) (
|
---|
983 | root +
|
---|
984 | entryTable[0].u2.s.OffsetToDirectory);
|
---|
985 | return NULL;
|
---|
986 | }
|
---|
987 | }
|
---|
988 |
|
---|