wined3d: Remove arb_tex_npot for NV FX series in fixup_extensions.
[wine] / dlls / setupapi / setupx_main.c
1 /*
2  *      SETUPX library
3  *
4  *      Copyright 1998,2000  Andreas Mohr
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * FIXME: Rather non-functional functions for now.
21  *
22  * See:
23  * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
24  * http://willemer.de/informatik/windows/inf_info.htm (German)
25  * DDK: setupx.h
26  * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
27  * http://www.rdrop.com/~cary/html/inf_faq.html
28  *
29  * Stuff tested with:
30  * - rs405deu.exe (German Acroread 4.05 setup)
31  * - ie5setup.exe
32  * - Netmeeting
33  *
34  * FIXME:
35  * - string handling is... weird ;) (buflen etc.)
36  * - memory leaks ?
37  * - separate that mess (but probably only when it's done completely)
38  *
39  * SETUPX consists of several parts with the following acronyms/prefixes:
40  * Di   device installer (devinst.c ?)
41  * Gen  generic installer (geninst.c ?)
42  * Ip   .INF parsing (infparse.c)
43  * LDD  logical device descriptor (ldd.c ?)
44  * LDID logical device ID
45  * SU   setup (setup.c ?)
46  * Tp   text processing (textproc.c ?)
47  * Vcp  virtual copy module (vcp.c ?)
48  * ...
49  *
50  * The SETUPX DLL is NOT thread-safe. That's why many installers urge you to
51  * "close all open applications".
52  * All in all the design of it seems to be a bit weak.
53  * Not sure whether my implementation of it is better, though ;-)
54  */
55
56 #include <stdlib.h>
57 #include <stdarg.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include "windef.h"
61 #include "winbase.h"
62 #include "winreg.h"
63 #include "winerror.h"
64 #include "wownt32.h"
65 #include "winuser.h"
66 #include "winnls.h"
67 #include "setupapi.h"
68 #include "setupx16.h"
69 #include "setupapi_private.h"
70 #include "wine/debug.h"
71
72 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
73
74 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
75
76 /***********************************************************************
77  *              SURegOpenKey (SETUPX.47)
78  */
79 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, PHKEY retkey )
80 {
81     FIXME("(%p,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
82     return RegOpenKeyA( hkey, lpszSubKey, retkey );
83 }
84
85 /***********************************************************************
86  *              SURegQueryValueEx (SETUPX.50)
87  */
88 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
89                                 LPDWORD lpdwReserved, LPDWORD lpdwType,
90                                 LPBYTE lpbData, LPDWORD lpcbData )
91 {
92     FIXME("(%p,%s,%p,%p,%p,%d), semi-stub.\n",hkey,debugstr_a(lpszValueName),
93           lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
94     return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
95                                lpbData, lpcbData );
96 }
97
98
99 /***********************************************************************
100  *              InstallHinfSection (SETUPX.527)
101  *
102  * hwnd = parent window
103  * hinst = instance of SETUPX.DLL
104  * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
105  * Here "DefaultInstall" is the .inf file section to be installed (optional).
106  * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
107  *
108  * nCmdShow = nCmdShow of CreateProcess
109  */
110 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
111 {
112     InstallHinfSectionA( HWND_32(hwnd), HINSTANCE_32(hinst), lpszCmdLine, nCmdShow );
113     return OK;
114 }
115
116 typedef struct
117 {
118     LPCSTR RegValName;
119     LPCSTR StdString; /* fallback string; sub dir of windows directory */
120 } LDID_DATA;
121
122 static const LDID_DATA LDID_Data[34] =
123 {
124     { /* 0 (LDID_NULL) -- not defined */
125         NULL,
126         NULL
127     },
128     { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
129         "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
130         NULL
131     },
132     { /* 2 (LDID_SETUPTEMP) = setup temp dir */
133         "SetupTempDir",
134         NULL
135     },
136     { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
137         "UninstallDir",
138         NULL
139     },
140     { /* 4 (LDID_BACKUP) = backup dir */
141         "BackupDir",
142         NULL
143     },
144     { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
145         "SetupScratchDir",
146         NULL
147     },
148     { /* 6 -- not defined */
149         NULL,
150         NULL
151     },
152     { /* 7 -- not defined */
153         NULL,
154         NULL
155     },
156     { /* 8 -- not defined */
157         NULL,
158         NULL
159     },
160     { /* 9 -- not defined */
161         NULL,
162         NULL
163     },
164     { /* 10 (LDID_WIN) = windows dir */
165         "WinDir",
166         ""
167     },
168     { /* 11 (LDID_SYS) = system dir */
169         "SysDir",
170         NULL /* call GetSystemDirectory() instead */
171     },
172     { /* 12 (LDID_IOS) = IOSubSys dir */
173         NULL, /* FIXME: registry string ? */
174         "SYSTEM\\IOSUBSYS"
175     },
176     { /* 13 (LDID_CMD) = COMMAND dir */
177         NULL, /* FIXME: registry string ? */
178         "COMMAND"
179     },
180     { /* 14 (LDID_CPL) = control panel dir */
181         NULL,
182         ""
183     },
184     { /* 15 (LDID_PRINT) = windows printer dir */
185         NULL,
186         "SYSTEM" /* correct ?? */
187     },
188     { /* 16 (LDID_MAIL) = destination mail dir */
189         NULL,
190         ""
191     },
192     { /* 17 (LDID_INF) = INF dir */
193         "SetupScratchDir", /* correct ? */
194         "INF"
195     },
196     { /* 18 (LDID_HELP) = HELP dir */
197         NULL, /* ??? */
198         "HELP"
199     },
200     { /* 19 (LDID_WINADMIN) = Admin dir */
201         "WinAdminDir",
202         ""
203     },
204     { /* 20 (LDID_FONTS) = Fonts dir */
205         NULL, /* ??? */
206         "FONTS"
207     },
208     { /* 21 (LDID_VIEWERS) = Viewers */
209         NULL, /* ??? */
210         "SYSTEM\\VIEWERS"
211     },
212     { /* 22 (LDID_VMM32) = VMM32 dir */
213         NULL, /* ??? */
214         "SYSTEM\\VMM32"
215     },
216     { /* 23 (LDID_COLOR) = ICM dir */
217         "ICMPath",
218         "SYSTEM\\COLOR"
219     },
220     { /* 24 (LDID_APPS) = root of boot drive ? */
221         "AppsDir",
222         "C:\\"
223     },
224     { /* 25 (LDID_SHARED) = shared dir */
225         "SharedDir",
226         ""
227     },
228     { /* 26 (LDID_WINBOOT) = Windows boot dir */
229         "WinBootDir",
230         ""
231     },
232     { /* 27 (LDID_MACHINE) = machine specific files */
233         "MachineDir",
234         NULL
235     },
236     { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
237         "HostWinBootDir",
238         NULL
239     },
240     { /* 29 -- not defined */
241         NULL,
242         NULL
243     },
244     { /* 30 (LDID_BOOT) = Root of boot drive */
245         "BootDir",
246         NULL
247     },
248     { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
249         "BootHost",
250         NULL
251     },
252     { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
253         "OldWinBootDir",
254         NULL
255     },
256     { /* 33 (LDID_OLD_WIN) = old win dir */
257         "OldWinDir",
258         NULL
259     }
260     /* the rest (34-38) isn't too interesting, so I'll forget about it */
261 };
262
263 /*
264  * LDD  == Logical Device Descriptor
265  * LDID == Logical Device ID
266  *
267  * The whole LDD/LDID business might go into a separate file named
268  * ldd.c.
269  * At the moment I don't know what the hell these functions are really doing.
270  * That's why I added reporting stubs.
271  * The only thing I do know is that I need them for the LDD/LDID infrastructure.
272  * That's why I implemented them in a way that's suitable for my purpose.
273  */
274 static LDD_LIST *pFirstLDD = NULL;
275
276 static BOOL std_LDDs_done = FALSE;
277
278 static void SETUPX_CreateStandardLDDs(void)
279 {
280     HKEY hKey = 0;
281     WORD n;
282     DWORD type, len;
283     LOGDISKDESC_S ldd;
284     char buffer[MAX_PATH];
285
286     /* has to be here, otherwise loop */
287     std_LDDs_done = TRUE;
288
289     RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
290
291     for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
292     {
293         buffer[0] = '\0';
294
295         len = MAX_PATH;
296         if ( (hKey) && (LDID_Data[n].RegValName)
297         &&   (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
298                 NULL, &type, (LPBYTE)buffer, &len) == ERROR_SUCCESS)
299         &&   (type == REG_SZ) )
300         {
301             TRACE("found value '%s' for LDID %d\n", buffer, n);
302         }
303         else
304         switch(n)
305         {
306             case LDID_SRCPATH:
307                 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
308                 strcpy(buffer, "X:\\FIXME");
309                 break;
310             case LDID_SYS:
311                 GetSystemDirectoryA(buffer, MAX_PATH);
312                 break;
313             case LDID_APPS:
314             case LDID_MACHINE:
315             case LDID_HOST_WINBOOT:
316             case LDID_BOOT:
317             case LDID_BOOT_HOST:
318                 strcpy(buffer, "C:\\");
319                 break;
320             default:
321                 if (LDID_Data[n].StdString)
322                 {
323                     DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
324                     LPSTR p;
325                     p = buffer + len;
326                     *p++ = '\\';
327                     strcpy(p, LDID_Data[n].StdString);
328                 }
329                 break;
330         }
331         if (buffer[0])
332         {
333             INIT_LDD(ldd, n);
334             ldd.pszPath = buffer;
335             TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
336             CtlSetLdd16(&ldd);
337         }
338     }
339     if (hKey) RegCloseKey(hKey);
340 }
341
342 /***********************************************************************
343  * CtlDelLdd            (SETUPX.37)
344  *
345  * RETURN
346  *   ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
347  */
348 static RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
349 {
350     LDD_LIST *pCurr, *pPrev = NULL;
351
352     TRACE("(%d)\n", ldid);
353
354     if (!std_LDDs_done)
355         SETUPX_CreateStandardLDDs();
356
357     if (ldid < LDID_ASSIGN_START)
358         return ERR_VCP_LDDINVALID;
359
360     pCurr = pFirstLDD;
361     /* search until we find the appropriate LDD or hit the end */
362     while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
363     {
364          pPrev = pCurr;
365          pCurr = pCurr->next;
366     }
367     if ( (pCurr == NULL) /* hit end of list */
368       || (ldid != pCurr->pldd->ldid) )
369         return ERR_VCP_LDDFIND; /* correct ? */
370
371     /* ok, found our victim: eliminate it */
372
373     if (pPrev)
374         pPrev->next = pCurr->next;
375
376     if (pCurr == pFirstLDD)
377         pFirstLDD = NULL;
378     HeapFree(GetProcessHeap(), 0, pCurr);
379
380     return OK;
381 }
382
383 /***********************************************************************
384  *              CtlDelLdd (SETUPX.37)
385  */
386 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
387 {
388     FIXME("(%d); - please report this!\n", ldid);
389     return SETUPX_DelLdd(ldid);
390 }
391
392 /***********************************************************************
393  * CtlFindLdd           (SETUPX.35)
394  *
395  * doesn't check pldd ptr validity: crash (W98SE)
396  *
397  * RETURN
398  *   ERR_VCP_LDDINVALID if pldd->cbSize != structsize
399  *   1 in all other cases ??
400  *
401  */
402 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
403 {
404     LDD_LIST *pCurr;
405
406     TRACE("(%p)\n", pldd);
407
408     if (!std_LDDs_done)
409         SETUPX_CreateStandardLDDs();
410
411     if (pldd->cbSize != sizeof(LOGDISKDESC_S))
412         return ERR_VCP_LDDINVALID;
413
414     pCurr = pFirstLDD;
415     /* search until we find the appropriate LDD or hit the end */
416     while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
417         pCurr = pCurr->next;
418     if ( (pCurr == NULL) /* hit end of list */
419       || (pldd->ldid != pCurr->pldd->ldid) )
420         return ERR_VCP_LDDFIND; /* correct ? */
421
422     memcpy(pldd, pCurr->pldd, pldd->cbSize);
423     /* hmm, we probably ought to strcpy() the string ptrs here */
424
425     return 1; /* what is this ?? */
426 }
427
428 /***********************************************************************
429  * CtlSetLdd                    (SETUPX.33)
430  *
431  * Set an LDD entry.
432  *
433  * RETURN
434  *   ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
435  *
436  */
437 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
438 {
439     LDD_LIST *pCurr, *pPrev = NULL;
440     LPLOGDISKDESC pCurrLDD;
441     HANDLE heap;
442     BOOL is_new = FALSE;
443
444     TRACE("(%p)\n", pldd);
445
446     if (!std_LDDs_done)
447         SETUPX_CreateStandardLDDs();
448
449     if (pldd->cbSize != sizeof(LOGDISKDESC_S))
450         return ERR_VCP_LDDINVALID;
451
452     heap = GetProcessHeap();
453     pCurr = pFirstLDD;
454     /* search until we find the appropriate LDD or hit the end */
455     while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
456     {
457          pPrev = pCurr;
458          pCurr = pCurr->next;
459     }
460     if (!pCurr || pldd->ldid != pCurr->pldd->ldid)
461     {
462         is_new = TRUE;
463         pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
464         pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
465         pCurr->next = NULL;
466         pCurrLDD = pCurr->pldd;
467     }
468     else
469     {
470         pCurrLDD = pCurr->pldd;
471         HeapFree(heap, 0, pCurrLDD->pszPath);
472         HeapFree(heap, 0, pCurrLDD->pszVolLabel);
473         HeapFree(heap, 0, pCurrLDD->pszDiskName);
474     }
475
476     *pCurrLDD = *pldd;
477
478     if (pldd->pszPath)
479     {
480         pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
481         strcpy( pCurrLDD->pszPath, pldd->pszPath );
482     }
483     if (pldd->pszVolLabel)
484     {
485         pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
486         strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
487     }
488     if (pldd->pszDiskName)
489     {
490         pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
491         strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
492     }
493
494     if (is_new) /* link into list */
495     {
496         if (pPrev)
497         {
498             pCurr->next = pPrev->next;
499             pPrev->next = pCurr;
500         }
501         if (!pFirstLDD)
502             pFirstLDD = pCurr;
503     }
504
505     return OK;
506 }
507
508
509 /***********************************************************************
510  * CtlAddLdd            (SETUPX.36)
511  *
512  * doesn't check pldd ptr validity: crash (W98SE)
513  *
514  */
515 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
516 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
517 {
518     pldd->ldid = ldid_to_add++;
519     return CtlSetLdd16(pldd);
520 }
521
522 /***********************************************************************
523  * CtlGetLdd            (SETUPX.34)
524  *
525  * doesn't check pldd ptr validity: crash (W98SE)
526  * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
527  *
528  * RETURN
529  *   ERR_VCP_LDDINVALID if pldd->cbSize != structsize
530  *
531  */
532 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
533 {
534     LDD_LIST *pCurr;
535
536     if (!std_LDDs_done)
537         SETUPX_CreateStandardLDDs();
538
539     if (pldd->cbSize != sizeof(LOGDISKDESC_S))
540         return ERR_VCP_LDDINVALID;
541
542     pCurr = pFirstLDD;
543     /* search until we find the appropriate LDD or hit the end */
544     while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
545         pCurr = pCurr->next;
546     if (pCurr == NULL) /* hit end of list */
547         return ERR_VCP_LDDFIND; /* correct ? */
548
549     memcpy(pldd, pCurr->pldd, pldd->cbSize);
550     /* hmm, we probably ought to strcpy() the string ptrs here */
551
552     return OK;
553 }
554
555 /**********************************************************************/
556
557 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
558 {
559     FIXME("(%p); - please report this!\n", pldd);
560     return SETUPX_GetLdd(pldd);
561 }
562
563 /***********************************************************************
564  *              CtlGetLddPath           (SETUPX.38)
565  *
566  * Gets the path of an LDD.
567  * No crash if szPath == NULL.
568  * szPath has to be at least MAX_PATH_LEN bytes long.
569  * RETURN
570  *   ERR_VCP_LDDUNINIT if LDD for LDID not found.
571  */
572 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
573 {
574     TRACE("(%d, %p);\n", ldid, szPath);
575
576     if (szPath)
577     {
578         LOGDISKDESC_S ldd;
579         INIT_LDD(ldd, ldid);
580         if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
581             return ERR_VCP_LDDUNINIT;
582         SETUPX_GetLdd(&ldd);
583         strcpy(szPath, ldd.pszPath);
584         TRACE("ret '%s' for LDID %d\n", szPath, ldid);
585     }
586     return OK;
587 }
588
589 /***********************************************************************
590  *              CtlSetLddPath           (SETUPX.508)
591  *
592  * Sets the path of an LDD.
593  * Creates LDD for LDID if not existing yet.
594  */
595 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
596 {
597     LOGDISKDESC_S ldd;
598     TRACE("(%d, '%s');\n", ldid, szPath);
599
600     SetupSetDirectoryIdA( 0, ldid, szPath );
601     INIT_LDD(ldd, ldid);
602     ldd.pszPath = szPath;
603     return CtlSetLdd16(&ldd);
604 }