msi: If the UserData product key exists, but the user product key doesn't, the produc...
[wine/hacks.git] / dlls / setupapi / setupx_main.c
blob81079d62416863b81fb2c2972654d9a7058058c3
1 /*
2 * SETUPX library
4 * Copyright 1998,2000 Andreas Mohr
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.
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.
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
20 * FIXME: Rather non-functional functions for now.
22 * See:
23 * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
24 * http://willemer.de/informatik/windows/inf_info.htm (German)
25 * http://www.microsoft.com/ddk/ddkdocs/win98ddk/devinst_12uw.htm
26 * DDK: setupx.h
27 * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
28 * http://www.rdrop.com/~cary/html/inf_faq.html
29 * http://support.microsoft.com/support/kb/articles/q194/6/40.asp
31 * Stuff tested with:
32 * - rs405deu.exe (German Acroread 4.05 setup)
33 * - ie5setup.exe
34 * - Netmeeting
36 * FIXME:
37 * - string handling is... weird ;) (buflen etc.)
38 * - memory leaks ?
39 * - separate that mess (but probably only when it's done completely)
41 * SETUPX consists of several parts with the following acronyms/prefixes:
42 * Di device installer (devinst.c ?)
43 * Gen generic installer (geninst.c ?)
44 * Ip .INF parsing (infparse.c)
45 * LDD logical device descriptor (ldd.c ?)
46 * LDID logical device ID
47 * SU setup (setup.c ?)
48 * Tp text processing (textproc.c ?)
49 * Vcp virtual copy module (vcp.c ?)
50 * ...
52 * The SETUPX DLL is NOT thread-safe. That's why many installers urge you to
53 * "close all open applications".
54 * All in all the design of it seems to be a bit weak.
55 * Not sure whether my implementation of it is better, though ;-)
58 #include <stdlib.h>
59 #include <stdarg.h>
60 #include <stdio.h>
61 #include <string.h>
62 #include "windef.h"
63 #include "winbase.h"
64 #include "winreg.h"
65 #include "winerror.h"
66 #include "wine/winuser16.h"
67 #include "wownt32.h"
68 #include "winuser.h"
69 #include "winnls.h"
70 #include "setupapi.h"
71 #include "setupx16.h"
72 #include "setupapi_private.h"
73 #include "winerror.h"
74 #include "wine/debug.h"
76 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
78 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
80 /***********************************************************************
81 * SURegOpenKey (SETUPX.47)
83 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, PHKEY retkey )
85 FIXME("(%p,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
86 return RegOpenKeyA( hkey, lpszSubKey, retkey );
89 /***********************************************************************
90 * SURegQueryValueEx (SETUPX.50)
92 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
93 LPDWORD lpdwReserved, LPDWORD lpdwType,
94 LPBYTE lpbData, LPDWORD lpcbData )
96 FIXME("(%p,%s,%p,%p,%p,%d), semi-stub.\n",hkey,debugstr_a(lpszValueName),
97 lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
98 return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
99 lpbData, lpcbData );
103 /***********************************************************************
104 * InstallHinfSection (SETUPX.527)
106 * hwnd = parent window
107 * hinst = instance of SETUPX.DLL
108 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
109 * Here "DefaultInstall" is the .inf file section to be installed (optional).
110 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
112 * nCmdShow = nCmdShow of CreateProcess
114 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
116 InstallHinfSectionA( HWND_32(hwnd), HINSTANCE_32(hinst), lpszCmdLine, nCmdShow );
117 return OK;
120 typedef struct
122 LPCSTR RegValName;
123 LPCSTR StdString; /* fallback string; sub dir of windows directory */
124 } LDID_DATA;
126 static const LDID_DATA LDID_Data[34] =
128 { /* 0 (LDID_NULL) -- not defined */
129 NULL,
130 NULL
132 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
133 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
134 NULL
136 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
137 "SetupTempDir",
138 NULL
140 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
141 "UninstallDir",
142 NULL
144 { /* 4 (LDID_BACKUP) = backup dir */
145 "BackupDir",
146 NULL
148 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
149 "SetupScratchDir",
150 NULL
152 { /* 6 -- not defined */
153 NULL,
154 NULL
156 { /* 7 -- not defined */
157 NULL,
158 NULL
160 { /* 8 -- not defined */
161 NULL,
162 NULL
164 { /* 9 -- not defined */
165 NULL,
166 NULL
168 { /* 10 (LDID_WIN) = windows dir */
169 "WinDir",
172 { /* 11 (LDID_SYS) = system dir */
173 "SysDir",
174 NULL /* call GetSystemDirectory() instead */
176 { /* 12 (LDID_IOS) = IOSubSys dir */
177 NULL, /* FIXME: registry string ? */
178 "SYSTEM\\IOSUBSYS"
180 { /* 13 (LDID_CMD) = COMMAND dir */
181 NULL, /* FIXME: registry string ? */
182 "COMMAND"
184 { /* 14 (LDID_CPL) = control panel dir */
185 NULL,
188 { /* 15 (LDID_PRINT) = windows printer dir */
189 NULL,
190 "SYSTEM" /* correct ?? */
192 { /* 16 (LDID_MAIL) = destination mail dir */
193 NULL,
196 { /* 17 (LDID_INF) = INF dir */
197 "SetupScratchDir", /* correct ? */
198 "INF"
200 { /* 18 (LDID_HELP) = HELP dir */
201 NULL, /* ??? */
202 "HELP"
204 { /* 19 (LDID_WINADMIN) = Admin dir */
205 "WinAdminDir",
208 { /* 20 (LDID_FONTS) = Fonts dir */
209 NULL, /* ??? */
210 "FONTS"
212 { /* 21 (LDID_VIEWERS) = Viewers */
213 NULL, /* ??? */
214 "SYSTEM\\VIEWERS"
216 { /* 22 (LDID_VMM32) = VMM32 dir */
217 NULL, /* ??? */
218 "SYSTEM\\VMM32"
220 { /* 23 (LDID_COLOR) = ICM dir */
221 "ICMPath",
222 "SYSTEM\\COLOR"
224 { /* 24 (LDID_APPS) = root of boot drive ? */
225 "AppsDir",
226 "C:\\"
228 { /* 25 (LDID_SHARED) = shared dir */
229 "SharedDir",
232 { /* 26 (LDID_WINBOOT) = Windows boot dir */
233 "WinBootDir",
236 { /* 27 (LDID_MACHINE) = machine specific files */
237 "MachineDir",
238 NULL
240 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
241 "HostWinBootDir",
242 NULL
244 { /* 29 -- not defined */
245 NULL,
246 NULL
248 { /* 30 (LDID_BOOT) = Root of boot drive */
249 "BootDir",
250 NULL
252 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
253 "BootHost",
254 NULL
256 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
257 "OldWinBootDir",
258 NULL
260 { /* 33 (LDID_OLD_WIN) = old win dir */
261 "OldWinDir",
262 NULL
264 /* the rest (34-38) isn't too interesting, so I'll forget about it */
268 * LDD == Logical Device Descriptor
269 * LDID == Logical Device ID
271 * The whole LDD/LDID business might go into a separate file named
272 * ldd.c.
273 * At the moment I don't know what the hell these functions are really doing.
274 * That's why I added reporting stubs.
275 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
276 * That's why I implemented them in a way that's suitable for my purpose.
278 static LDD_LIST *pFirstLDD = NULL;
280 static BOOL std_LDDs_done = FALSE;
282 static void SETUPX_CreateStandardLDDs(void)
284 HKEY hKey = 0;
285 WORD n;
286 DWORD type, len;
287 LOGDISKDESC_S ldd;
288 char buffer[MAX_PATH];
290 /* has to be here, otherwise loop */
291 std_LDDs_done = TRUE;
293 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
295 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
297 buffer[0] = '\0';
299 len = MAX_PATH;
300 if ( (hKey) && (LDID_Data[n].RegValName)
301 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
302 NULL, &type, (LPBYTE)buffer, &len) == ERROR_SUCCESS)
303 && (type == REG_SZ) )
305 TRACE("found value '%s' for LDID %d\n", buffer, n);
307 else
308 switch(n)
310 case LDID_SRCPATH:
311 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
312 strcpy(buffer, "X:\\FIXME");
313 break;
314 case LDID_SYS:
315 GetSystemDirectoryA(buffer, MAX_PATH);
316 break;
317 case LDID_APPS:
318 case LDID_MACHINE:
319 case LDID_HOST_WINBOOT:
320 case LDID_BOOT:
321 case LDID_BOOT_HOST:
322 strcpy(buffer, "C:\\");
323 break;
324 default:
325 if (LDID_Data[n].StdString)
327 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
328 LPSTR p;
329 p = buffer + len;
330 *p++ = '\\';
331 strcpy(p, LDID_Data[n].StdString);
333 break;
335 if (buffer[0])
337 INIT_LDD(ldd, n);
338 ldd.pszPath = buffer;
339 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
340 CtlSetLdd16(&ldd);
343 if (hKey) RegCloseKey(hKey);
346 /***********************************************************************
347 * CtlDelLdd (SETUPX.37)
349 * RETURN
350 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
352 static RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
354 LDD_LIST *pCurr, *pPrev = NULL;
356 TRACE("(%d)\n", ldid);
358 if (!std_LDDs_done)
359 SETUPX_CreateStandardLDDs();
361 if (ldid < LDID_ASSIGN_START)
362 return ERR_VCP_LDDINVALID;
364 pCurr = pFirstLDD;
365 /* search until we find the appropriate LDD or hit the end */
366 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
368 pPrev = pCurr;
369 pCurr = pCurr->next;
371 if ( (pCurr == NULL) /* hit end of list */
372 || (ldid != pCurr->pldd->ldid) )
373 return ERR_VCP_LDDFIND; /* correct ? */
375 /* ok, found our victim: eliminate it */
377 if (pPrev)
378 pPrev->next = pCurr->next;
380 if (pCurr == pFirstLDD)
381 pFirstLDD = NULL;
382 HeapFree(GetProcessHeap(), 0, pCurr);
384 return OK;
387 /***********************************************************************
388 * CtlDelLdd (SETUPX.37)
390 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
392 FIXME("(%d); - please report this!\n", ldid);
393 return SETUPX_DelLdd(ldid);
396 /***********************************************************************
397 * CtlFindLdd (SETUPX.35)
399 * doesn't check pldd ptr validity: crash (W98SE)
401 * RETURN
402 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
403 * 1 in all other cases ??
406 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
408 LDD_LIST *pCurr, *pPrev = NULL;
410 TRACE("(%p)\n", pldd);
412 if (!std_LDDs_done)
413 SETUPX_CreateStandardLDDs();
415 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
416 return ERR_VCP_LDDINVALID;
418 pCurr = pFirstLDD;
419 /* search until we find the appropriate LDD or hit the end */
420 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
422 pPrev = pCurr;
423 pCurr = pCurr->next;
425 if ( (pCurr == NULL) /* hit end of list */
426 || (pldd->ldid != pCurr->pldd->ldid) )
427 return ERR_VCP_LDDFIND; /* correct ? */
429 memcpy(pldd, pCurr->pldd, pldd->cbSize);
430 /* hmm, we probably ought to strcpy() the string ptrs here */
432 return 1; /* what is this ?? */
435 /***********************************************************************
436 * CtlSetLdd (SETUPX.33)
438 * Set an LDD entry.
440 * RETURN
441 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
444 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
446 LDD_LIST *pCurr, *pPrev = NULL;
447 LPLOGDISKDESC pCurrLDD;
448 HANDLE heap;
449 BOOL is_new = FALSE;
451 TRACE("(%p)\n", pldd);
453 if (!std_LDDs_done)
454 SETUPX_CreateStandardLDDs();
456 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
457 return ERR_VCP_LDDINVALID;
459 heap = GetProcessHeap();
460 pCurr = pFirstLDD;
461 /* search until we find the appropriate LDD or hit the end */
462 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
464 pPrev = pCurr;
465 pCurr = pCurr->next;
467 if (!pCurr || pldd->ldid != pCurr->pldd->ldid)
469 is_new = TRUE;
470 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
471 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
472 pCurr->next = NULL;
473 pCurrLDD = pCurr->pldd;
475 else
477 pCurrLDD = pCurr->pldd;
478 HeapFree(heap, 0, pCurrLDD->pszPath);
479 HeapFree(heap, 0, pCurrLDD->pszVolLabel);
480 HeapFree(heap, 0, pCurrLDD->pszDiskName);
483 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
485 if (pldd->pszPath)
487 pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
488 strcpy( pCurrLDD->pszPath, pldd->pszPath );
490 if (pldd->pszVolLabel)
492 pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
493 strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
495 if (pldd->pszDiskName)
497 pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
498 strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
501 if (is_new) /* link into list */
503 if (pPrev)
505 pCurr->next = pPrev->next;
506 pPrev->next = pCurr;
508 if (!pFirstLDD)
509 pFirstLDD = pCurr;
512 return OK;
516 /***********************************************************************
517 * CtlAddLdd (SETUPX.36)
519 * doesn't check pldd ptr validity: crash (W98SE)
522 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
523 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
525 pldd->ldid = ldid_to_add++;
526 return CtlSetLdd16(pldd);
529 /***********************************************************************
530 * CtlGetLdd (SETUPX.34)
532 * doesn't check pldd ptr validity: crash (W98SE)
533 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
535 * RETURN
536 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
539 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
541 LDD_LIST *pCurr, *pPrev = NULL;
543 if (!std_LDDs_done)
544 SETUPX_CreateStandardLDDs();
546 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
547 return ERR_VCP_LDDINVALID;
549 pCurr = pFirstLDD;
550 /* search until we find the appropriate LDD or hit the end */
551 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
553 pPrev = pCurr;
554 pCurr = pCurr->next;
556 if (pCurr == NULL) /* hit end of list */
557 return ERR_VCP_LDDFIND; /* correct ? */
559 memcpy(pldd, pCurr->pldd, pldd->cbSize);
560 /* hmm, we probably ought to strcpy() the string ptrs here */
562 return OK;
565 /**********************************************************************/
567 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
569 FIXME("(%p); - please report this!\n", pldd);
570 return SETUPX_GetLdd(pldd);
573 /***********************************************************************
574 * CtlGetLddPath (SETUPX.38)
576 * Gets the path of an LDD.
577 * No crash if szPath == NULL.
578 * szPath has to be at least MAX_PATH_LEN bytes long.
579 * RETURN
580 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
582 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
584 TRACE("(%d, %p);\n", ldid, szPath);
586 if (szPath)
588 LOGDISKDESC_S ldd;
589 INIT_LDD(ldd, ldid);
590 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
591 return ERR_VCP_LDDUNINIT;
592 SETUPX_GetLdd(&ldd);
593 strcpy(szPath, ldd.pszPath);
594 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
596 return OK;
599 /***********************************************************************
600 * CtlSetLddPath (SETUPX.508)
602 * Sets the path of an LDD.
603 * Creates LDD for LDID if not existing yet.
605 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
607 LOGDISKDESC_S ldd;
608 TRACE("(%d, '%s');\n", ldid, szPath);
610 SetupSetDirectoryIdA( 0, ldid, szPath );
611 INIT_LDD(ldd, ldid);
612 ldd.pszPath = szPath;
613 return CtlSetLdd16(&ldd);