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 ;-)
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
,
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
);
121 LPCSTR StdString
; /* fallback string; sub dir of windows directory */
124 static const LDID_DATA LDID_Data
[34] =
126 { /* 0 (LDID_NULL) -- not defined */
130 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
131 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
134 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
138 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
142 { /* 4 (LDID_BACKUP) = backup dir */
146 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
150 { /* 6 -- not defined */
154 { /* 7 -- not defined */
158 { /* 8 -- not defined */
162 { /* 9 -- not defined */
166 { /* 10 (LDID_WIN) = windows dir */
170 { /* 11 (LDID_SYS) = system dir */
172 NULL
/* call GetSystemDirectory() instead */
174 { /* 12 (LDID_IOS) = IOSubSys dir */
175 NULL
, /* FIXME: registry string ? */
178 { /* 13 (LDID_CMD) = COMMAND dir */
179 NULL
, /* FIXME: registry string ? */
182 { /* 14 (LDID_CPL) = control panel dir */
186 { /* 15 (LDID_PRINT) = windows printer dir */
188 "SYSTEM" /* correct ?? */
190 { /* 16 (LDID_MAIL) = destination mail dir */
194 { /* 17 (LDID_INF) = INF dir */
195 "SetupScratchDir", /* correct ? */
198 { /* 18 (LDID_HELP) = HELP dir */
202 { /* 19 (LDID_WINADMIN) = Admin dir */
206 { /* 20 (LDID_FONTS) = Fonts dir */
210 { /* 21 (LDID_VIEWERS) = Viewers */
214 { /* 22 (LDID_VMM32) = VMM32 dir */
218 { /* 23 (LDID_COLOR) = ICM dir */
222 { /* 24 (LDID_APPS) = root of boot drive ? */
226 { /* 25 (LDID_SHARED) = shared dir */
230 { /* 26 (LDID_WINBOOT) = Windows boot dir */
234 { /* 27 (LDID_MACHINE) = machine specific files */
238 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
242 { /* 29 -- not defined */
246 { /* 30 (LDID_BOOT) = Root of boot drive */
250 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
254 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
258 { /* 33 (LDID_OLD_WIN) = old win dir */
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
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)
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
++)
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
);
309 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
310 strcpy(buffer
, "X:\\FIXME");
313 GetSystemDirectoryA(buffer
, MAX_PATH
);
317 case LDID_HOST_WINBOOT
:
320 strcpy(buffer
, "C:\\");
323 if (LDID_Data
[n
].StdString
)
325 DWORD len
= GetWindowsDirectoryA(buffer
, MAX_PATH
);
329 strcpy(p
, LDID_Data
[n
].StdString
);
336 ldd
.pszPath
= buffer
;
337 TRACE("LDID %d -> '%s'\n", ldd
.ldid
, ldd
.pszPath
);
341 if (hKey
) RegCloseKey(hKey
);
344 /***********************************************************************
345 * CtlDelLdd (SETUPX.37)
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
);
357 SETUPX_CreateStandardLDDs();
359 if (ldid
< LDID_ASSIGN_START
)
360 return ERR_VCP_LDDINVALID
;
363 /* search until we find the appropriate LDD or hit the end */
364 while ((pCurr
!= NULL
) && (ldid
> pCurr
->pldd
->ldid
))
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 */
376 pPrev
->next
= pCurr
->next
;
378 if (pCurr
== pFirstLDD
)
380 HeapFree(GetProcessHeap(), 0, pCurr
);
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)
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
);
411 SETUPX_CreateStandardLDDs();
413 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
414 return ERR_VCP_LDDINVALID
;
417 /* search until we find the appropriate LDD or hit the end */
418 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
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)
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
;
449 TRACE("(%p)\n", pldd
);
452 SETUPX_CreateStandardLDDs();
454 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
455 return ERR_VCP_LDDINVALID
;
457 heap
= GetProcessHeap();
459 /* search until we find the appropriate LDD or hit the end */
460 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
465 if (!pCurr
|| pldd
->ldid
!= pCurr
->pldd
->ldid
)
468 pCurr
= HeapAlloc(heap
, 0, sizeof(LDD_LIST
));
469 pCurr
->pldd
= HeapAlloc(heap
, 0, sizeof(LOGDISKDESC_S
));
471 pCurrLDD
= pCurr
->pldd
;
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
));
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 */
503 pCurr
->next
= pPrev
->next
;
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() ??
534 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
537 static RETERR16
SETUPX_GetLdd(LPLOGDISKDESC pldd
)
539 LDD_LIST
*pCurr
, *pPrev
= NULL
;
542 SETUPX_CreateStandardLDDs();
544 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
545 return ERR_VCP_LDDINVALID
;
548 /* search until we find the appropriate LDD or hit the end */
549 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
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 */
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.
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
);
588 if (CtlFindLdd16(&ldd
) == ERR_VCP_LDDFIND
)
589 return ERR_VCP_LDDUNINIT
;
591 strcpy(szPath
, ldd
.pszPath
);
592 TRACE("ret '%s' for LDID %d\n", szPath
, ldid
);
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
)
606 TRACE("(%d, '%s');\n", ldid
, szPath
);
608 SetupSetDirectoryIdA( 0, ldid
, szPath
);
610 ldd
.pszPath
= szPath
;
611 return CtlSetLdd16(&ldd
);