source: trunk/src/shell32/shell32_odin.cpp@ 5120

Last change on this file since 5120 was 4544, checked in by sandervl, 25 years ago

print build in About Odin dialog (ShellAbout)

File size: 38.5 KB
Line 
1/* $Id: shell32_odin.cpp,v 1.2 2000-10-28 14:36:48 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 basics
10 *
11 * 1998 Marcus Meissner
12 * 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
13 *
14 */
15
16/*****************************************************************************
17 * Includes *
18 *****************************************************************************/
19
20#include <odin.h>
21#include <odinwrap.h>
22#include <os2sel.h>
23
24#include <stdlib.h>
25#include <string.h>
26
27#define ICOM_CINTERFACE 1
28#define CINTERFACE 1
29
30#include "winerror.h"
31#include "heap.h"
32#include "resource.h"
33#include "dlgs.h"
34#include "sysmetrics.h"
35#include "debugtools.h"
36#include "winreg.h"
37#include "authors.h"
38#include "winversion.h"
39
40#include "shellapi.h"
41#include "pidl.h"
42
43#include "shlobj.h"
44#include "shell32_main.h"
45#include "shlguid.h"
46#include "wine/undocshell.h"
47#include "shpolicy.h"
48#include "shlwapi.h"
49
50#include <heapstring.h>
51#include <misc.h>
52#include <peexe.h>
53#include <neexe.h>
54#include <cursoricon.h>
55#include <ctype.h>
56#include <module.h>
57
58/*****************************************************************************
59 * Local Variables *
60 *****************************************************************************/
61
62ODINDEBUGCHANNEL(SHELL32-MAIN)
63
64typedef struct
65{ LPCSTR szApp;
66 LPCSTR szOtherStuff;
67 HICON hIcon;
68} ABOUT_INFO;
69
70#define IDC_STATIC_TEXT 100
71#define IDC_LISTBOX 99
72#define IDC_WINE_TEXT 98
73#define IDC_ODIN_TEXT 98
74
75#define DROP_FIELD_TOP (-15)
76#define DROP_FIELD_HEIGHT 15
77
78extern HICON hIconTitleFont;
79
80static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
81{ HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
82 if( hWndCtl )
83 { GetWindowRect( hWndCtl, lprect );
84 MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
85 lprect->bottom = (lprect->top += DROP_FIELD_TOP);
86 return TRUE;
87 }
88 return FALSE;
89}
90
91
92/*************************************************************************
93 * AboutDlgProc32 (internal)
94 */
95#define IDC_ODINLOGO 2001
96#define IDC_ODINBUILDNR 2002
97#define IDB_ODINLOGO 5555
98
99BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
100 LPARAM lParam )
101{
102 HWND hWndCtl;
103 char Template[512], AppTitle[512];
104
105 switch(msg)
106 {
107 case WM_INITDIALOG:
108 {
109 ABOUT_INFO *info = (ABOUT_INFO *)lParam;
110 if(info)
111 {
112 const char* const *pstr = SHELL_People;
113
114 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,info->hIcon, 0);
115 GetWindowTextA( hWnd, Template, sizeof(Template) );
116 sprintf( AppTitle, Template, info->szApp );
117 SetWindowTextA( hWnd, AppTitle );
118 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), info->szOtherStuff );
119
120 sprintf( AppTitle, "(%s)", __DATE__);
121 SetWindowTextA( GetDlgItem(hWnd, IDC_ODINBUILDNR), AppTitle);
122 HWND hwndOdinLogo = GetDlgItem(hWnd, IDC_ODINLOGO);
123 if(hwndOdinLogo) {
124 HBITMAP hBitmap = LoadBitmapA(shell32_hInstance, MAKEINTRESOURCEA(IDB_ODINLOGO));
125 SendMessageA(hwndOdinLogo, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
126 }
127
128 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
129 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
130#if 0 //CB: not used (hIconTitleFont not valid!!!), default font is ok
131 SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
132#endif
133 while (*pstr)
134 {
135 SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
136 pstr++;
137 }
138 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
139 }
140 return 1;
141 }
142
143 case WM_PAINT:
144 {
145 RECT rect;
146 PAINTSTRUCT ps;
147 HDC hDC = BeginPaint( hWnd, &ps );
148
149 if( __get_dropline( hWnd, &rect ) ) {
150 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
151 MoveToEx( hDC, rect.left, rect.top, NULL );
152 LineTo( hDC, rect.right, rect.bottom );
153 }
154 EndPaint( hWnd, &ps );
155 break;
156 }
157
158 case WM_LBTRACKPOINT:
159 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
160 if( (INT)GetKeyState( VK_CONTROL ) < 0 )
161 { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
162 { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
163 if( idx != -1 )
164 { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
165 HGLOBAL hMemObj = GlobalAlloc( GMEM_MOVEABLE, length + 1 );
166 char* pstr = (char*)GlobalLock( hMemObj );
167
168 if( pstr )
169 { HCURSOR hCursor = LoadCursorA( 0, (LPCSTR)OCR_DRAGOBJECT );
170 SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
171 SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
172 UpdateWindow( hWndCtl );
173
174 if( !DragObject(hWnd, hWnd, DRAGOBJ_DATA, hMemObj, hCursor) )
175 SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
176 }
177 if( hMemObj )
178 GlobalFree( hMemObj );
179 }
180 }
181 }
182 break;
183
184 case WM_QUERYDROPOBJECT:
185 if( wParam == 0 )
186 { LPDRAGINFO lpDragInfo = (LPDRAGINFO)lParam;
187 if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
188 { RECT rect;
189 if( __get_dropline( hWnd, &rect ) )
190 { POINT pt;
191 pt.x=lpDragInfo->pt.x;
192 pt.x=lpDragInfo->pt.y;
193 rect.bottom += DROP_FIELD_HEIGHT;
194 if( PtInRect( &rect, pt ) )
195 { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
196 return TRUE;
197 }
198 }
199 }
200 }
201 break;
202
203 case WM_DROPOBJECT:
204 if( wParam == hWnd )
205 { LPDRAGINFO lpDragInfo = (LPDRAGINFO)lParam;
206 if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
207 { char* pstr = (char*)GlobalLock( (HGLOBAL)(lpDragInfo->hList) );
208 if( pstr )
209 { static char __appendix_str[] = " with";
210
211 hWndCtl = GetDlgItem( hWnd, IDC_ODIN_TEXT );
212 SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
213 if( !strncmp( Template, "ODIN", 4 ) )
214 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
215 else
216 { char* pch = Template + strlen(Template) - strlen(__appendix_str);
217 *pch = '\0';
218 SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING,
219 (WPARAM)-1, (LPARAM)Template );
220 }
221
222 strcpy( Template, pstr );
223 strcat( Template, __appendix_str );
224 SetWindowTextA( hWndCtl, Template );
225 SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
226 return TRUE;
227 }
228 }
229 }
230 break;
231
232 case WM_COMMAND:
233 if (wParam == IDOK)
234 {
235 EndDialog(hWnd, TRUE);
236 return TRUE;
237 }
238 break;
239
240 case WM_CLOSE:
241 EndDialog(hWnd, TRUE);
242 break;
243 }
244 return 0;
245}
246
247
248/*************************************************************************
249 * ShellAboutA [SHELL32.243]
250 */
251
252ODINFUNCTION4(BOOL,ShellAboutA, HWND, hWnd,
253 LPCSTR, szApp,
254 LPCSTR, szOtherStuff,
255 HICON, hIcon )
256{ ABOUT_INFO info;
257 HRSRC hRes;
258 LPVOID dlgTemplate;
259
260 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
261 return FALSE;
262 if(!(dlgTemplate = (LPVOID)LoadResource(shell32_hInstance, hRes)))
263 return FALSE;
264
265 info.szApp = szApp;
266 info.szOtherStuff = szOtherStuff;
267 info.hIcon = hIcon;
268 if (!hIcon) info.hIcon = LoadIconA( 0, MAKEINTRESOURCEA(OIC_ODINICON) );
269 return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
270 (DLGTEMPLATE*)dlgTemplate , hWnd, AboutDlgProc, (LPARAM)&info );
271}
272
273
274/*************************************************************************
275 * ShellAboutW [SHELL32.244]
276 */
277ODINFUNCTION4(BOOL,ShellAboutW, HWND, hWnd,
278 LPCWSTR, szApp,
279 LPCWSTR, szOtherStuff,
280 HICON, hIcon )
281{ INT ret;
282 ABOUT_INFO info;
283 HRSRC hRes;
284 LPVOID dlgTemplate;
285
286 if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
287 return FALSE;
288 if(!(dlgTemplate = (LPVOID)LoadResource(shell32_hInstance, hRes)))
289 return FALSE;
290
291 info.szApp = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
292 info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
293 info.hIcon = hIcon;
294 if (!hIcon) info.hIcon = LoadIconA( 0, MAKEINTRESOURCEA(OIC_ODINICON) );
295 ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
296 (DLGTEMPLATE*)dlgTemplate, hWnd, AboutDlgProc, (LPARAM)&info );
297 HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
298 HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
299 return ret;
300}
301
302/*************************************************************************
303 * ExtractAssociatedIcon [SHELL.36]
304 *
305 * Return icon for given file (either from file itself or from associated
306 * executable) and patch parameters if needed.
307 */
308ODINFUNCTION3(HICON, ExtractAssociatedIconA,
309 HINSTANCE, hInst,
310 LPSTR, lpIconPath,
311 LPWORD, lpiIcon)
312{
313 HICON hIcon;
314
315 hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon);
316
317 if( hIcon < 2 )
318 { if( hIcon == 1 ) /* no icons found in given file */
319 { char tempPath[0x104];
320 UINT uRet = FindExecutableA(lpIconPath,NULL,tempPath);
321
322 if( uRet > 32 && tempPath[0] )
323 { strcpy(lpIconPath,tempPath);
324 hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon);
325 if( hIcon > 2 )
326 return hIcon;
327 }
328 else hIcon = 0;
329 }
330
331 if( hIcon == 1 )
332 *lpiIcon = 2; /* MSDOS icon - we found .exe but no icons in it */
333 else
334 *lpiIcon = 6; /* generic icon - found nothing */
335
336 GetModuleFileNameA(hInst, lpIconPath, 0x80);
337 hIcon = LoadIconA( hInst, (LPCSTR)*lpiIcon);
338 }
339 return hIcon;
340}
341
342#if 0 //CB: DirectResAlloc16 not yet ported
343/*************************************************************************
344 * SHELL_LoadResource
345 */
346static HGLOBAL SHELL_LoadResource(HINSTANCE hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift)
347{ BYTE* ptr;
348 HGLOBAL handle = DirectResAlloc( hInst, 0x10, (DWORD)pNInfo->length << sizeShift);
349
350 TRACE("\n");
351
352 if( (ptr = (BYTE*)GlobalLock( handle )) )
353 { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
354 _lread( hFile, (char*)ptr, pNInfo->length << sizeShift);
355 return handle;
356 }
357 return 0;
358}
359
360/*************************************************************************
361 * ICO_LoadIcon
362 */
363static HGLOBAL ICO_LoadIcon(HINSTANCE hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE)
364{ BYTE* ptr;
365 HGLOBAL handle = DirectResAlloc( hInst, 0x10, lpiIDE->dwBytesInRes);
366 TRACE("\n");
367 if( (ptr = (BYTE*)GlobalLock( handle )) )
368 { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
369 _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
370 return handle;
371 }
372 return 0;
373}
374
375/*************************************************************************
376 * ICO_GetIconDirectory
377 *
378 * Read .ico file and build phony ICONDIR struct for GetIconID
379 */
380static HGLOBAL ICO_GetIconDirectory(HINSTANCE hInst, HFILE hFile, LPicoICONDIR* lplpiID )
381{ WORD id[3]; /* idReserved, idType, idCount */
382 LPicoICONDIR lpiID;
383 int i;
384
385 TRACE("\n");
386 _llseek( hFile, 0, SEEK_SET );
387 if( _lread(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0;
388
389 /* check .ICO header
390 *
391 * - see http://www.microsoft.com/win32dev/ui/icons.htm
392 */
393
394 if( id[0] || id[1] != 1 || !id[2] ) return 0;
395
396 i = id[2]*sizeof(icoICONDIRENTRY) ;
397
398 lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i + sizeof(id));
399
400 if( _lread(hFile,(char*)lpiID->idEntries,i) == i )
401 { HGLOBAL handle = DirectResAlloc( hInst, 0x10,
402 id[2]*sizeof(CURSORICONDIRENTRY) + sizeof(id) );
403 if( handle )
404 { CURSORICONDIR* lpID = (CURSORICONDIR*)GlobalLock( handle );
405 lpID->idReserved = lpiID->idReserved = id[0];
406 lpID->idType = lpiID->idType = id[1];
407 lpID->idCount = lpiID->idCount = id[2];
408 for( i=0; i < lpiID->idCount; i++ )
409 { memcpy((void*)(lpID->idEntries + i),
410 (void*)(lpiID->idEntries + i), sizeof(CURSORICONDIRENTRY) - 2);
411 lpID->idEntries[i].wResId = i;
412 }
413 *lplpiID = lpiID;
414 return handle;
415 }
416 }
417 /* fail */
418
419 HeapFree( GetProcessHeap(), 0, lpiID);
420 return 0;
421}
422#endif
423
424//iconcache.c
425DWORD SHELL_GetResourceTable(HFILE hFile, LPBYTE *retptr);
426
427//CB: from loader/pe_resource.c
428
429/**********************************************************************
430 * GetResDirEntryW
431 *
432 * Helper function - goes down one level of PE resource tree
433 *
434 */
435PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
436 LPCWSTR name,DWORD root,
437 BOOL allowdefault)
438{
439 int entrynum;
440 PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
441 int namelen;
442
443 if (HIWORD(name)) {
444 if (name[0]=='#') {
445 char buf[10];
446
447 lstrcpynWtoA(buf,name+1,10);
448 return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
449 }
450 entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
451 (BYTE *) resdirptr +
452 sizeof(IMAGE_RESOURCE_DIRECTORY));
453 namelen = lstrlenW(name);
454 for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
455 {
456 PIMAGE_RESOURCE_DIR_STRING_U str =
457 (PIMAGE_RESOURCE_DIR_STRING_U) (root +
458 entryTable[entrynum].u1.s.NameOffset);
459 if(namelen != str->Length)
460 continue;
461 if(lstrncmpiW(name,str->NameString,str->Length)==0)
462 return (PIMAGE_RESOURCE_DIRECTORY) (
463 root +
464 entryTable[entrynum].u2.s.OffsetToDirectory);
465 }
466 return NULL;
467 } else {
468 entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
469 (BYTE *) resdirptr +
470 sizeof(IMAGE_RESOURCE_DIRECTORY) +
471 resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
472 for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
473 if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
474 return (PIMAGE_RESOURCE_DIRECTORY) (
475 root +
476 entryTable[entrynum].u2.s.OffsetToDirectory);
477 /* just use first entry if no default can be found */
478 if (allowdefault && !name && resdirptr->NumberOfIdEntries)
479 return (PIMAGE_RESOURCE_DIRECTORY) (
480 root +
481 entryTable[0].u2.s.OffsetToDirectory);
482 return NULL;
483 }
484}
485
486/*************************************************************************
487 * InternalExtractIcon [SHELL.39]
488 *
489 * This abortion is called directly by Progman
490 */
491HGLOBAL WINAPI InternalExtractIcon(HINSTANCE hInstance,
492 LPCSTR lpszExeFileName, UINT nIconIndex, WORD n )
493{ HGLOBAL hRet = 0;
494 HGLOBAL* RetPtr = NULL;
495 LPBYTE pData;
496 OFSTRUCT ofs;
497 DWORD sig;
498 HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
499 UINT iconDirCount = 0,iconCount = 0;
500 LPBYTE peimage;
501 HANDLE fmapping;
502
503 TRACE("(%04x,file %s,start %d,extract %d\n",
504 hInstance, lpszExeFileName, nIconIndex, n);
505
506 if( hFile == HFILE_ERROR || !n )
507 return 0;
508
509 hRet = GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n);
510 RetPtr = (HGLOBAL*)GlobalLock(hRet);
511
512 *RetPtr = (n == 0xFFFF)? 0: 1; /* error return values */
513
514 sig = SHELL_GetResourceTable(hFile,&pData);
515#if 0 //CB: some functions not (yet) supported
516 if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
517 { HICON hIcon = 0;
518 NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2);
519 NE_NAMEINFO* pIconStorage = NULL;
520 NE_NAMEINFO* pIconDir = NULL;
521 LPicoICONDIR lpiID = NULL;
522
523 if( pData == (BYTE*)-1 )
524 { hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID); /* check for .ICO file */
525 if( hIcon )
526 { iconDirCount = 1; iconCount = lpiID->idCount;
527 }
528 }
529 else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
530 { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON ) /* find icon directory and icon repository */
531 { iconDirCount = pTInfo->count;
532 pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
533 TRACE("\tfound directory - %i icon families\n", iconDirCount);
534 }
535 if( pTInfo->type_id == NE_RSCTYPE_ICON )
536 { iconCount = pTInfo->count;
537 pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
538 TRACE("\ttotal icons - %i\n", iconCount);
539 }
540 pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
541 }
542
543 /* load resources and create icons */
544
545 if( (pIconStorage && pIconDir) || lpiID )
546 { if( nIconIndex == (UINT16)-1 )
547 { RetPtr[0] = iconDirCount;
548 }
549 else if( nIconIndex < iconDirCount )
550 { UINT i, icon;
551 if( n > iconDirCount - nIconIndex )
552 n = iconDirCount - nIconIndex;
553
554 for( i = nIconIndex; i < nIconIndex + n; i++ )
555 { /* .ICO files have only one icon directory */
556
557 if( lpiID == NULL )
558 hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i, *(WORD*)pData );
559 RetPtr[i-nIconIndex] = GetIconID( hIcon, 3 );
560 GlobalFree(hIcon);
561 }
562
563 for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
564 { hIcon = 0;
565 if( lpiID )
566 { hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]);
567 }
568 else
569 { for( i = 0; i < iconCount; i++ )
570 { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
571 { hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,*(WORD*)pData );
572 }
573 }
574 }
575 if( hIcon )
576 { RetPtr[icon-nIconIndex] = LoadIconHandler16( hIcon, TRUE );
577 FarSetOwner16( RetPtr[icon-nIconIndex], GetExePtr(hInstance) );
578 }
579 else
580 { RetPtr[icon-nIconIndex] = 0;
581 }
582 }
583 }
584 }
585 if( lpiID )
586 HeapFree( GetProcessHeap(), 0, lpiID);
587 else
588 HeapFree( GetProcessHeap(), 0, pData);
589 }
590#endif
591 if( sig == IMAGE_NT_SIGNATURE)
592 { LPBYTE idata,igdata;
593 PIMAGE_DOS_HEADER dheader;
594 PIMAGE_NT_HEADERS pe_header;
595 PIMAGE_SECTION_HEADER pe_sections;
596 PIMAGE_RESOURCE_DIRECTORY rootresdir,iconresdir,icongroupresdir;
597 PIMAGE_RESOURCE_DATA_ENTRY idataent,igdataent;
598 int i,j;
599 PIMAGE_RESOURCE_DIRECTORY_ENTRY xresent;
600 CURSORICONDIR **cids;
601
602 fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL);
603 if (fmapping == 0)
604 { /* FIXME, INVALID_HANDLE_VALUE? */
605 WARN("failed to create filemap.\n");
606 hRet = 0;
607 goto end_2; /* failure */
608 }
609 peimage = (BYTE*)MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0);
610 if (!peimage)
611 { WARN("failed to mmap filemap.\n");
612 hRet = 0;
613 goto end_2; /* failure */
614 }
615 dheader = (PIMAGE_DOS_HEADER)peimage;
616
617 /* it is a pe header, SHELL_GetResourceTable checked that */
618 pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew);
619
620 /* probably makes problems with short PE headers... but I haven't seen
621 * one yet...
622 */
623 pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header));
624 rootresdir = NULL;
625
626 for (i=0;i<pe_header->FileHeader.NumberOfSections;i++)
627 { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
628 continue;
629 /* FIXME: doesn't work when the resources are not in a seperate section */
630 if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress)
631 { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
632 break;
633 }
634 }
635
636 if (!rootresdir)
637 { WARN("haven't found section for resource directory.\n");
638 goto end_4; /* failure */
639 }
640
641 icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE);
642
643 if (!icongroupresdir)
644 { WARN("No Icongroupresourcedirectory!\n");
645 goto end_4; /* failure */
646 }
647
648 iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
649
650 if( nIconIndex == (UINT)-1 )
651 { RetPtr[0] = iconDirCount;
652 goto end_3; /* success */
653 }
654
655 if (nIconIndex >= iconDirCount)
656 { WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
657 GlobalFree(hRet);
658 goto end_4; /* failure */
659 }
660
661 cids = (CURSORICONDIR**)HeapAlloc(GetProcessHeap(),0,n*sizeof(CURSORICONDIR*));
662
663 /* caller just wanted the number of entries */
664 xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
665
666 /* assure we don't get too much ... */
667 if( n > iconDirCount - nIconIndex )
668 { n = iconDirCount - nIconIndex;
669 }
670
671 /* starting from specified index ... */
672 xresent = xresent+nIconIndex;
673
674 for (i=0;i<n;i++,xresent++)
675 { CURSORICONDIR *cid;
676 PIMAGE_RESOURCE_DIRECTORY resdir;
677
678 /* go down this resource entry, name */
679 resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
680
681 /* default language (0) */
682 resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
683 igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
684
685 /* lookup address in mapped image for virtual address */
686 igdata = NULL;
687
688 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
689 { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
690 continue;
691 if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
692 continue;
693 igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
694 }
695
696 if (!igdata)
697 { WARN("no matching real address for icongroup!\n");
698 goto end_4; /* failure */
699 }
700 /* found */
701 cid = (CURSORICONDIR*)igdata;
702 cids[i] = cid;
703 RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
704 }
705
706 iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE);
707
708 if (!iconresdir)
709 { WARN("No Iconresourcedirectory!\n");
710 goto end_4; /* failure */
711 }
712
713 for (i=0;i<n;i++)
714 { PIMAGE_RESOURCE_DIRECTORY xresdir;
715 xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
716 xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
717 idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
718 idata = NULL;
719
720 /* map virtual to address in image */
721 for (j=0;j<pe_header->FileHeader.NumberOfSections;j++)
722 { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
723 continue;
724 if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
725 continue;
726 idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
727 }
728 if (!idata)
729 { WARN("no matching real address found for icondata!\n");
730 RetPtr[i]=0;
731 continue;
732 }
733 RetPtr[i] = CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
734 }
735 goto end_3; /* sucess */
736 }
737 goto end_1; /* return array with icon handles */
738
739/* cleaning up (try & catch would be nicer) */
740end_4: hRet = 0; /* failure */
741end_3: UnmapViewOfFile(peimage); /* success */
742end_2: CloseHandle(fmapping);
743end_1: _lclose( hFile);
744 return hRet;
745}
746
747/*************************************************************************
748 * SHELL_GetResourceTable
749 */
750DWORD SHELL_GetResourceTable(HFILE hFile,LPBYTE *retptr)
751{ IMAGE_DOS_HEADER mz_header;
752 char magic[4];
753 int size;
754
755 TRACE("\n");
756
757 *retptr = NULL;
758 _llseek( hFile, 0, SEEK_SET );
759 if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
760 { /* .ICO file ? */
761 if (mz_header.e_cblp == 1)
762 { /* ICONHEADER.idType, must be 1 */
763 *retptr = (LPBYTE)-1;
764 return 1;
765 }
766 else
767 return 0; /* failed */
768 }
769 _llseek( hFile, mz_header.e_lfanew, SEEK_SET );
770
771 if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic))
772 return 0;
773
774 _llseek( hFile, mz_header.e_lfanew, SEEK_SET);
775
776 if (*(DWORD*)magic == IMAGE_NT_SIGNATURE)
777 return IMAGE_NT_SIGNATURE;
778
779 if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
780 { IMAGE_OS2_HEADER ne_header;
781 LPBYTE pTypeInfo = (LPBYTE)-1;
782
783 if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
784 return 0;
785
786 if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
787 return 0;
788
789 size = ne_header.ne_restab - ne_header.ne_rsrctab;
790
791 if( size > sizeof(NE_TYPEINFO) )
792 { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
793 if( pTypeInfo )
794 { _llseek(hFile, mz_header.e_lfanew+ne_header.ne_rsrctab, SEEK_SET);
795 if( _lread( hFile, (char*)pTypeInfo, size) != size )
796 { HeapFree( GetProcessHeap(), 0, pTypeInfo);
797 pTypeInfo = NULL;
798 }
799 }
800 }
801 *retptr = pTypeInfo;
802 return IMAGE_OS2_SIGNATURE;
803 }
804 return 0; /* failed */
805}
806
807/*************************************************************************
808 * SHELL_FindExecutable [Internal]
809 *
810 * Utility for code sharing between FindExecutable and ShellExecute
811 */
812HINSTANCE SHELL_FindExecutable( LPCSTR lpFile,
813 LPCSTR lpOperation,
814 LPSTR lpResult)
815{ char *extension = NULL; /* pointer to file extension */
816 char tmpext[5]; /* local copy to mung as we please */
817 char filetype[256]; /* registry name for this filetype */
818 LONG filetypelen=256; /* length of above */
819 char command[256]; /* command from registry */
820 LONG commandlen=256; /* This is the most DOS can handle :) */
821 char buffer[256]; /* Used to GetProfileString */
822 HINSTANCE retval=31; /* default - 'No association was found' */
823 char *tok; /* token pointer */
824 int i; /* random counter */
825 char xlpFile[256]; /* result of SearchPath */
826
827 dprintf(("SHELL32:SHELL:SHELL_FindExecutable(%s,%s,%08xh)\n",
828 lpFile,
829 lpOperation,
830 lpResult));
831
832 lpResult[0]='\0'; /* Start off with an empty return string */
833
834 /* trap NULL parameters on entry */
835 if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL ))
836 { dprintf(("SHELL32:SHELL:SHELL_FindExecutable(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
837 lpFile, lpOperation, lpResult));
838 return 2; /* File not found. Close enough, I guess. */
839 }
840
841 if (SearchPathA( NULL, lpFile,".exe",sizeof(xlpFile),xlpFile,NULL))
842 { dprintf(("SHELL32:SHELL:SHELL_FindExecutable(SearchPath32A returned non-zero\n"));
843 lpFile = xlpFile;
844 }
845
846 /* First thing we need is the file's extension */
847 extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */
848 /* File->Run in progman uses */
849 /* .\FILE.EXE :( */
850 dprintf(("SHELL32:SHELL:SHELL_FindExecutable(xlpFile=%s,extension=%s)\n",
851 xlpFile, extension));
852
853 if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
854 { dprintf(("SHELL32:SHELL:SHELL_FindExecutable Returning 31 - No association\n"));
855 return 31; /* no association */
856 }
857
858 /* Make local copy & lowercase it for reg & 'programs=' lookup */
859 lstrcpynA( tmpext, extension, 5 );
860 CharLowerA( tmpext );
861
862
863 dprintf(("SHELL32:SHELL:SHELL_FindExecutable(%s file)\n", tmpext));
864
865 /* Three places to check: */
866 /* 1. win.ini, [windows], programs (NB no leading '.') */
867 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
868 /* 3. win.ini, [extensions], extension (NB no leading '.' */
869 /* All I know of the order is that registry is checked before */
870 /* extensions; however, it'd make sense to check the programs */
871 /* section first, so that's what happens here. */
872
873 /* See if it's a program - if GetProfileString fails, we skip this
874 * section. Actually, if GetProfileString fails, we've probably
875 * got a lot more to worry about than running a program... */
876 if ( GetProfileStringA("windows", "programs", "exe pif bat com",
877 buffer, sizeof(buffer)) > 0 )
878 { for (i=0;i<strlen(buffer); i++) buffer[i]=tolower(buffer[i]);
879
880 tok = strtok(buffer, " \t"); /* ? */
881 while( tok!= NULL)
882 {
883 if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */
884 {
885 strcpy(lpResult, xlpFile);
886 /* Need to perhaps check that the file has a path
887 * attached */
888 dprintf(("SHELL32:SHELL:SHELL_FindExecutable found %s\n",
889 lpResult));
890 return 33;
891
892 /* Greater than 32 to indicate success FIXME According to the
893 * docs, I should be returning a handle for the
894 * executable. Does this mean I'm supposed to open the
895 * executable file or something? More RTFM, I guess... */
896 }
897 tok=strtok(NULL, " \t");
898 }
899 }
900
901 /* Check registry */
902 if (RegQueryValueA( HKEY_CLASSES_ROOT, tmpext, filetype,
903 &filetypelen ) == ERROR_SUCCESS )
904 {
905 filetype[filetypelen]='\0';
906 dprintf(("SHELL32:SHELL:SHELL_FindExecutable(File type: %s)\n",
907 filetype));
908
909 /* Looking for ...buffer\shell\lpOperation\command */
910 strcat( filetype, "\\shell\\" );
911 strcat( filetype, lpOperation );
912 strcat( filetype, "\\command" );
913
914 if (RegQueryValueA( HKEY_CLASSES_ROOT, filetype, command,
915 &commandlen ) == ERROR_SUCCESS )
916 {
917 LPSTR tmp;
918 char param[256];
919 LONG paramlen = 256;
920
921 /* Get the parameters needed by the application
922 from the associated ddeexec key */
923 tmp = strstr(filetype,"command");
924 tmp[0] = '\0';
925 strcat(filetype,"ddeexec");
926
927 if(RegQueryValueA( HKEY_CLASSES_ROOT, filetype, param,&paramlen ) == ERROR_SUCCESS)
928 {
929 strcat(command," ");
930 strcat(command,param);
931 commandlen += paramlen;
932 }
933
934 /* Is there a replace() function anywhere? */
935 command[commandlen]='\0';
936 strcpy( lpResult, command );
937 tok=strstr( lpResult, "%1" );
938 if (tok != NULL)
939 {
940 tok[0]='\0'; /* truncate string at the percent */
941 strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
942 tok=strstr( command, "%1" );
943 if ((tok!=NULL) && (strlen(tok)>2))
944 {
945 strcat( lpResult, &tok[2] );
946 }
947 }
948 retval=33; /* FIXME see above */
949 }
950 }
951 else /* Check win.ini */
952 {
953 /* Toss the leading dot */
954 extension++;
955 if ( GetProfileStringA( "extensions", extension, "", command,
956 sizeof(command)) > 0)
957 {
958 if (strlen(command)!=0)
959 {
960 strcpy( lpResult, command );
961 tok=strstr( lpResult, "^" ); /* should be ^.extension? */
962 if (tok != NULL)
963 {
964 tok[0]='\0';
965 strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
966 tok=strstr( command, "^" ); /* see above */
967 if ((tok != NULL) && (strlen(tok)>5))
968 {
969 strcat( lpResult, &tok[5]);
970 }
971 }
972 retval=33; /* FIXME - see above */
973 }
974 }
975 }
976
977 dprintf(("SHELL32:SHELL:SHELL_FindExecutable (returning %s)\n", lpResult));
978 return retval;
979}
980
981/*************************************************************************
982 * ShellExecuteA [SHELL32.245]
983 */
984
985ODINFUNCTION6(HINSTANCE, ShellExecuteA, HWND, hWnd,
986 LPCSTR, lpOperation,
987 LPCSTR, lpFile,
988 LPCSTR, lpParameters,
989 LPCSTR, lpDirectory,
990 INT, iShowCmd )
991{ HINSTANCE retval=31;
992 char old_dir[1024];
993 char cmd[256];
994
995 if (lpFile==NULL) return 0; /* should not happen */
996 if (lpOperation==NULL) /* default is open */
997 lpOperation="open";
998
999 if (lpDirectory)
1000 { GetCurrentDirectoryA( sizeof(old_dir), old_dir );
1001 SetCurrentDirectoryA( lpDirectory );
1002 }
1003
1004 cmd[0] = '\0';
1005 retval = SHELL_FindExecutable( lpFile, lpOperation, cmd );
1006
1007 if (retval > 32) /* Found */
1008 {
1009 if (lpParameters)
1010 {
1011 strcat(cmd," ");
1012 strcat(cmd,lpParameters);
1013 }
1014
1015 dprintf(("starting %s\n",cmd));
1016 retval = WinExec( cmd, iShowCmd );
1017 }
1018 else if(PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */
1019 {
1020 char lpstrProtocol[256];
1021 LONG cmdlen = 512;
1022 LPSTR lpstrRes;
1023 INT iSize;
1024
1025 lpstrRes = strchr(lpFile,':');
1026 iSize = lpstrRes - lpFile;
1027
1028 /* Looking for ...protocol\shell\lpOperation\command */
1029 strncpy(lpstrProtocol,lpFile,iSize);
1030 lpstrProtocol[iSize]='\0';
1031 strcat( lpstrProtocol, "\\shell\\" );
1032 strcat( lpstrProtocol, lpOperation );
1033 strcat( lpstrProtocol, "\\command" );
1034
1035 /* Remove File Protocol from lpFile */
1036 /* In the case file://path/file */
1037 if(!strnicmp(lpFile,"file",iSize))
1038 {
1039 lpFile += iSize;
1040 while(*lpFile == ':') lpFile++;
1041 }
1042
1043
1044 /* Get the application for the protocol and execute it */
1045 if (RegQueryValueA( HKEY_CLASSES_ROOT, lpstrProtocol, cmd,
1046 &cmdlen ) == ERROR_SUCCESS )
1047 {
1048 LPSTR tok;
1049 LPSTR tmp;
1050 char param[256] = "";
1051 LONG paramlen = 256;
1052
1053 /* Get the parameters needed by the application
1054 from the associated ddeexec key */
1055 tmp = strstr(lpstrProtocol,"command");
1056 tmp[0] = '\0';
1057 strcat(lpstrProtocol,"ddeexec");
1058
1059 if(RegQueryValueA( HKEY_CLASSES_ROOT, lpstrProtocol, param,&paramlen ) == ERROR_SUCCESS)
1060 {
1061 strcat(cmd," ");
1062 strcat(cmd,param);
1063 cmdlen += paramlen;
1064 }
1065
1066 /* Is there a replace() function anywhere? */
1067 cmd[cmdlen]='\0';
1068 tok=strstr( cmd, "%1" );
1069 if (tok != NULL)
1070 {
1071 tok[0]='\0'; /* truncate string at the percent */
1072 strcat( cmd, lpFile ); /* what if no dir in xlpFile? */
1073 tok=strstr( cmd, "%1" );
1074 if ((tok!=NULL) && (strlen(tok)>2))
1075 {
1076 strcat( cmd, &tok[2] );
1077 }
1078 }
1079
1080 retval = WinExec( cmd, iShowCmd );
1081 }
1082 }
1083 /* Check if file specified is in the form www.??????.*** */
1084 else if(!strnicmp(lpFile,"www",3))
1085 {
1086 /* if so, append lpFile http:// and call ShellExecute */
1087 char lpstrTmpFile[256] = "http://" ;
1088 strcat(lpstrTmpFile,lpFile);
1089 retval = ShellExecuteA(hWnd,lpOperation,lpstrTmpFile,NULL,NULL,0);
1090 }
1091 /* Nothing was done yet, try to execute the cmdline directly,
1092 maybe it's an OS/2 program */
1093 else
1094 {
1095 strcpy(cmd,lpFile);
1096 strcat(cmd,lpParameters ? lpParameters : "");
1097 retval = WinExec( cmd, iShowCmd );
1098 }
1099
1100 if (lpDirectory)
1101 SetCurrentDirectoryA( old_dir );
1102 return retval;
1103}
1104
1105
1106/*****************************************************************************
1107 * Name : UINT DragQueryFileAorW
1108 * Purpose :
1109 * Parameters: HDROP hDrop - drop structure handle
1110 * UINT iFile - index of file to query
1111 * LPTSTR lpszFile - target buffer
1112 * UINT cch - target buffer size
1113 * Variables :
1114 * Result :
1115 * Remark :
1116 * Status : UNTESTED STUB
1117 *
1118 * Author : Patrick Haller [Tue, 1999/06/09 20:00]
1119 *****************************************************************************/
1120
1121ODINFUNCTION4(UINT, DragQueryFileAorW,
1122 HDROP, hDrop,
1123 UINT, iFile,
1124 LPTSTR, lpszFile,
1125 UINT, cch)
1126{
1127 // @@@PH maybe they want automatic determination here
1128 if (SHELL_OsIsUnicode())
1129 return DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch);
1130 else
1131 return DragQueryFileA(hDrop, iFile, lpszFile, cch);
1132}
1133
1134
1135LPCSTR debugstr_guid1( void *id1 )
1136{
1137 static char str[40];
1138 GUID *id = (GUID *)id1;
1139
1140 if (!id) return "(null)";
1141 if (!HIWORD(id))
1142 {
1143 sprintf( str, "<guid-0x%04x>", LOWORD(id) );
1144 }
1145 else
1146 {
1147 sprintf( str, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
1148 id->Data1, id->Data2, id->Data3,
1149 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
1150 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );
1151 }
1152 return str;
1153}
1154
Note: See TracBrowser for help on using the repository browser.