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