msi: Read the disk prompt source list property from the user-unmanaged context.
[wine.git] / dlls / setupapi / setupx_main.c
blob9b12ff79b8673337d36456ecac38674d02fb01b6
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 "wownt32.h"
67 #include "winuser.h"
68 #include "winnls.h"
69 #include "setupapi.h"
70 #include "setupx16.h"
71 #include "setupapi_private.h"
72 #include "wine/debug.h"
74 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
76 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
78 /***********************************************************************
79 * SURegOpenKey (SETUPX.47)
81 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, PHKEY retkey )
83 FIXME("(%p,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
84 return RegOpenKeyA( hkey, lpszSubKey, retkey );
87 /***********************************************************************
88 * SURegQueryValueEx (SETUPX.50)
90 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
91 LPDWORD lpdwReserved, LPDWORD lpdwType,
92 LPBYTE lpbData, LPDWORD lpcbData )
94 FIXME("(%p,%s,%p,%p,%p,%d), semi-stub.\n",hkey,debugstr_a(lpszValueName),
95 lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
96 return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
97 lpbData, lpcbData );
101 /***********************************************************************
102 * InstallHinfSection (SETUPX.527)
104 * hwnd = parent window
105 * hinst = instance of SETUPX.DLL
106 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
107 * Here "DefaultInstall" is the .inf file section to be installed (optional).
108 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
110 * nCmdShow = nCmdShow of CreateProcess
112 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
114 InstallHinfSectionA( HWND_32(hwnd), HINSTANCE_32(hinst), lpszCmdLine, nCmdShow );
115 return OK;
118 typedef struct
120 LPCSTR RegValName;
121 LPCSTR StdString; /* fallback string; sub dir of windows directory */
122 } LDID_DATA;
124 static const LDID_DATA LDID_Data[34] =
126 { /* 0 (LDID_NULL) -- not defined */
127 NULL,
128 NULL
130 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
131 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
132 NULL
134 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
135 "SetupTempDir",
136 NULL
138 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
139 "UninstallDir",
140 NULL
142 { /* 4 (LDID_BACKUP) = backup dir */
143 "BackupDir",
144 NULL
146 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
147 "SetupScratchDir",
148 NULL
150 { /* 6 -- not defined */
151 NULL,
152 NULL
154 { /* 7 -- not defined */
155 NULL,
156 NULL
158 { /* 8 -- not defined */
159 NULL,
160 NULL
162 { /* 9 -- not defined */
163 NULL,
164 NULL
166 { /* 10 (LDID_WIN) = windows dir */
167 "WinDir",
170 { /* 11 (LDID_SYS) = system dir */
171 "SysDir",
172 NULL /* call GetSystemDirectory() instead */
174 { /* 12 (LDID_IOS) = IOSubSys dir */
175 NULL, /* FIXME: registry string ? */
176 "SYSTEM\\IOSUBSYS"
178 { /* 13 (LDID_CMD) = COMMAND dir */
179 NULL, /* FIXME: registry string ? */
180 "COMMAND"
182 { /* 14 (LDID_CPL) = control panel dir */
183 NULL,
186 { /* 15 (LDID_PRINT) = windows printer dir */
187 NULL,
188 "SYSTEM" /* correct ?? */
190 { /* 16 (LDID_MAIL) = destination mail dir */
191 NULL,
194 { /* 17 (LDID_INF) = INF dir */
195 "SetupScratchDir", /* correct ? */
196 "INF"
198 { /* 18 (LDID_HELP) = HELP dir */
199 NULL, /* ??? */
200 "HELP"
202 { /* 19 (LDID_WINADMIN) = Admin dir */
203 "WinAdminDir",
206 { /* 20 (LDID_FONTS) = Fonts dir */
207 NULL, /* ??? */
208 "FONTS"
210 { /* 21 (LDID_VIEWERS) = Viewers */
211 NULL, /* ??? */
212 "SYSTEM\\VIEWERS"
214 { /* 22 (LDID_VMM32) = VMM32 dir */
215 NULL, /* ??? */
216 "SYSTEM\\VMM32"
218 { /* 23 (LDID_COLOR) = ICM dir */
219 "ICMPath",
220 "SYSTEM\\COLOR"
222 { /* 24 (LDID_APPS) = root of boot drive ? */
223 "AppsDir",
224 "C:\\"
226 { /* 25 (LDID_SHARED) = shared dir */
227 "SharedDir",
230 { /* 26 (LDID_WINBOOT) = Windows boot dir */
231 "WinBootDir",
234 { /* 27 (LDID_MACHINE) = machine specific files */
235 "MachineDir",
236 NULL
238 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
239 "HostWinBootDir",
240 NULL
242 { /* 29 -- not defined */
243 NULL,
244 NULL
246 { /* 30 (LDID_BOOT) = Root of boot drive */
247 "BootDir",
248 NULL
250 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
251 "BootHost",
252 NULL
254 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
255 "OldWinBootDir",
256 NULL
258 { /* 33 (LDID_OLD_WIN) = old win dir */
259 "OldWinDir",
260 NULL
262 /* the rest (34-38) isn't too interesting, so I'll forget about it */
266 * LDD == Logical Device Descriptor
267 * LDID == Logical Device ID
269 * The whole LDD/LDID business might go into a separate file named
270 * ldd.c.
271 * At the moment I don't know what the hell these functions are really doing.
272 * That's why I added reporting stubs.
273 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
274 * That's why I implemented them in a way that's suitable for my purpose.
276 static LDD_LIST *pFirstLDD = NULL;
278 static BOOL std_LDDs_done = FALSE;
280 static void SETUPX_CreateStandardLDDs(void)
282 HKEY hKey = 0;
283 WORD n;
284 DWORD type, len;
285 LOGDISKDESC_S ldd;
286 char buffer[MAX_PATH];
288 /* has to be here, otherwise loop */
289 std_LDDs_done = TRUE;
291 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
293 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
295 buffer[0] = '\0';
297 len = MAX_PATH;
298 if ( (hKey) && (LDID_Data[n].RegValName)
299 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
300 NULL, &type, (LPBYTE)buffer, &len) == ERROR_SUCCESS)
301 && (type == REG_SZ) )
303 TRACE("found value '%s' for LDID %d\n", buffer, n);
305 else
306 switch(n)
308 case LDID_SRCPATH:
309 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
310 strcpy(buffer, "X:\\FIXME");
311 break;
312 case LDID_SYS:
313 GetSystemDirectoryA(buffer, MAX_PATH);
314 break;
315 case LDID_APPS:
316 case LDID_MACHINE:
317 case LDID_HOST_WINBOOT:
318 case LDID_BOOT:
319 case LDID_BOOT_HOST:
320 strcpy(buffer, "C:\\");
321 break;
322 default:
323 if (LDID_Data[n].StdString)
325 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
326 LPSTR p;
327 p = buffer + len;
328 *p++ = '\\';
329 strcpy(p, LDID_Data[n].StdString);
331 break;
333 if (buffer[0])
335 INIT_LDD(ldd, n);
336 ldd.pszPath = buffer;
337 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
338 CtlSetLdd16(&ldd);
341 if (hKey) RegCloseKey(hKey);
344 /***********************************************************************
345 * CtlDelLdd (SETUPX.37)
347 * RETURN
348 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
350 static RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
352 LDD_LIST *pCurr, *pPrev = NULL;
354 TRACE("(%d)\n", ldid);
356 if (!std_LDDs_done)
357 SETUPX_CreateStandardLDDs();
359 if (ldid < LDID_ASSIGN_START)
360 return ERR_VCP_LDDINVALID;
362 pCurr = pFirstLDD;
363 /* search until we find the appropriate LDD or hit the end */
364 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
366 pPrev = pCurr;
367 pCurr = pCurr->next;
369 if ( (pCurr == NULL) /* hit end of list */
370 || (ldid != pCurr->pldd->ldid) )
371 return ERR_VCP_LDDFIND; /* correct ? */
373 /* ok, found our victim: eliminate it */
375 if (pPrev)
376 pPrev->next = pCurr->next;
378 if (pCurr == pFirstLDD)
379 pFirstLDD = NULL;
380 HeapFree(GetProcessHeap(), 0, pCurr);
382 return OK;
385 /***********************************************************************
386 * CtlDelLdd (SETUPX.37)
388 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
390 FIXME("(%d); - please report this!\n", ldid);
391 return SETUPX_DelLdd(ldid);
394 /***********************************************************************
395 * CtlFindLdd (SETUPX.35)
397 * doesn't check pldd ptr validity: crash (W98SE)
399 * RETURN
400 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
401 * 1 in all other cases ??
404 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
406 LDD_LIST *pCurr, *pPrev = NULL;
408 TRACE("(%p)\n", pldd);
410 if (!std_LDDs_done)
411 SETUPX_CreateStandardLDDs();
413 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
414 return ERR_VCP_LDDINVALID;
416 pCurr = pFirstLDD;
417 /* search until we find the appropriate LDD or hit the end */
418 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
420 pPrev = pCurr;
421 pCurr = pCurr->next;
423 if ( (pCurr == NULL) /* hit end of list */
424 || (pldd->ldid != pCurr->pldd->ldid) )
425 return ERR_VCP_LDDFIND; /* correct ? */
427 memcpy(pldd, pCurr->pldd, pldd->cbSize);
428 /* hmm, we probably ought to strcpy() the string ptrs here */
430 return 1; /* what is this ?? */
433 /***********************************************************************
434 * CtlSetLdd (SETUPX.33)
436 * Set an LDD entry.
438 * RETURN
439 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
442 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
444 LDD_LIST *pCurr, *pPrev = NULL;
445 LPLOGDISKDESC pCurrLDD;
446 HANDLE heap;
447 BOOL is_new = FALSE;
449 TRACE("(%p)\n", pldd);
451 if (!std_LDDs_done)
452 SETUPX_CreateStandardLDDs();
454 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
455 return ERR_VCP_LDDINVALID;
457 heap = GetProcessHeap();
458 pCurr = pFirstLDD;
459 /* search until we find the appropriate LDD or hit the end */
460 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
462 pPrev = pCurr;
463 pCurr = pCurr->next;
465 if (!pCurr || pldd->ldid != pCurr->pldd->ldid)
467 is_new = TRUE;
468 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
469 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
470 pCurr->next = NULL;
471 pCurrLDD = pCurr->pldd;
473 else
475 pCurrLDD = pCurr->pldd;
476 HeapFree(heap, 0, pCurrLDD->pszPath);
477 HeapFree(heap, 0, pCurrLDD->pszVolLabel);
478 HeapFree(heap, 0, pCurrLDD->pszDiskName);
481 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
483 if (pldd->pszPath)
485 pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
486 strcpy( pCurrLDD->pszPath, pldd->pszPath );
488 if (pldd->pszVolLabel)
490 pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
491 strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
493 if (pldd->pszDiskName)
495 pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
496 strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
499 if (is_new) /* link into list */
501 if (pPrev)
503 pCurr->next = pPrev->next;
504 pPrev->next = pCurr;
506 if (!pFirstLDD)
507 pFirstLDD = pCurr;
510 return OK;
514 /***********************************************************************
515 * CtlAddLdd (SETUPX.36)
517 * doesn't check pldd ptr validity: crash (W98SE)
520 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
521 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
523 pldd->ldid = ldid_to_add++;
524 return CtlSetLdd16(pldd);
527 /***********************************************************************
528 * CtlGetLdd (SETUPX.34)
530 * doesn't check pldd ptr validity: crash (W98SE)
531 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
533 * RETURN
534 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
537 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
539 LDD_LIST *pCurr, *pPrev = NULL;
541 if (!std_LDDs_done)
542 SETUPX_CreateStandardLDDs();
544 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
545 return ERR_VCP_LDDINVALID;
547 pCurr = pFirstLDD;
548 /* search until we find the appropriate LDD or hit the end */
549 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
551 pPrev = pCurr;
552 pCurr = pCurr->next;
554 if (pCurr == NULL) /* hit end of list */
555 return ERR_VCP_LDDFIND; /* correct ? */
557 memcpy(pldd, pCurr->pldd, pldd->cbSize);
558 /* hmm, we probably ought to strcpy() the string ptrs here */
560 return OK;
563 /**********************************************************************/
565 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
567 FIXME("(%p); - please report this!\n", pldd);
568 return SETUPX_GetLdd(pldd);
571 /***********************************************************************
572 * CtlGetLddPath (SETUPX.38)
574 * Gets the path of an LDD.
575 * No crash if szPath == NULL.
576 * szPath has to be at least MAX_PATH_LEN bytes long.
577 * RETURN
578 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
580 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
582 TRACE("(%d, %p);\n", ldid, szPath);
584 if (szPath)
586 LOGDISKDESC_S ldd;
587 INIT_LDD(ldd, ldid);
588 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
589 return ERR_VCP_LDDUNINIT;
590 SETUPX_GetLdd(&ldd);
591 strcpy(szPath, ldd.pszPath);
592 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
594 return OK;
597 /***********************************************************************
598 * CtlSetLddPath (SETUPX.508)
600 * Sets the path of an LDD.
601 * Creates LDD for LDID if not existing yet.
603 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
605 LOGDISKDESC_S ldd;
606 TRACE("(%d, '%s');\n", ldid, szPath);
608 SetupSetDirectoryIdA( 0, ldid, szPath );
609 INIT_LDD(ldd, ldid);
610 ldd.pszPath = szPath;
611 return CtlSetLdd16(&ldd);