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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
73 #include "setupapi_private.h"
75 #include "wine/debug.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
79 /***********************************************************************
80 * SURegOpenKey (SETUPX.47)
82 DWORD WINAPI
SURegOpenKey( HKEY hkey
, LPCSTR lpszSubKey
, PHKEY retkey
)
84 FIXME("(%p,%s,%p), semi-stub.\n",hkey
,debugstr_a(lpszSubKey
),retkey
);
85 return RegOpenKeyA( hkey
, lpszSubKey
, retkey
);
88 /***********************************************************************
89 * SURegQueryValueEx (SETUPX.50)
91 DWORD WINAPI
SURegQueryValueEx( HKEY hkey
, LPSTR lpszValueName
,
92 LPDWORD lpdwReserved
, LPDWORD lpdwType
,
93 LPBYTE lpbData
, LPDWORD lpcbData
)
95 FIXME("(%p,%s,%p,%p,%p,%ld), semi-stub.\n",hkey
,debugstr_a(lpszValueName
),
96 lpdwReserved
,lpdwType
,lpbData
,lpcbData
?*lpcbData
:0);
97 return RegQueryValueExA( hkey
, lpszValueName
, lpdwReserved
, lpdwType
,
102 * Returns pointer to a string list with the first entry being number
105 * Hmm. Should this be InitSubstrData(), GetFirstSubstr() and GetNextSubstr()
108 static LPSTR
*SETUPX_GetSubStrings(LPSTR start
, char delimiter
)
119 /* find beginning of real substring */
120 while ( (*p
== ' ') || (*p
== '\t') || (*p
== '"') ) p
++;
122 /* find end of real substring */
125 && (*q
!= ' ') && (*q
!= '\t') && (*q
!= '"')
126 && (*q
!= ';') && (*q
!= delimiter
) ) q
++;
129 len
= (int)q
- (int)p
;
131 /* alloc entry for new substring in steps of 32 units and copy over */
133 { /* 1 for count field + current count + 32 */
135 res
= HeapReAlloc(GetProcessHeap(), 0, res
, (1+count
+32)*sizeof(LPSTR
));
137 res
= HeapAlloc(GetProcessHeap(), 0, (1+count
+32)*sizeof(LPSTR
));
139 *(res
+1+count
) = HeapAlloc(GetProcessHeap(), 0, len
+1);
140 strncpy(*(res
+1+count
), p
, len
);
141 (*(res
+1+count
))[len
] = '\0';
144 /* we are still within last substring (before delimiter),
145 * so get out of it */
146 while ((*q
) && (*q
!= ';') && (*q
!= delimiter
)) q
++;
147 if ((!*q
) || (*q
== ';'))
152 /* put number of entries at beginning of list */
153 *(DWORD
*)res
= count
;
157 static void SETUPX_FreeSubStrings(LPSTR
*substr
)
159 DWORD count
= *(DWORD
*)substr
;
160 LPSTR
*pStrings
= substr
+1;
163 for (n
=0; n
< count
; n
++)
164 HeapFree(GetProcessHeap(), 0, *pStrings
++);
166 HeapFree(GetProcessHeap(), 0, substr
);
170 /***********************************************************************
171 * InstallHinfSection (SETUPX.527)
173 * hwnd = parent window
174 * hinst = instance of SETUPX.DLL
175 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
176 * Here "DefaultInstall" is the .inf file section to be installed (optional).
177 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
179 * nCmdShow = nCmdShow of CreateProcess
181 RETERR16 WINAPI
InstallHinfSection16( HWND16 hwnd
, HINSTANCE16 hinst
, LPCSTR lpszCmdLine
, INT16 nCmdShow
)
186 RETERR16 res
= OK
, tmp
;
190 TRACE("(%04x, %04x, %s, %d);\n", hwnd
, hinst
, lpszCmdLine
, nCmdShow
);
192 pSub
= SETUPX_GetSubStrings((LPSTR
)lpszCmdLine
, ' ');
194 count
= *(DWORD
*)pSub
;
195 if (count
< 2) /* invalid number of arguments ? */
197 if (IpOpen16(*(pSub
+count
), &hInf
) != OK
)
199 res
= ERROR_FILE_NOT_FOUND
; /* yes, correct */
202 if (VcpOpen16(NULL
, 0))
204 if (GenInstall16(hInf
, *(pSub
+count
-2), GENINSTALL_DO_ALL
) != OK
)
206 wFlags
= atoi(*(pSub
+count
-1)) & ~128;
209 case HOW_ALWAYS_SILENT_REBOOT
:
210 case HOW_SILENT_REBOOT
:
213 case HOW_ALWAYS_PROMPT_REBOOT
:
214 case HOW_PROMPT_REBOOT
:
215 if (MessageBoxA(HWND_32(hwnd
), "You must restart Wine before the new settings will take effect.\n\nDo you want to exit Wine now ?", "Systems Settings Change", MB_YESNO
|MB_ICONQUESTION
) == IDYES
)
219 ERR("invalid flags %d !\n", wFlags
);
225 tmp
= VcpClose16(VCPFL_ALL
, NULL
);
228 tmp
= IpClose16(hInf
);
231 SETUPX_FreeSubStrings(pSub
);
234 /* FIXME: we should have a means of terminating all wine + wineserver */
235 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
245 LPCSTR StdString
; /* fallback string; sub dir of windows directory */
248 static const LDID_DATA LDID_Data
[34] =
250 { /* 0 (LDID_NULL) -- not defined */
254 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
255 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
258 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
262 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
266 { /* 4 (LDID_BACKUP) = backup dir */
270 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
274 { /* 6 -- not defined */
278 { /* 7 -- not defined */
282 { /* 8 -- not defined */
286 { /* 9 -- not defined */
290 { /* 10 (LDID_WIN) = windows dir */
294 { /* 11 (LDID_SYS) = system dir */
296 NULL
/* call GetSystemDirectory() instead */
298 { /* 12 (LDID_IOS) = IOSubSys dir */
299 NULL
, /* FIXME: registry string ? */
302 { /* 13 (LDID_CMD) = COMMAND dir */
303 NULL
, /* FIXME: registry string ? */
306 { /* 14 (LDID_CPL) = control panel dir */
310 { /* 15 (LDID_PRINT) = windows printer dir */
312 "SYSTEM" /* correct ?? */
314 { /* 16 (LDID_MAIL) = destination mail dir */
318 { /* 17 (LDID_INF) = INF dir */
319 "SetupScratchDir", /* correct ? */
322 { /* 18 (LDID_HELP) = HELP dir */
326 { /* 19 (LDID_WINADMIN) = Admin dir */
330 { /* 20 (LDID_FONTS) = Fonts dir */
334 { /* 21 (LDID_VIEWERS) = Viewers */
338 { /* 22 (LDID_VMM32) = VMM32 dir */
342 { /* 23 (LDID_COLOR) = ICM dir */
346 { /* 24 (LDID_APPS) = root of boot drive ? */
350 { /* 25 (LDID_SHARED) = shared dir */
354 { /* 26 (LDID_WINBOOT) = Windows boot dir */
358 { /* 27 (LDID_MACHINE) = machine specific files */
362 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
366 { /* 29 -- not defined */
370 { /* 30 (LDID_BOOT) = Root of boot drive */
374 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
378 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
382 { /* 33 (LDID_OLD_WIN) = old win dir */
386 /* the rest (34-38) isn't too interesting, so I'll forget about it */
390 * LDD == Logical Device Descriptor
391 * LDID == Logical Device ID
393 * The whole LDD/LDID business might go into a separate file named
395 * At the moment I don't know what the hell these functions are really doing.
396 * That's why I added reporting stubs.
397 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
398 * That's why I implemented them in a way that's suitable for my purpose.
400 static LDD_LIST
*pFirstLDD
= NULL
;
402 static BOOL std_LDDs_done
= FALSE
;
404 void SETUPX_CreateStandardLDDs(void)
410 char buffer
[MAX_PATH
];
412 /* has to be here, otherwise loop */
413 std_LDDs_done
= TRUE
;
415 RegOpenKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey
);
417 for (n
=0; n
< sizeof(LDID_Data
)/sizeof(LDID_DATA
); n
++)
422 if ( (hKey
) && (LDID_Data
[n
].RegValName
)
423 && (RegQueryValueExA(hKey
, LDID_Data
[n
].RegValName
,
424 NULL
, &type
, buffer
, &len
) == ERROR_SUCCESS
)
425 && (type
== REG_SZ
) )
427 TRACE("found value '%s' for LDID %d\n", buffer
, n
);
433 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
434 strcpy(buffer
, "X:\\FIXME");
437 GetSystemDirectoryA(buffer
, MAX_PATH
);
441 case LDID_HOST_WINBOOT
:
444 strcpy(buffer
, "C:\\");
447 if (LDID_Data
[n
].StdString
)
449 DWORD len
= GetWindowsDirectoryA(buffer
, MAX_PATH
);
453 strcpy(p
, LDID_Data
[n
].StdString
);
460 ldd
.pszPath
= buffer
;
461 TRACE("LDID %d -> '%s'\n", ldd
.ldid
, ldd
.pszPath
);
465 if (hKey
) RegCloseKey(hKey
);
468 /***********************************************************************
469 * CtlDelLdd (SETUPX.37)
472 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
474 RETERR16
SETUPX_DelLdd(LOGDISKID16 ldid
)
476 LDD_LIST
*pCurr
, *pPrev
= NULL
;
478 TRACE("(%d)\n", ldid
);
481 SETUPX_CreateStandardLDDs();
483 if (ldid
< LDID_ASSIGN_START
)
484 return ERR_VCP_LDDINVALID
;
487 /* search until we find the appropriate LDD or hit the end */
488 while ((pCurr
!= NULL
) && (ldid
> pCurr
->pldd
->ldid
))
493 if ( (pCurr
== NULL
) /* hit end of list */
494 || (ldid
!= pCurr
->pldd
->ldid
) )
495 return ERR_VCP_LDDFIND
; /* correct ? */
497 /* ok, found our victim: eliminate it */
500 pPrev
->next
= pCurr
->next
;
502 if (pCurr
== pFirstLDD
)
504 HeapFree(GetProcessHeap(), 0, pCurr
);
509 /***********************************************************************
510 * CtlDelLdd (SETUPX.37)
512 RETERR16 WINAPI
CtlDelLdd16(LOGDISKID16 ldid
)
514 FIXME("(%d); - please report this!\n", ldid
);
515 return SETUPX_DelLdd(ldid
);
518 /***********************************************************************
519 * CtlFindLdd (SETUPX.35)
521 * doesn't check pldd ptr validity: crash (W98SE)
524 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
525 * 1 in all other cases ??
528 RETERR16 WINAPI
CtlFindLdd16(LPLOGDISKDESC pldd
)
530 LDD_LIST
*pCurr
, *pPrev
= NULL
;
532 TRACE("(%p)\n", pldd
);
535 SETUPX_CreateStandardLDDs();
537 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
538 return ERR_VCP_LDDINVALID
;
541 /* search until we find the appropriate LDD or hit the end */
542 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
547 if ( (pCurr
== NULL
) /* hit end of list */
548 || (pldd
->ldid
!= pCurr
->pldd
->ldid
) )
549 return ERR_VCP_LDDFIND
; /* correct ? */
551 memcpy(pldd
, pCurr
->pldd
, pldd
->cbSize
);
552 /* hmm, we probably ought to strcpy() the string ptrs here */
554 return 1; /* what is this ?? */
557 /***********************************************************************
558 * CtlSetLdd (SETUPX.33)
563 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
566 RETERR16 WINAPI
CtlSetLdd16(LPLOGDISKDESC pldd
)
568 LDD_LIST
*pCurr
, *pPrev
= NULL
;
569 LPLOGDISKDESC pCurrLDD
;
573 TRACE("(%p)\n", pldd
);
576 SETUPX_CreateStandardLDDs();
578 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
579 return ERR_VCP_LDDINVALID
;
581 heap
= GetProcessHeap();
583 /* search until we find the appropriate LDD or hit the end */
584 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
589 if (!pCurr
|| pldd
->ldid
!= pCurr
->pldd
->ldid
)
592 pCurr
= HeapAlloc(heap
, 0, sizeof(LDD_LIST
));
593 pCurr
->pldd
= HeapAlloc(heap
, 0, sizeof(LOGDISKDESC_S
));
595 pCurrLDD
= pCurr
->pldd
;
599 pCurrLDD
= pCurr
->pldd
;
600 if (pCurrLDD
->pszPath
) HeapFree(heap
, 0, pCurrLDD
->pszPath
);
601 if (pCurrLDD
->pszVolLabel
) HeapFree(heap
, 0, pCurrLDD
->pszVolLabel
);
602 if (pCurrLDD
->pszDiskName
) HeapFree(heap
, 0, pCurrLDD
->pszDiskName
);
605 memcpy(pCurrLDD
, pldd
, sizeof(LOGDISKDESC_S
));
609 pCurrLDD
->pszPath
= HeapAlloc( heap
, 0, strlen(pldd
->pszPath
)+1 );
610 strcpy( pCurrLDD
->pszPath
, pldd
->pszPath
);
612 if (pldd
->pszVolLabel
)
614 pCurrLDD
->pszVolLabel
= HeapAlloc( heap
, 0, strlen(pldd
->pszVolLabel
)+1 );
615 strcpy( pCurrLDD
->pszVolLabel
, pldd
->pszVolLabel
);
617 if (pldd
->pszDiskName
)
619 pCurrLDD
->pszDiskName
= HeapAlloc( heap
, 0, strlen(pldd
->pszDiskName
)+1 );
620 strcpy( pCurrLDD
->pszDiskName
, pldd
->pszDiskName
);
623 if (is_new
) /* link into list */
627 pCurr
->next
= pPrev
->next
;
638 /***********************************************************************
639 * CtlAddLdd (SETUPX.36)
641 * doesn't check pldd ptr validity: crash (W98SE)
644 static LOGDISKID16 ldid_to_add
= LDID_ASSIGN_START
;
645 RETERR16 WINAPI
CtlAddLdd16(LPLOGDISKDESC pldd
)
647 pldd
->ldid
= ldid_to_add
++;
648 return CtlSetLdd16(pldd
);
651 /***********************************************************************
652 * CtlGetLdd (SETUPX.34)
654 * doesn't check pldd ptr validity: crash (W98SE)
655 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
658 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
661 static RETERR16
SETUPX_GetLdd(LPLOGDISKDESC pldd
)
663 LDD_LIST
*pCurr
, *pPrev
= NULL
;
666 SETUPX_CreateStandardLDDs();
668 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
669 return ERR_VCP_LDDINVALID
;
672 /* search until we find the appropriate LDD or hit the end */
673 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
678 if (pCurr
== NULL
) /* hit end of list */
679 return ERR_VCP_LDDFIND
; /* correct ? */
681 memcpy(pldd
, pCurr
->pldd
, pldd
->cbSize
);
682 /* hmm, we probably ought to strcpy() the string ptrs here */
687 /**********************************************************************/
689 RETERR16 WINAPI
CtlGetLdd16(LPLOGDISKDESC pldd
)
691 FIXME("(%p); - please report this!\n", pldd
);
692 return SETUPX_GetLdd(pldd
);
695 /***********************************************************************
696 * CtlGetLddPath (SETUPX.38)
698 * Gets the path of an LDD.
699 * No crash if szPath == NULL.
700 * szPath has to be at least MAX_PATH_LEN bytes long.
702 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
704 RETERR16 WINAPI
CtlGetLddPath16(LOGDISKID16 ldid
, LPSTR szPath
)
706 TRACE("(%d, %p);\n", ldid
, szPath
);
712 if (CtlFindLdd16(&ldd
) == ERR_VCP_LDDFIND
)
713 return ERR_VCP_LDDUNINIT
;
715 strcpy(szPath
, ldd
.pszPath
);
716 TRACE("ret '%s' for LDID %d\n", szPath
, ldid
);
721 /***********************************************************************
722 * CtlSetLddPath (SETUPX.508)
724 * Sets the path of an LDD.
725 * Creates LDD for LDID if not existing yet.
727 RETERR16 WINAPI
CtlSetLddPath16(LOGDISKID16 ldid
, LPSTR szPath
)
730 TRACE("(%d, '%s');\n", ldid
, szPath
);
732 SetupSetDirectoryIdA( 0, ldid
, szPath
);
734 ldd
.pszPath
= szPath
;
735 return CtlSetLdd16(&ldd
);