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 ;-)
63 #include "wine/winuser16.h"
67 #include "setupapi_private.h"
69 #include "wine/debug.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
73 /***********************************************************************
74 * SURegOpenKey (SETUPX.47)
76 DWORD WINAPI
SURegOpenKey( HKEY hkey
, LPCSTR lpszSubKey
, PHKEY retkey
)
78 FIXME("(%p,%s,%p), semi-stub.\n",hkey
,debugstr_a(lpszSubKey
),retkey
);
79 return RegOpenKeyA( hkey
, lpszSubKey
, retkey
);
82 /***********************************************************************
83 * SURegQueryValueEx (SETUPX.50)
85 DWORD WINAPI
SURegQueryValueEx( HKEY hkey
, LPSTR lpszValueName
,
86 LPDWORD lpdwReserved
, LPDWORD lpdwType
,
87 LPBYTE lpbData
, LPDWORD lpcbData
)
89 FIXME("(%p,%s,%p,%p,%p,%ld), semi-stub.\n",hkey
,debugstr_a(lpszValueName
),
90 lpdwReserved
,lpdwType
,lpbData
,lpcbData
?*lpcbData
:0);
91 return RegQueryValueExA( hkey
, lpszValueName
, lpdwReserved
, lpdwType
,
96 * Returns pointer to a string list with the first entry being number
99 * Hmm. Should this be InitSubstrData(), GetFirstSubstr() and GetNextSubstr()
102 static LPSTR
*SETUPX_GetSubStrings(LPSTR start
, char delimiter
)
113 /* find beginning of real substring */
114 while ( (*p
== ' ') || (*p
== '\t') || (*p
== '"') ) p
++;
116 /* find end of real substring */
119 && (*q
!= ' ') && (*q
!= '\t') && (*q
!= '"')
120 && (*q
!= ';') && (*q
!= delimiter
) ) q
++;
123 len
= (int)q
- (int)p
;
125 /* alloc entry for new substring in steps of 32 units and copy over */
127 { /* 1 for count field + current count + 32 */
128 res
= HeapReAlloc(GetProcessHeap(), 0, res
, (1+count
+32)*sizeof(LPSTR
));
130 *(res
+1+count
) = HeapAlloc(GetProcessHeap(), 0, len
+1);
131 strncpy(*(res
+1+count
), p
, len
);
132 (*(res
+1+count
))[len
] = '\0';
135 /* we are still within last substring (before delimiter),
136 * so get out of it */
137 while ((*q
) && (*q
!= ';') && (*q
!= delimiter
)) q
++;
138 if ((!*q
) || (*q
== ';'))
143 /* put number of entries at beginning of list */
144 *(DWORD
*)res
= count
;
148 static void SETUPX_FreeSubStrings(LPSTR
*substr
)
150 DWORD count
= *(DWORD
*)substr
;
151 LPSTR
*pStrings
= substr
+1;
154 for (n
=0; n
< count
; n
++)
155 HeapFree(GetProcessHeap(), 0, *pStrings
++);
157 HeapFree(GetProcessHeap(), 0, substr
);
161 /***********************************************************************
162 * InstallHinfSection (SETUPX.527)
164 * hwnd = parent window
165 * hinst = instance of SETUPX.DLL
166 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
167 * Here "DefaultInstall" is the .inf file section to be installed (optional).
168 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
170 * nCmdShow = nCmdShow of CreateProcess
172 RETERR16 WINAPI
InstallHinfSection16( HWND16 hwnd
, HINSTANCE16 hinst
, LPCSTR lpszCmdLine
, INT16 nCmdShow
)
177 RETERR16 res
= OK
, tmp
;
181 TRACE("(%04x, %04x, %s, %d);\n", hwnd
, hinst
, lpszCmdLine
, nCmdShow
);
183 pSub
= SETUPX_GetSubStrings((LPSTR
)lpszCmdLine
, ' ');
185 count
= *(DWORD
*)pSub
;
186 if (count
< 2) /* invalid number of arguments ? */
188 if (IpOpen16(*(pSub
+count
), &hInf
) != OK
)
190 res
= ERROR_FILE_NOT_FOUND
; /* yes, correct */
193 if (VcpOpen16(NULL
, 0))
195 if (GenInstall16(hInf
, *(pSub
+count
-2), GENINSTALL_DO_ALL
) != OK
)
197 wFlags
= atoi(*(pSub
+count
-1)) & ~128;
200 case HOW_ALWAYS_SILENT_REBOOT
:
201 case HOW_SILENT_REBOOT
:
204 case HOW_ALWAYS_PROMPT_REBOOT
:
205 case HOW_PROMPT_REBOOT
:
206 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
)
210 ERR("invalid flags %d !\n", wFlags
);
216 tmp
= VcpClose16(VCPFL_ALL
, NULL
);
219 tmp
= IpClose16(hInf
);
222 SETUPX_FreeSubStrings(pSub
);
225 /* FIXME: we should have a means of terminating all wine + wineserver */
226 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
236 LPCSTR StdString
; /* fallback string; sub dir of windows directory */
239 static const LDID_DATA LDID_Data
[34] =
241 { /* 0 (LDID_NULL) -- not defined */
245 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
246 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
249 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
253 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
257 { /* 4 (LDID_BACKUP) = backup dir */
261 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
265 { /* 6 -- not defined */
269 { /* 7 -- not defined */
273 { /* 8 -- not defined */
277 { /* 9 -- not defined */
281 { /* 10 (LDID_WIN) = windows dir */
285 { /* 11 (LDID_SYS) = system dir */
287 NULL
/* call GetSystemDirectory() instead */
289 { /* 12 (LDID_IOS) = IOSubSys dir */
290 NULL
, /* FIXME: registry string ? */
293 { /* 13 (LDID_CMD) = COMMAND dir */
294 NULL
, /* FIXME: registry string ? */
297 { /* 14 (LDID_CPL) = control panel dir */
301 { /* 15 (LDID_PRINT) = windows printer dir */
303 "SYSTEM" /* correct ?? */
305 { /* 16 (LDID_MAIL) = destination mail dir */
309 { /* 17 (LDID_INF) = INF dir */
310 "SetupScratchDir", /* correct ? */
313 { /* 18 (LDID_HELP) = HELP dir */
317 { /* 19 (LDID_WINADMIN) = Admin dir */
321 { /* 20 (LDID_FONTS) = Fonts dir */
325 { /* 21 (LDID_VIEWERS) = Viewers */
329 { /* 22 (LDID_VMM32) = VMM32 dir */
333 { /* 23 (LDID_COLOR) = ICM dir */
337 { /* 24 (LDID_APPS) = root of boot drive ? */
341 { /* 25 (LDID_SHARED) = shared dir */
345 { /* 26 (LDID_WINBOOT) = Windows boot dir */
349 { /* 27 (LDID_MACHINE) = machine specific files */
353 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
357 { /* 29 -- not defined */
361 { /* 30 (LDID_BOOT) = Root of boot drive */
365 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
369 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
373 { /* 33 (LDID_OLD_WIN) = old win dir */
377 /* the rest (34-38) isn't too interesting, so I'll forget about it */
381 * LDD == Logical Device Descriptor
382 * LDID == Logical Device ID
384 * The whole LDD/LDID business might go into a separate file named
386 * At the moment I don't know what the hell these functions are really doing.
387 * That's why I added reporting stubs.
388 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
389 * That's why I implemented them in a way that's suitable for my purpose.
391 static LDD_LIST
*pFirstLDD
= NULL
;
393 static BOOL std_LDDs_done
= FALSE
;
395 void SETUPX_CreateStandardLDDs(void)
401 char buffer
[MAX_PATH
];
403 /* has to be here, otherwise loop */
404 std_LDDs_done
= TRUE
;
406 RegOpenKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey
);
408 for (n
=0; n
< sizeof(LDID_Data
)/sizeof(LDID_DATA
); n
++)
413 if ( (hKey
) && (LDID_Data
[n
].RegValName
)
414 && (RegQueryValueExA(hKey
, LDID_Data
[n
].RegValName
,
415 NULL
, &type
, buffer
, &len
) == ERROR_SUCCESS
)
416 && (type
== REG_SZ
) )
418 TRACE("found value '%s' for LDID %d\n", buffer
, n
);
424 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
425 strcpy(buffer
, "X:\\FIXME");
428 GetSystemDirectoryA(buffer
, MAX_PATH
);
432 case LDID_HOST_WINBOOT
:
435 strcpy(buffer
, "C:\\");
438 if (LDID_Data
[n
].StdString
)
440 DWORD len
= GetWindowsDirectoryA(buffer
, MAX_PATH
);
444 strcpy(p
, LDID_Data
[n
].StdString
);
451 ldd
.pszPath
= buffer
;
452 TRACE("LDID %d -> '%s'\n", ldd
.ldid
, ldd
.pszPath
);
456 if (hKey
) RegCloseKey(hKey
);
459 /***********************************************************************
460 * CtlDelLdd (SETUPX.37)
463 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
465 RETERR16
SETUPX_DelLdd(LOGDISKID16 ldid
)
467 LDD_LIST
*pCurr
, *pPrev
= NULL
;
469 TRACE("(%d)\n", ldid
);
472 SETUPX_CreateStandardLDDs();
474 if (ldid
< LDID_ASSIGN_START
)
475 return ERR_VCP_LDDINVALID
;
478 /* search until we find the appropriate LDD or hit the end */
479 while ((pCurr
!= NULL
) && (ldid
> pCurr
->pldd
->ldid
))
484 if ( (pCurr
== NULL
) /* hit end of list */
485 || (ldid
!= pCurr
->pldd
->ldid
) )
486 return ERR_VCP_LDDFIND
; /* correct ? */
488 /* ok, found our victim: eliminate it */
491 pPrev
->next
= pCurr
->next
;
493 if (pCurr
== pFirstLDD
)
495 HeapFree(GetProcessHeap(), 0, pCurr
);
500 /***********************************************************************
501 * CtlDelLdd (SETUPX.37)
503 RETERR16 WINAPI
CtlDelLdd16(LOGDISKID16 ldid
)
505 FIXME("(%d); - please report this!\n", ldid
);
506 return SETUPX_DelLdd(ldid
);
509 /***********************************************************************
510 * CtlFindLdd (SETUPX.35)
512 * doesn't check pldd ptr validity: crash (W98SE)
515 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
516 * 1 in all other cases ??
519 RETERR16 WINAPI
CtlFindLdd16(LPLOGDISKDESC pldd
)
521 LDD_LIST
*pCurr
, *pPrev
= NULL
;
523 TRACE("(%p)\n", pldd
);
526 SETUPX_CreateStandardLDDs();
528 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
529 return ERR_VCP_LDDINVALID
;
532 /* search until we find the appropriate LDD or hit the end */
533 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
538 if ( (pCurr
== NULL
) /* hit end of list */
539 || (pldd
->ldid
!= pCurr
->pldd
->ldid
) )
540 return ERR_VCP_LDDFIND
; /* correct ? */
542 memcpy(pldd
, pCurr
->pldd
, pldd
->cbSize
);
543 /* hmm, we probably ought to strcpy() the string ptrs here */
545 return 1; /* what is this ?? */
548 /***********************************************************************
549 * CtlSetLdd (SETUPX.33)
554 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
557 RETERR16 WINAPI
CtlSetLdd16(LPLOGDISKDESC pldd
)
559 LDD_LIST
*pCurr
, *pPrev
= NULL
;
560 LPLOGDISKDESC pCurrLDD
;
564 TRACE("(%p)\n", pldd
);
567 SETUPX_CreateStandardLDDs();
569 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
570 return ERR_VCP_LDDINVALID
;
572 heap
= GetProcessHeap();
574 /* search until we find the appropriate LDD or hit the end */
575 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
580 if (!pCurr
|| pldd
->ldid
!= pCurr
->pldd
->ldid
)
583 pCurr
= HeapAlloc(heap
, 0, sizeof(LDD_LIST
));
584 pCurr
->pldd
= HeapAlloc(heap
, 0, sizeof(LOGDISKDESC_S
));
586 pCurrLDD
= pCurr
->pldd
;
590 pCurrLDD
= pCurr
->pldd
;
591 if (pCurrLDD
->pszPath
) HeapFree(heap
, 0, pCurrLDD
->pszPath
);
592 if (pCurrLDD
->pszVolLabel
) HeapFree(heap
, 0, pCurrLDD
->pszVolLabel
);
593 if (pCurrLDD
->pszDiskName
) HeapFree(heap
, 0, pCurrLDD
->pszDiskName
);
596 memcpy(pCurrLDD
, pldd
, sizeof(LOGDISKDESC_S
));
600 pCurrLDD
->pszPath
= HeapAlloc( heap
, 0, strlen(pldd
->pszPath
)+1 );
601 strcpy( pCurrLDD
->pszPath
, pldd
->pszPath
);
603 if (pldd
->pszVolLabel
)
605 pCurrLDD
->pszVolLabel
= HeapAlloc( heap
, 0, strlen(pldd
->pszVolLabel
)+1 );
606 strcpy( pCurrLDD
->pszVolLabel
, pldd
->pszVolLabel
);
608 if (pldd
->pszDiskName
)
610 pCurrLDD
->pszDiskName
= HeapAlloc( heap
, 0, strlen(pldd
->pszDiskName
)+1 );
611 strcpy( pCurrLDD
->pszDiskName
, pldd
->pszDiskName
);
614 if (is_new
) /* link into list */
618 pCurr
->next
= pPrev
->next
;
629 /***********************************************************************
630 * CtlAddLdd (SETUPX.36)
632 * doesn't check pldd ptr validity: crash (W98SE)
635 static LOGDISKID16 ldid_to_add
= LDID_ASSIGN_START
;
636 RETERR16 WINAPI
CtlAddLdd16(LPLOGDISKDESC pldd
)
638 pldd
->ldid
= ldid_to_add
++;
639 return CtlSetLdd16(pldd
);
642 /***********************************************************************
643 * CtlGetLdd (SETUPX.34)
645 * doesn't check pldd ptr validity: crash (W98SE)
646 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
649 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
652 static RETERR16
SETUPX_GetLdd(LPLOGDISKDESC pldd
)
654 LDD_LIST
*pCurr
, *pPrev
= NULL
;
657 SETUPX_CreateStandardLDDs();
659 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
660 return ERR_VCP_LDDINVALID
;
663 /* search until we find the appropriate LDD or hit the end */
664 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
669 if (pCurr
== NULL
) /* hit end of list */
670 return ERR_VCP_LDDFIND
; /* correct ? */
672 memcpy(pldd
, pCurr
->pldd
, pldd
->cbSize
);
673 /* hmm, we probably ought to strcpy() the string ptrs here */
678 /**********************************************************************/
680 RETERR16 WINAPI
CtlGetLdd16(LPLOGDISKDESC pldd
)
682 FIXME("(%p); - please report this!\n", pldd
);
683 return SETUPX_GetLdd(pldd
);
686 /***********************************************************************
687 * CtlGetLddPath (SETUPX.38)
689 * Gets the path of an LDD.
690 * No crash if szPath == NULL.
691 * szPath has to be at least MAX_PATH_LEN bytes long.
693 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
695 RETERR16 WINAPI
CtlGetLddPath16(LOGDISKID16 ldid
, LPSTR szPath
)
697 TRACE("(%d, %p);\n", ldid
, szPath
);
703 if (CtlFindLdd16(&ldd
) == ERR_VCP_LDDFIND
)
704 return ERR_VCP_LDDUNINIT
;
706 strcpy(szPath
, ldd
.pszPath
);
707 TRACE("ret '%s' for LDID %d\n", szPath
, ldid
);
712 /***********************************************************************
713 * CtlSetLddPath (SETUPX.508)
715 * Sets the path of an LDD.
716 * Creates LDD for LDID if not existing yet.
718 RETERR16 WINAPI
CtlSetLddPath16(LOGDISKID16 ldid
, LPSTR szPath
)
721 TRACE("(%d, '%s');\n", ldid
, szPath
);
723 SetupSetDirectoryIdA( 0, ldid
, szPath
);
725 ldd
.pszPath
= szPath
;
726 return CtlSetLdd16(&ldd
);