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.
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
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
32 * - rs405deu.exe (German Acroread 4.05 setup)
37 * - string handling is... weird ;) (buflen etc.)
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 ?)
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 ;-)
66 #include "wine/winuser16.h"
72 #include "setupapi_private.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,
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 );
123 LPCSTR StdString; /* fallback string; sub dir of windows directory */
126 static const LDID_DATA LDID_Data[34] =
128 { /* 0 (LDID_NULL) -- not defined */
132 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
133 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
136 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
140 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
144 { /* 4 (LDID_BACKUP) = backup dir */
148 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
152 { /* 6 -- not defined */
156 { /* 7 -- not defined */
160 { /* 8 -- not defined */
164 { /* 9 -- not defined */
168 { /* 10 (LDID_WIN) = windows dir */
172 { /* 11 (LDID_SYS) = system dir */
174 NULL /* call GetSystemDirectory() instead */
176 { /* 12 (LDID_IOS) = IOSubSys dir */
177 NULL, /* FIXME: registry string ? */
180 { /* 13 (LDID_CMD) = COMMAND dir */
181 NULL, /* FIXME: registry string ? */
184 { /* 14 (LDID_CPL) = control panel dir */
188 { /* 15 (LDID_PRINT) = windows printer dir */
190 "SYSTEM" /* correct ?? */
192 { /* 16 (LDID_MAIL) = destination mail dir */
196 { /* 17 (LDID_INF) = INF dir */
197 "SetupScratchDir", /* correct ? */
200 { /* 18 (LDID_HELP) = HELP dir */
204 { /* 19 (LDID_WINADMIN) = Admin dir */
208 { /* 20 (LDID_FONTS) = Fonts dir */
212 { /* 21 (LDID_VIEWERS) = Viewers */
216 { /* 22 (LDID_VMM32) = VMM32 dir */
220 { /* 23 (LDID_COLOR) = ICM dir */
224 { /* 24 (LDID_APPS) = root of boot drive ? */
228 { /* 25 (LDID_SHARED) = shared dir */
232 { /* 26 (LDID_WINBOOT) = Windows boot dir */
236 { /* 27 (LDID_MACHINE) = machine specific files */
240 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
244 { /* 29 -- not defined */
248 { /* 30 (LDID_BOOT) = Root of boot drive */
252 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
256 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
260 { /* 33 (LDID_OLD_WIN) = old win dir */
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
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)
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++)
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);
311 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
312 strcpy(buffer, "X:\\FIXME");
315 GetSystemDirectoryA(buffer, MAX_PATH);
319 case LDID_HOST_WINBOOT:
322 strcpy(buffer, "C:\\");
325 if (LDID_Data[n].StdString)
327 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
331 strcpy(p, LDID_Data[n].StdString);
338 ldd.pszPath = buffer;
339 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
343 if (hKey) RegCloseKey(hKey);
346 /***********************************************************************
347 * CtlDelLdd (SETUPX.37)
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);
359 SETUPX_CreateStandardLDDs();
361 if (ldid < LDID_ASSIGN_START)
362 return ERR_VCP_LDDINVALID;
365 /* search until we find the appropriate LDD or hit the end */
366 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
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 */
378 pPrev->next = pCurr->next;
380 if (pCurr == pFirstLDD)
382 HeapFree(GetProcessHeap(), 0, pCurr);
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)
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);
413 SETUPX_CreateStandardLDDs();
415 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
416 return ERR_VCP_LDDINVALID;
419 /* search until we find the appropriate LDD or hit the end */
420 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
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)
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;
451 TRACE("(%p)\n", pldd);
454 SETUPX_CreateStandardLDDs();
456 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
457 return ERR_VCP_LDDINVALID;
459 heap = GetProcessHeap();
461 /* search until we find the appropriate LDD or hit the end */
462 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
467 if (!pCurr || pldd->ldid != pCurr->pldd->ldid)
470 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
471 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
473 pCurrLDD = pCurr->pldd;
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));
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 */
505 pCurr->next = pPrev->next;
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() ??
536 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
539 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
541 LDD_LIST *pCurr, *pPrev = NULL;
544 SETUPX_CreateStandardLDDs();
546 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
547 return ERR_VCP_LDDINVALID;
550 /* search until we find the appropriate LDD or hit the end */
551 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
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 */
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.
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);
590 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
591 return ERR_VCP_LDDUNINIT;
593 strcpy(szPath, ldd.pszPath);
594 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
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)
608 TRACE("(%d, '%s');\n", ldid, szPath);
610 SetupSetDirectoryIdA( 0, ldid, szPath );
612 ldd.pszPath = szPath;
613 return CtlSetLdd16(&ldd);