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 */
134 res = HeapReAlloc(GetProcessHeap(), 0, res, (1+count+32)*sizeof(LPSTR));
136 *(res+1+count) = HeapAlloc(GetProcessHeap(), 0, len+1);
137 strncpy(*(res+1+count), p, len);
138 (*(res+1+count))[len] = '\0';
141 /* we are still within last substring (before delimiter),
142 * so get out of it */
143 while ((*q) && (*q != ';') && (*q != delimiter)) q++;
144 if ((!*q) || (*q == ';'))
149 /* put number of entries at beginning of list */
150 *(DWORD *)res = count;
154 static void SETUPX_FreeSubStrings(LPSTR *substr)
156 DWORD count = *(DWORD *)substr;
157 LPSTR *pStrings = substr+1;
160 for (n=0; n < count; n++)
161 HeapFree(GetProcessHeap(), 0, *pStrings++);
163 HeapFree(GetProcessHeap(), 0, substr);
167 /***********************************************************************
168 * InstallHinfSection (SETUPX.527)
170 * hwnd = parent window
171 * hinst = instance of SETUPX.DLL
172 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
173 * Here "DefaultInstall" is the .inf file section to be installed (optional).
174 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
176 * nCmdShow = nCmdShow of CreateProcess
178 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
183 RETERR16 res = OK, tmp;
187 TRACE("(%04x, %04x, %s, %d);\n", hwnd, hinst, lpszCmdLine, nCmdShow);
189 pSub = SETUPX_GetSubStrings((LPSTR)lpszCmdLine, ' ');
191 count = *(DWORD *)pSub;
192 if (count < 2) /* invalid number of arguments ? */
194 if (IpOpen16(*(pSub+count), &hInf) != OK)
196 res = ERROR_FILE_NOT_FOUND; /* yes, correct */
199 if (VcpOpen16(NULL, 0))
201 if (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
203 wFlags = atoi(*(pSub+count-1)) & ~128;
206 case HOW_ALWAYS_SILENT_REBOOT:
207 case HOW_SILENT_REBOOT:
210 case HOW_ALWAYS_PROMPT_REBOOT:
211 case HOW_PROMPT_REBOOT:
212 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)
216 ERR("invalid flags %d !\n", wFlags);
222 tmp = VcpClose16(VCPFL_ALL, NULL);
225 tmp = IpClose16(hInf);
228 SETUPX_FreeSubStrings(pSub);
231 /* FIXME: we should have a means of terminating all wine + wineserver */
232 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
242 LPCSTR StdString; /* fallback string; sub dir of windows directory */
245 static const LDID_DATA LDID_Data[34] =
247 { /* 0 (LDID_NULL) -- not defined */
251 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
252 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
255 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
259 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
263 { /* 4 (LDID_BACKUP) = backup dir */
267 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
271 { /* 6 -- not defined */
275 { /* 7 -- not defined */
279 { /* 8 -- not defined */
283 { /* 9 -- not defined */
287 { /* 10 (LDID_WIN) = windows dir */
291 { /* 11 (LDID_SYS) = system dir */
293 NULL /* call GetSystemDirectory() instead */
295 { /* 12 (LDID_IOS) = IOSubSys dir */
296 NULL, /* FIXME: registry string ? */
299 { /* 13 (LDID_CMD) = COMMAND dir */
300 NULL, /* FIXME: registry string ? */
303 { /* 14 (LDID_CPL) = control panel dir */
307 { /* 15 (LDID_PRINT) = windows printer dir */
309 "SYSTEM" /* correct ?? */
311 { /* 16 (LDID_MAIL) = destination mail dir */
315 { /* 17 (LDID_INF) = INF dir */
316 "SetupScratchDir", /* correct ? */
319 { /* 18 (LDID_HELP) = HELP dir */
323 { /* 19 (LDID_WINADMIN) = Admin dir */
327 { /* 20 (LDID_FONTS) = Fonts dir */
331 { /* 21 (LDID_VIEWERS) = Viewers */
335 { /* 22 (LDID_VMM32) = VMM32 dir */
339 { /* 23 (LDID_COLOR) = ICM dir */
343 { /* 24 (LDID_APPS) = root of boot drive ? */
347 { /* 25 (LDID_SHARED) = shared dir */
351 { /* 26 (LDID_WINBOOT) = Windows boot dir */
355 { /* 27 (LDID_MACHINE) = machine specific files */
359 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
363 { /* 29 -- not defined */
367 { /* 30 (LDID_BOOT) = Root of boot drive */
371 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
375 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
379 { /* 33 (LDID_OLD_WIN) = old win dir */
383 /* the rest (34-38) isn't too interesting, so I'll forget about it */
387 * LDD == Logical Device Descriptor
388 * LDID == Logical Device ID
390 * The whole LDD/LDID business might go into a separate file named
392 * At the moment I don't know what the hell these functions are really doing.
393 * That's why I added reporting stubs.
394 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
395 * That's why I implemented them in a way that's suitable for my purpose.
397 static LDD_LIST *pFirstLDD = NULL;
399 static BOOL std_LDDs_done = FALSE;
401 void SETUPX_CreateStandardLDDs(void)
407 char buffer[MAX_PATH];
409 /* has to be here, otherwise loop */
410 std_LDDs_done = TRUE;
412 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
414 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
419 if ( (hKey) && (LDID_Data[n].RegValName)
420 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
421 NULL, &type, buffer, &len) == ERROR_SUCCESS)
422 && (type == REG_SZ) )
424 TRACE("found value '%s' for LDID %d\n", buffer, n);
430 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
431 strcpy(buffer, "X:\\FIXME");
434 GetSystemDirectoryA(buffer, MAX_PATH);
438 case LDID_HOST_WINBOOT:
441 strcpy(buffer, "C:\\");
444 if (LDID_Data[n].StdString)
446 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
450 strcpy(p, LDID_Data[n].StdString);
457 ldd.pszPath = buffer;
458 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
462 if (hKey) RegCloseKey(hKey);
465 /***********************************************************************
466 * CtlDelLdd (SETUPX.37)
469 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
471 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
473 LDD_LIST *pCurr, *pPrev = NULL;
475 TRACE("(%d)\n", ldid);
478 SETUPX_CreateStandardLDDs();
480 if (ldid < LDID_ASSIGN_START)
481 return ERR_VCP_LDDINVALID;
484 /* search until we find the appropriate LDD or hit the end */
485 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
490 if ( (pCurr == NULL) /* hit end of list */
491 || (ldid != pCurr->pldd->ldid) )
492 return ERR_VCP_LDDFIND; /* correct ? */
494 /* ok, found our victim: eliminate it */
497 pPrev->next = pCurr->next;
499 if (pCurr == pFirstLDD)
501 HeapFree(GetProcessHeap(), 0, pCurr);
506 /***********************************************************************
507 * CtlDelLdd (SETUPX.37)
509 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
511 FIXME("(%d); - please report this!\n", ldid);
512 return SETUPX_DelLdd(ldid);
515 /***********************************************************************
516 * CtlFindLdd (SETUPX.35)
518 * doesn't check pldd ptr validity: crash (W98SE)
521 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
522 * 1 in all other cases ??
525 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
527 LDD_LIST *pCurr, *pPrev = NULL;
529 TRACE("(%p)\n", pldd);
532 SETUPX_CreateStandardLDDs();
534 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
535 return ERR_VCP_LDDINVALID;
538 /* search until we find the appropriate LDD or hit the end */
539 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
544 if ( (pCurr == NULL) /* hit end of list */
545 || (pldd->ldid != pCurr->pldd->ldid) )
546 return ERR_VCP_LDDFIND; /* correct ? */
548 memcpy(pldd, pCurr->pldd, pldd->cbSize);
549 /* hmm, we probably ought to strcpy() the string ptrs here */
551 return 1; /* what is this ?? */
554 /***********************************************************************
555 * CtlSetLdd (SETUPX.33)
560 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
563 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
565 LDD_LIST *pCurr, *pPrev = NULL;
566 LPLOGDISKDESC pCurrLDD;
570 TRACE("(%p)\n", pldd);
573 SETUPX_CreateStandardLDDs();
575 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
576 return ERR_VCP_LDDINVALID;
578 heap = GetProcessHeap();
580 /* search until we find the appropriate LDD or hit the end */
581 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
586 if (!pCurr || pldd->ldid != pCurr->pldd->ldid)
589 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
590 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
592 pCurrLDD = pCurr->pldd;
596 pCurrLDD = pCurr->pldd;
597 if (pCurrLDD->pszPath) HeapFree(heap, 0, pCurrLDD->pszPath);
598 if (pCurrLDD->pszVolLabel) HeapFree(heap, 0, pCurrLDD->pszVolLabel);
599 if (pCurrLDD->pszDiskName) HeapFree(heap, 0, pCurrLDD->pszDiskName);
602 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
606 pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
607 strcpy( pCurrLDD->pszPath, pldd->pszPath );
609 if (pldd->pszVolLabel)
611 pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
612 strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
614 if (pldd->pszDiskName)
616 pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
617 strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
620 if (is_new) /* link into list */
624 pCurr->next = pPrev->next;
635 /***********************************************************************
636 * CtlAddLdd (SETUPX.36)
638 * doesn't check pldd ptr validity: crash (W98SE)
641 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
642 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
644 pldd->ldid = ldid_to_add++;
645 return CtlSetLdd16(pldd);
648 /***********************************************************************
649 * CtlGetLdd (SETUPX.34)
651 * doesn't check pldd ptr validity: crash (W98SE)
652 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
655 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
658 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
660 LDD_LIST *pCurr, *pPrev = NULL;
663 SETUPX_CreateStandardLDDs();
665 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
666 return ERR_VCP_LDDINVALID;
669 /* search until we find the appropriate LDD or hit the end */
670 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
675 if (pCurr == NULL) /* hit end of list */
676 return ERR_VCP_LDDFIND; /* correct ? */
678 memcpy(pldd, pCurr->pldd, pldd->cbSize);
679 /* hmm, we probably ought to strcpy() the string ptrs here */
684 /**********************************************************************/
686 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
688 FIXME("(%p); - please report this!\n", pldd);
689 return SETUPX_GetLdd(pldd);
692 /***********************************************************************
693 * CtlGetLddPath (SETUPX.38)
695 * Gets the path of an LDD.
696 * No crash if szPath == NULL.
697 * szPath has to be at least MAX_PATH_LEN bytes long.
699 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
701 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
703 TRACE("(%d, %p);\n", ldid, szPath);
709 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
710 return ERR_VCP_LDDUNINIT;
712 strcpy(szPath, ldd.pszPath);
713 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
718 /***********************************************************************
719 * CtlSetLddPath (SETUPX.508)
721 * Sets the path of an LDD.
722 * Creates LDD for LDID if not existing yet.
724 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
727 TRACE("(%d, '%s');\n", ldid, szPath);
729 SetupSetDirectoryIdA( 0, ldid, szPath );
731 ldd.pszPath = szPath;
732 return CtlSetLdd16(&ldd);