Release 940620
[wine] / misc / shell.c
1 /*
2  *                              Shell Library Functions
3  */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include "prototypes.h"
9 #include "windows.h"
10 #include "shell.h"
11
12 /*
13 #define DEBUG_REG
14 */
15
16 LPKEYSTRUCT     lphRootKey = NULL;
17
18 DECLARE_HANDLE(HDROP);
19
20 extern HINSTANCE hSysRes;
21
22 /*************************************************************************
23  *                              RegOpenKey              [SHELL.1]
24  */
25 LONG RegOpenKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
26 {
27         LPKEYSTRUCT     lpKey = lphRootKey;
28         LPSTR           ptr;
29         char            str[128];
30         int                     size;
31 #ifdef DEBUG_REG
32         fprintf(stderr, "RegOpenKey(%04X, %08X='%s', %08X)\n",
33                                                 hKey, lpSubKey, lpSubKey, lphKey);
34 #endif
35         if (lpKey == NULL) return ERROR_BADKEY;
36         if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
37         if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
38         if (hKey != HKEY_CLASSES_ROOT) {
39 #ifdef DEBUG_REG
40                 printf("RegOpenKey // specific key = %04X !\n", hKey);
41 #endif
42                 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
43                 }
44         while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
45                 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
46                 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
47                 lpSubKey = ptr + 1;
48 #ifdef DEBUG_REG
49                 printf("RegOpenKey // next level '%s' !\n", str);
50 #endif
51                 while(TRUE) {
52 #ifdef DEBUG_REG
53                         printf("RegOpenKey // '%s' <-> '%s' !\n", str, lpKey->lpSubKey);
54 #endif
55                         if (lpKey->lpSubKey != NULL && lpKey->lpSubKey[0] != '\0' &&
56                                 strcmp(lpKey->lpSubKey, str) == 0) {
57                                 lpKey = lpKey->lpSubLvl;
58                                 if (lpKey == NULL) {
59                                         printf("RegOpenKey // can't find subkey '%s' !\n", str);
60                                         return ERROR_BADKEY;
61                                         }
62                                 break;
63                                 }
64                         if (lpKey->lpNextKey == NULL) {
65                                 printf("RegOpenKey // can't find subkey '%s' !\n", str);
66                                 return ERROR_BADKEY;
67                                 }
68                         lpKey = lpKey->lpNextKey;
69                         }
70                 }
71         while(TRUE) {
72                 if (lpKey->lpSubKey != NULL && 
73                         strcmp(lpKey->lpSubKey, lpSubKey) == 0) break;
74                 if (lpKey->lpNextKey == NULL) {
75                         printf("RegOpenKey // can't find subkey '%s' !\n", str);
76                         return ERROR_BADKEY;
77                         }
78                 lpKey = lpKey->lpNextKey;
79                 }
80         *lphKey = lpKey->hKey;
81 #ifdef DEBUG_REG
82         printf("RegOpenKey // return hKey=%04X !\n", lpKey->hKey);
83 #endif
84         return ERROR_SUCCESS;
85 }
86
87
88 /*************************************************************************
89  *                              RegCreateKey            [SHELL.2]
90  */
91 LONG RegCreateKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
92 {
93         HKEY            hNewKey;
94         LPKEYSTRUCT     lpNewKey;
95         LPKEYSTRUCT     lpKey = lphRootKey;
96         LPKEYSTRUCT     lpPrevKey;
97         LONG            dwRet;
98         LPSTR           ptr;
99         char            str[128];
100 #ifdef DEBUG_REG
101         fprintf(stderr, "RegCreateKey(%04X, '%s', %08X)\n",     hKey, lpSubKey, lphKey);
102 #endif
103         if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
104         if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
105         if (hKey != HKEY_CLASSES_ROOT) {
106 #ifdef DEBUG_REG
107                 printf("RegCreateKey // specific key = %04X !\n", hKey);
108 #endif
109                 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
110                 }
111         while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
112                 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
113                 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
114                 lpSubKey = ptr + 1;
115 #ifdef DEBUG_REG
116                 printf("RegCreateKey // next level '%s' !\n", str);
117 #endif
118                 lpPrevKey = lpKey;
119                 while(TRUE) {
120 #ifdef DEBUG_REG
121                         printf("RegCreateKey // '%s' <-> '%s' !\n", str, lpKey->lpSubKey);
122 #endif
123                         if (lpKey->lpSubKey != NULL &&
124                                 strcmp(lpKey->lpSubKey, str) == 0) {
125                                 if (lpKey->lpSubLvl == NULL) {
126 #ifdef DEBUG_REG
127                                         printf("RegCreateKey // '%s' found !\n", str);
128 #endif
129                                         if ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
130                                                 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
131                                                 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
132                                                 lpSubKey = ptr + 1;
133                                                 }
134                                         else
135                                                 strcpy(str, lpSubKey);
136                                         dwRet = RegCreateKey(lpKey->hKey, str, &hNewKey);
137                                         if (dwRet != ERROR_SUCCESS) {
138                                                 printf("RegCreateKey // can't create subkey '%s' !\n", str);
139                                                 return dwRet;
140                                                 }
141                                         lpKey->lpSubLvl = (LPKEYSTRUCT)GlobalLock(hNewKey);
142                                         }
143                                 lpKey = lpKey->lpSubLvl;
144                                 break;
145                                 }
146                         if (lpKey->lpNextKey == NULL) {
147                                 dwRet = RegCreateKey(lpPrevKey->hKey, str, &hNewKey);
148                                 if (dwRet != ERROR_SUCCESS) {
149                                         printf("RegCreateKey // can't create subkey '%s' !\n", str);
150                                         return dwRet;
151                                         }
152                                 lpKey = (LPKEYSTRUCT)GlobalLock(hNewKey);
153                                 break;
154                                 }
155                         lpKey = lpKey->lpNextKey;
156                         }
157                 }
158         hNewKey = GlobalAlloc(GMEM_MOVEABLE, sizeof(KEYSTRUCT));
159         lpNewKey = (LPKEYSTRUCT) GlobalLock(hNewKey);
160         if (lpNewKey == NULL) {
161                 printf("RegCreateKey // Can't alloc new key !\n");
162                 return ERROR_OUTOFMEMORY;
163                 }
164         if (lphRootKey == NULL) {
165                 lphRootKey = lpNewKey;
166                 lpNewKey->lpPrevKey = NULL;
167                 }
168         else {
169                 lpKey->lpNextKey = lpNewKey;
170                 lpNewKey->lpPrevKey = lpKey;
171                 }
172         lpNewKey->hKey = hNewKey;
173         lpNewKey->lpSubKey = malloc(strlen(lpSubKey) + 1);
174         if (lpNewKey->lpSubKey == NULL) {
175                 printf("RegCreateKey // Can't alloc key string !\n");
176                 return ERROR_OUTOFMEMORY;
177                 }
178         strcpy(lpNewKey->lpSubKey, lpSubKey);
179         lpNewKey->dwType = 0;
180         lpNewKey->lpValue = NULL;
181         lpNewKey->lpNextKey = NULL;
182         lpNewKey->lpSubLvl = NULL;
183         *lphKey = hNewKey;
184 #ifdef DEBUG_REG
185         printf("RegCreateKey // successful '%s' key=%04X !\n", lpSubKey, hNewKey);
186 #endif
187         return ERROR_SUCCESS;
188 }
189
190
191 /*************************************************************************
192  *                              RegCloseKey             [SHELL.3]
193  */
194 LONG RegCloseKey(HKEY hKey)
195 {
196         fprintf(stderr, "EMPTY STUB !!! RegCloseKey(%04X);\n", hKey);
197         return ERROR_INVALID_PARAMETER;
198 }
199
200
201 /*************************************************************************
202  *                              RegDeleteKey            [SHELL.4]
203  */
204 LONG RegDeleteKey(HKEY hKey, LPCSTR lpSubKey)
205 {
206         fprintf(stderr, "EMPTY STUB !!! RegDeleteKey(%04X, '%s');\n", 
207                                                                                                 hKey, lpSubKey);
208         return ERROR_INVALID_PARAMETER;
209 }
210
211
212 /*************************************************************************
213  *                              RegSetValue             [SHELL.5]
214  */
215 LONG RegSetValue(HKEY hKey, LPCSTR lpSubKey, DWORD dwType, 
216                                         LPCSTR lpVal, DWORD dwIgnored)
217 {
218         HKEY            hRetKey;
219         LPKEYSTRUCT     lpKey;
220         LONG            dwRet;
221 #ifdef DEBUG_REG
222         fprintf(stderr, "RegSetValue(%04X, '%s', %08X, '%s', %08X);\n",
223                                                 hKey, lpSubKey, dwType, lpVal, dwIgnored);
224 #endif
225         if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
226         if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
227         if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
228 #ifdef DEBUG_REG
229                 fprintf(stderr, "RegSetValue // key not found ... so create it !\n");
230 #endif
231                 if ((dwRet = RegCreateKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
232                         fprintf(stderr, "RegSetValue // key creation error %04X !\n", dwRet);
233                         return dwRet;
234                         }
235                 }
236         lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
237         if (lpKey == NULL) return ERROR_BADKEY;
238         if (lpKey->lpValue != NULL) free(lpKey->lpValue);
239         lpKey->lpValue = malloc(strlen(lpVal) + 1);
240         strcpy(lpKey->lpValue, lpVal);
241 #ifdef DEBUG_REG
242         printf("RegSetValue // successful key='%s' val='%s' !\n", lpSubKey, lpVal);
243 #endif
244         return ERROR_SUCCESS;
245 }
246
247
248 /*************************************************************************
249  *                              RegQueryValue           [SHELL.6]
250  */
251 LONG RegQueryValue(HKEY hKey, LPCSTR lpSubKey, LPSTR lpVal, LONG FAR *lpcb)
252 {
253         HKEY            hRetKey;
254         LPKEYSTRUCT     lpKey;
255         LONG            dwRet;
256         int                     size;
257         fprintf(stderr, "RegQueryValue(%04X, '%s', %08X, %08X);\n",
258                                                         hKey, lpSubKey, lpVal, lpcb);
259         if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
260         if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
261         if (lpcb == NULL) return ERROR_INVALID_PARAMETER;
262         if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
263                 fprintf(stderr, "RegQueryValue // key not found !\n");
264                 return dwRet;
265                 }
266         lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
267         if (lpKey == NULL) return ERROR_BADKEY;
268         if (lpKey->lpValue != NULL) {
269                 size = min(strlen(lpKey->lpValue), *lpcb);
270                 strncpy(lpVal, lpKey->lpValue, size);
271                 *lpcb = (LONG)size;
272                 }
273         else {
274                 lpVal[0] = '\0';
275                 *lpcb = (LONG)0;
276                 }
277         printf("RegQueryValue // return '%s' !\n", lpVal);
278         return ERROR_SUCCESS;
279 }
280
281
282 /*************************************************************************
283  *                              RegEnumKey              [SHELL.7]
284  */
285 LONG RegEnumKey(HKEY hKey, DWORD dwSubKey, LPSTR lpBuf, DWORD dwSize)
286 {
287         fprintf(stderr, "RegEnumKey : Empty Stub !!!\n");
288         return ERROR_INVALID_PARAMETER;
289 }
290
291 /*************************************************************************
292  *                              DragAcceptFiles         [SHELL.9]
293  */
294 void DragAcceptFiles(HWND hWnd, BOOL b)
295 {
296         fprintf(stderr, "DragAcceptFiles : Empty Stub !!!\n");
297 }
298
299
300 /*************************************************************************
301  *                              DragQueryFile           [SHELL.11]
302  */
303 void DragQueryFile(HDROP h, UINT u, LPSTR u2, UINT u3)
304 {
305         fprintf(stderr, "DragQueryFile : Empty Stub !!!\n");
306
307 }
308
309
310 /*************************************************************************
311  *                              DragFinish              [SHELL.12]
312  */
313 void DragFinish(HDROP h)
314 {
315         fprintf(stderr, "DragFinish : Empty Stub !!!\n");
316
317 }
318
319
320 /*************************************************************************
321  *                              DragQueryPoint          [SHELL.13]
322  */
323 BOOL DragQueryPoint(HDROP h, POINT FAR *p)
324 {
325         fprintf(stderr, "DragQueryPoinyt : Empty Stub !!!\n");
326
327 }
328
329
330 /*************************************************************************
331  *                              ShellExecute            [SHELL.20]
332  */
333 HINSTANCE ShellExecute(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int iShowCmd)
334 {
335         fprintf(stderr, "ShellExecute // hWnd=%04X\n", hWnd);
336         fprintf(stderr, "ShellExecute // lpOperation='%s'\n", lpOperation);
337         fprintf(stderr, "ShellExecute // lpFile='%s'\n", lpFile);
338         fprintf(stderr, "ShellExecute // lpParameters='%s'\n", lpParameters);
339         fprintf(stderr, "ShellExecute // lpDirectory='%s'\n", lpDirectory);
340         fprintf(stderr, "ShellExecute // iShowCmd=%04X\n", iShowCmd);
341         return 2; /* file not found */
342 }
343
344
345 /*************************************************************************
346  *                              FindExecutable          [SHELL.21]
347  */
348 HINSTANCE FindExecutable(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
349 {
350         fprintf(stderr, "FindExecutable : Empty Stub !!!\n");
351
352 }
353
354 char AppName[256], AppMisc[256];
355 INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam);
356
357 /*************************************************************************
358  *                              ShellAbout              [SHELL.22]
359  */
360 INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon)
361 {
362         fprintf(stderr, "ShellAbout ! (%s, %s)\n", szApp, szOtherStuff);
363
364         strcpy(AppName, szApp);
365         strcpy(AppMisc, szOtherStuff);
366
367         return DialogBox(hSysRes, "SHELL_ABOUT_MSGBOX", hWnd, (FARPROC)AboutDlgProc);
368 }
369
370
371 /*************************************************************************
372  *                              AboutDlgProc            [SHELL.33]
373  */
374 INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
375 {
376         char temp[256];
377
378         switch(msg) {
379         case WM_INITDIALOG:
380                 sprintf(temp, "About %s", AppName);
381                 SetWindowText(hWnd, temp);
382                 SetDlgItemText(hWnd, 100, AppMisc);
383                 break;
384
385         case WM_COMMAND:
386                 switch (wParam) {
387                 case IDOK:
388                         EndDialog(hWnd, TRUE);
389                         return TRUE;
390                 }
391         }
392         return FALSE;
393 }
394
395 /*************************************************************************
396  *                              ExtractIcon             [SHELL.34]
397  */
398 HICON ExtractIcon(HINSTANCE hInst, LPCSTR lpszExeFileName, UINT nIconIndex)
399 {
400         int             count;
401         HICON   hIcon = 0;
402         HINSTANCE hInst2 = hInst;
403         fprintf(stderr, "ExtractIcon(%04X, '%s', %d\n", 
404                         hInst, lpszExeFileName, nIconIndex);
405         if (lpszExeFileName != NULL) {
406                 hInst2 = LoadLibrary(lpszExeFileName);
407                 }
408         if (hInst2 != 0 && nIconIndex == (UINT)-1) {
409                 count = GetRsrcCount(hInst2, NE_RSCTYPE_GROUP_ICON);
410                 printf("ExtractIcon // '%s' has %d icons !\n", lpszExeFileName, count);
411                 return (HICON)count;
412                 }
413         if (hInst2 != hInst && hInst2 != 0) {
414                 FreeLibrary(hInst2);
415                 }
416         return hIcon;
417 }
418
419
420 /*************************************************************************
421  *                              ExtractAssociatedIcon   [SHELL.36]
422  */
423 HICON ExtractAssociatedIcon(HINSTANCE hInst,LPSTR lpIconPath, LPWORD lpiIcon)
424 {
425         fprintf(stderr, "ExtractAssociatedIcon : Empty Stub !!!\n");
426 }
427
428 /*************************************************************************
429  *                              RegisterShellHook       [SHELL.102]
430  */
431 int RegisterShellHook(void *ptr) 
432 {
433         fprintf(stderr, "RegisterShellHook : Empty Stub !!!\n");
434         return 0;
435 }
436
437
438 /*************************************************************************
439  *                              ShellHookProc           [SHELL.103]
440  */
441 int ShellHookProc(void) 
442 {
443         fprintf(stderr, "ShellHookProc : Empty Stub !!!\n");
444 }