4 * Copyright 1998,2000 Andreas Mohr
6 * FIXME: Rather non-functional functions for now.
9 * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
10 * http://willemer.de/informatik/windows/inf_info.htm (German)
11 * http://www.microsoft.com/ddk/ddkdocs/win98ddk/devinst_12uw.htm
13 * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
14 * http://www.rdrop.com/~cary/html/inf_faq.html
15 * http://support.microsoft.com/support/kb/articles/q194/6/40.asp
18 * - rs405deu.exe (German Acroread 4.05 setup)
23 * - string handling is... weird ;) (buflen etc.)
25 * - separate that mess (but probably only when it's done completely)
27 * SETUPX consists of several parts with the following acronyms/prefixes:
28 * Di device installer (devinst.c ?)
29 * Gen generic installer (geninst.c ?)
30 * Ip .INF parsing (infparse.c)
31 * LDD logical device descriptor (ldd.c ?)
32 * LDID logical device ID
33 * SU setup (setup.c ?)
34 * Tp text processing (textproc.c ?)
35 * Vcp virtual copy module (vcp.c ?)
38 * The SETUPX DLL is NOT thread-safe. That's why many installers urge you to
39 * "close all open applications".
40 * All in all the design of it seems to be a bit weak.
41 * Not sure whether my implementation of it is better, though ;-)
48 #include "wine/winuser16.h"
50 #include "setupapi_private.h"
52 #include "debugtools.h"
54 DEFAULT_DEBUG_CHANNEL(setupapi);
56 /***********************************************************************
57 * SURegOpenKey (SETUPX.47)
59 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, LPHKEY retkey )
61 FIXME("(%x,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
62 return RegOpenKeyA( hkey, lpszSubKey, retkey );
65 /***********************************************************************
66 * SURegQueryValueEx (SETUPX.50)
68 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
69 LPDWORD lpdwReserved, LPDWORD lpdwType,
70 LPBYTE lpbData, LPDWORD lpcbData )
72 FIXME("(%x,%s,%p,%p,%p,%ld), semi-stub.\n",hkey,debugstr_a(lpszValueName),
73 lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
74 return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
79 * Returns pointer to a string list with the first entry being number
82 * Hmm. Should this be InitSubstrData(), GetFirstSubstr() and GetNextSubstr()
85 static LPSTR *SETUPX_GetSubStrings(LPSTR start, char delimiter)
96 /* find beginning of real substring */
97 while ( (*p == ' ') || (*p == '\t') || (*p == '"') ) p++;
99 /* find end of real substring */
102 && (*q != ' ') && (*q != '\t') && (*q != '"')
103 && (*q != ';') && (*q != delimiter) ) q++;
106 len = (int)q - (int)p;
108 /* alloc entry for new substring in steps of 32 units and copy over */
110 { /* 1 for count field + current count + 32 */
111 res = HeapReAlloc(GetProcessHeap(), 0, res, (1+count+32)*sizeof(LPSTR));
113 *(res+1+count) = HeapAlloc(GetProcessHeap(), 0, len+1);
114 strncpy(*(res+1+count), p, len);
115 (*(res+1+count))[len] = '\0';
118 /* we are still within last substring (before delimiter),
119 * so get out of it */
120 while ((*q) && (*q != ';') && (*q != delimiter)) q++;
121 if ((!*q) || (*q == ';'))
126 /* put number of entries at beginning of list */
127 *(DWORD *)res = count;
131 static void SETUPX_FreeSubStrings(LPSTR *substr)
133 DWORD count = *(DWORD *)substr;
134 LPSTR *pStrings = substr+1;
137 for (n=0; n < count; n++)
138 HeapFree(GetProcessHeap(), 0, *pStrings++);
140 HeapFree(GetProcessHeap(), 0, substr);
143 static void SETUPX_IsolateSubString(LPSTR *begin, LPSTR *end)
150 while ((p < q) && ((*p == ' ') || (*p == '\t'))) p++;
151 while ((p < q) && (*p == '"')) p++;
153 while ((q-1 >= p) && ((*(q-1) == ' ') || (*(q-1) == '\t'))) q--;
154 while ((q-1 >= p) && (*(q-1) == '"')) q--;
161 * Example: HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
162 * FIXME: use SETUPX_GetSubStrings() instead.
163 * Hmm, but on the other hand SETUPX_GetSubStrings() will probably
164 * soon be replaced by InitSubstrData() etc. anyway.
167 static BOOL SETUPX_LookupRegistryString(LPSTR regstr, LPSTR buffer, DWORD buflen)
169 HANDLE heap = GetProcessHeap();
176 TRACE("retrieving '%s'\n", regstr);
180 /* isolate root key, subkey, value, flag, defval */
181 for (n=0; n < 5; n++)
194 SETUPX_IsolateSubString(&p, &q);
195 len = (int)q - (int)p;
196 items[n] = HeapAlloc(heap, 0, len+1);
197 strncpy(items[n], p, len);
198 items[n][len] = '\0';
201 TRACE("got '%s','%s','%s','%s','%s'\n",
202 items[0], items[1], items[2], items[3], items[4]);
205 if (!strcasecmp(items[0], "HKCR"))
206 hkey = HKEY_CLASSES_ROOT;
208 if (!strcasecmp(items[0], "HKCU"))
209 hkey = HKEY_CURRENT_USER;
211 if (!strcasecmp(items[0], "HKLM"))
212 hkey = HKEY_LOCAL_MACHINE;
214 if (!strcasecmp(items[0], "HKU"))
217 { /* HKR ? -> relative to key passed to GenInstallEx */
218 FIXME("unsupported regkey '%s'\n", items[0]);
222 if (RegOpenKeyA(hkey, items[1], &hsubkey) != ERROR_SUCCESS)
225 if (RegQueryValueExA(hsubkey, items[2], NULL, &dwType, buffer, &buflen)
231 if (buffer) strcpy(buffer, items[4]); /* I don't care about buflen */
233 for (n=0; n < 5; n++)
234 HeapFree(heap, 0, items[n]);
236 TRACE("return '%s'\n", buffer);
240 static LPSTR SETUPX_GetSections(LPCSTR filename)
243 DWORD len = 1024, res;
246 buf = HeapReAlloc(GetProcessHeap(), 0, buf, len);
247 res = GetPrivateProfileStringA(NULL, NULL, NULL, buf, len, filename);
249 } while ((!res) && (len < 1048576));
252 HeapFree(GetProcessHeap(), 0, buf);
258 static LPSTR SETUPX_GetSectionEntries(LPCSTR filename, LPCSTR section)
261 DWORD len = 1024, res;
264 buf = HeapReAlloc(GetProcessHeap(), 0, buf, len);
265 res = GetPrivateProfileSectionA(section, buf, len, filename);
267 } while ((!res) && (len < 1048576));
270 HeapFree(GetProcessHeap(), 0, buf);
277 /***********************************************************************
278 * InstallHinfSection (SETUPX.527)
280 * hwnd = parent window
281 * hinst = instance of SETUPX.DLL
282 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
283 * Here "DefaultInstall" is the .inf file section to be installed (optional).
284 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
286 * nCmdShow = nCmdShow of CreateProcess
288 typedef INT WINAPI (*MSGBOX_PROC)( HWND, LPCSTR, LPCSTR, UINT );
289 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
294 RETERR16 res = OK, tmp;
298 MSGBOX_PROC pMessageBoxA;
300 TRACE("(%04x, %04x, %s, %d);\n", hwnd, hinst, lpszCmdLine, nCmdShow);
302 pSub = SETUPX_GetSubStrings((LPSTR)lpszCmdLine, ' ');
304 count = *(DWORD *)pSub;
305 if (count < 2) /* invalid number of arguments ? */
307 if (IpOpen16(*(pSub+count), &hInf) != OK)
309 res = ERROR_FILE_NOT_FOUND; /* yes, correct */
312 if (VcpOpen16(NULL, 0))
314 if (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
316 wFlags = atoi(*(pSub+count-1)) & ~128;
319 case HOW_ALWAYS_SILENT_REBOOT:
320 case HOW_SILENT_REBOOT:
323 case HOW_ALWAYS_PROMPT_REBOOT:
324 case HOW_PROMPT_REBOOT:
325 if ((hMod = GetModuleHandleA("user32.dll")))
327 if ((pMessageBoxA = (MSGBOX_PROC)GetProcAddress( hMod, "MessageBoxA" )))
330 if (pMessageBoxA(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)
336 ERR("invalid flags %d !\n", wFlags);
342 tmp = VcpClose16(VCPFL_ALL, NULL);
345 tmp = IpClose16(hInf);
348 SETUPX_FreeSubStrings(pSub);
351 /* FIXME: we should have a means of terminating all wine + wineserver */
352 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
362 LPCSTR StdString; /* fallback string; sub dir of windows directory */
365 static const LDID_DATA LDID_Data[34] =
367 { /* 0 (LDID_NULL) -- not defined */
371 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
372 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
375 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
379 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
383 { /* 4 (LDID_BACKUP) = backup dir */
387 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
391 { /* 6 -- not defined */
395 { /* 7 -- not defined */
399 { /* 8 -- not defined */
403 { /* 9 -- not defined */
407 { /* 10 (LDID_WIN) = windows dir */
411 { /* 11 (LDID_SYS) = system dir */
413 NULL /* call GetSystemDirectory() instead */
415 { /* 12 (LDID_IOS) = IOSubSys dir */
416 NULL, /* FIXME: registry string ? */
419 { /* 13 (LDID_CMD) = COMMAND dir */
420 NULL, /* FIXME: registry string ? */
423 { /* 14 (LDID_CPL) = control panel dir */
427 { /* 15 (LDID_PRINT) = windows printer dir */
429 "SYSTEM" /* correct ?? */
431 { /* 16 (LDID_MAIL) = destination mail dir */
435 { /* 17 (LDID_INF) = INF dir */
436 "SetupScratchDir", /* correct ? */
439 { /* 18 (LDID_HELP) = HELP dir */
443 { /* 19 (LDID_WINADMIN) = Admin dir */
447 { /* 20 (LDID_FONTS) = Fonts dir */
451 { /* 21 (LDID_VIEWERS) = Viewers */
455 { /* 22 (LDID_VMM32) = VMM32 dir */
459 { /* 23 (LDID_COLOR) = ICM dir */
463 { /* 24 (LDID_APPS) = root of boot drive ? */
467 { /* 25 (LDID_SHARED) = shared dir */
471 { /* 26 (LDID_WINBOOT) = Windows boot dir */
475 { /* 27 (LDID_MACHINE) = machine specific files */
479 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
483 { /* 29 -- not defined */
487 { /* 30 (LDID_BOOT) = Root of boot drive */
491 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
495 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
499 { /* 33 (LDID_OLD_WIN) = old win dir */
503 /* the rest (34-38) isn't too interesting, so I'll forget about it */
507 * LDD == Logical Device Descriptor
508 * LDID == Logical Device ID
510 * The whole LDD/LDID business might go into a separate file named
512 * At the moment I don't know what the hell these functions are really doing.
513 * That's why I added reporting stubs.
514 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
515 * That's why I implemented them in a way that's suitable for my purpose.
517 static LDD_LIST *pFirstLDD = NULL;
519 static BOOL std_LDDs_done = FALSE;
521 void SETUPX_CreateStandardLDDs(void)
527 char buffer[MAX_PATH];
529 /* has to be here, otherwise loop */
530 std_LDDs_done = TRUE;
532 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
534 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
539 if ( (hKey) && (LDID_Data[n].RegValName)
540 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
541 NULL, &type, buffer, &len) == ERROR_SUCCESS)
542 && (type == REG_SZ) )
544 TRACE("found value '%s' for LDID %d\n", buffer, n);
550 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
551 strcpy(buffer, "X:\\FIXME");
554 GetSystemDirectoryA(buffer, MAX_PATH);
558 case LDID_HOST_WINBOOT:
561 strcpy(buffer, "C:\\");
564 if (LDID_Data[n].StdString)
566 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
570 strcpy(p, LDID_Data[n].StdString);
577 ldd.pszPath = buffer;
578 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
582 if (hKey) RegCloseKey(hKey);
585 /***********************************************************************
586 * CtlDelLdd (SETUPX.37)
589 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
591 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
593 LDD_LIST *pCurr, *pPrev = NULL;
595 TRACE("(%d)\n", ldid);
598 SETUPX_CreateStandardLDDs();
600 if (ldid < LDID_ASSIGN_START)
601 return ERR_VCP_LDDINVALID;
604 /* search until we find the appropriate LDD or hit the end */
605 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
610 if ( (pCurr == NULL) /* hit end of list */
611 || (ldid != pCurr->pldd->ldid) )
612 return ERR_VCP_LDDFIND; /* correct ? */
614 /* ok, found our victim: eliminate it */
617 pPrev->next = pCurr->next;
619 if (pCurr == pFirstLDD)
621 HeapFree(GetProcessHeap(), 0, pCurr);
626 /***********************************************************************
627 * CtlDelLdd (SETUPX.37)
629 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
631 FIXME("(%d); - please report to a.mohr@mailto.de !!!\n", ldid);
632 return SETUPX_DelLdd(ldid);
635 /***********************************************************************
636 * CtlFindLdd (SETUPX.35)
638 * doesn't check pldd ptr validity: crash (W98SE)
641 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
642 * 1 in all other cases ??
645 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
647 LDD_LIST *pCurr, *pPrev = NULL;
649 TRACE("(%p)\n", pldd);
652 SETUPX_CreateStandardLDDs();
654 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
655 return ERR_VCP_LDDINVALID;
658 /* search until we find the appropriate LDD or hit the end */
659 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
664 if ( (pCurr == NULL) /* hit end of list */
665 || (pldd->ldid != pCurr->pldd->ldid) )
666 return ERR_VCP_LDDFIND; /* correct ? */
668 memcpy(pldd, pCurr->pldd, pldd->cbSize);
669 /* hmm, we probably ought to strcpy() the string ptrs here */
671 return 1; /* what is this ?? */
674 /***********************************************************************
675 * CtlSetLdd (SETUPX.33)
680 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
683 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
685 LDD_LIST *pCurr, *pPrev = NULL;
686 LPLOGDISKDESC pCurrLDD;
690 TRACE("(%p)\n", pldd);
693 SETUPX_CreateStandardLDDs();
695 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
696 return ERR_VCP_LDDINVALID;
698 heap = GetProcessHeap();
700 /* search until we find the appropriate LDD or hit the end */
701 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
706 if (pCurr == NULL) /* hit end of list */
709 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
710 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
712 pCurrLDD = pCurr->pldd;
716 pCurrLDD = pCurr->pldd;
717 if (pCurrLDD->pszPath) HeapFree(heap, 0, pCurrLDD->pszPath);
718 if (pCurrLDD->pszVolLabel) HeapFree(heap, 0, pCurrLDD->pszVolLabel);
719 if (pCurrLDD->pszDiskName) HeapFree(heap, 0, pCurrLDD->pszDiskName);
722 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
726 pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
727 strcpy( pCurrLDD->pszPath, pldd->pszPath );
729 if (pldd->pszVolLabel)
731 pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
732 strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
734 if (pldd->pszDiskName)
736 pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
737 strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
740 if (is_new) /* link into list */
744 pCurr->next = pPrev->next;
755 /***********************************************************************
756 * CtlAddLdd (SETUPX.36)
758 * doesn't check pldd ptr validity: crash (W98SE)
761 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
762 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
764 pldd->ldid = ldid_to_add++;
765 return CtlSetLdd16(pldd);
768 /***********************************************************************
769 * CtlGetLdd (SETUPX.34)
771 * doesn't check pldd ptr validity: crash (W98SE)
772 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
775 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
778 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
780 LDD_LIST *pCurr, *pPrev = NULL;
783 SETUPX_CreateStandardLDDs();
785 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
786 return ERR_VCP_LDDINVALID;
789 /* search until we find the appropriate LDD or hit the end */
790 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
795 if (pCurr == NULL) /* hit end of list */
796 return ERR_VCP_LDDFIND; /* correct ? */
798 memcpy(pldd, pCurr->pldd, pldd->cbSize);
799 /* hmm, we probably ought to strcpy() the string ptrs here */
804 /**********************************************************************/
806 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
808 FIXME("(%p); - please report to a.mohr@mailto.de !!!\n", pldd);
809 return SETUPX_GetLdd(pldd);
812 /***********************************************************************
813 * CtlGetLddPath (SETUPX.38)
815 * Gets the path of an LDD.
816 * No crash if szPath == NULL.
817 * szPath has to be at least MAX_PATH_LEN bytes long.
819 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
821 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
823 TRACE("(%d, %p);\n", ldid, szPath);
829 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
830 return ERR_VCP_LDDUNINIT;
832 strcpy(szPath, ldd.pszPath);
833 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
838 /***********************************************************************
839 * CtlSetLddPath (SETUPX.508)
841 * Sets the path of an LDD.
842 * Creates LDD for LDID if not existing yet.
844 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
847 TRACE("(%d, '%s');\n", ldid, szPath);
850 ldd.pszPath = szPath;
851 return CtlSetLdd16(&ldd);
855 * Find the value of a custom LDID in a .inf file
857 * 49300,49301=ProgramFilesDir,5
858 * -- profile section lookup -->
860 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"%24%"
861 * -- GenFormStrWithoutPlaceHolders16 -->
862 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
863 * -- registry lookup -->
864 * C:\Program Files (or C:\ if not found in registry)
867 * - maybe we ought to add a caching array for speed ? - I don't care :)
868 * - not sure whether the processing is correct - sometimes there are equal
869 * LDIDs for both install and removal sections.
870 * - probably the whole function can be removed as installers add that on their
873 static BOOL SETUPX_AddCustomLDID(int ldid, INT16 hInf)
876 LPSTR sectionbuf = NULL, entrybuf = NULL, regsectionbuf = NULL;
878 LPSTR pSec, pEnt, pEqual, p, *pSub = NULL;
880 char buffer[MAX_PATH];
883 sprintf(ldidstr, "%d", ldid);
884 filename = IP_GetFileName(hInf);
885 if (!(sectionbuf = SETUPX_GetSections(filename)))
887 ERR("couldn't get sections !\n");
890 for (pSec=sectionbuf; *pSec; pSec += strlen(pSec)+1)
892 if (!(entrybuf = SETUPX_GetSectionEntries(filename, pSec)))
894 ERR("couldn't get section entries !\n");
897 for (pEnt=entrybuf; *pEnt; pEnt += strlen(pEnt)+1)
899 if (strstr(pEnt, ldidstr))
901 pEqual = strchr(pEnt, '=');
902 if (!pEqual) /* crippled entry ?? */
905 /* make sure we found the LDID on left side of the equation */
906 if (pEnt+strlen(ldidstr) <= pEqual)
909 /* but we don't want entries in the strings section */
910 if (!strcasecmp(pSec, "Strings"))
921 TRACE("found entry '%s'\n", p);
922 pSub = SETUPX_GetSubStrings(p, ',');
923 if (*(DWORD *)pSub > 2)
925 ERR("malformed entry '%s' ?\n", p);
928 TRACE("found section '%s'\n", *(pSub+1));
929 /* FIXME: what are the optional flags at the end of an entry used for ?? */
931 /* get the location of the registry key from that section */
932 if (!(regsectionbuf = SETUPX_GetSectionEntries(filename, *(pSub+1))))
934 ERR("couldn't get registry section entries !\n");
937 /* sectionbuf is > 1024 bytes anyway, so use it */
938 GenFormStrWithoutPlaceHolders16(sectionbuf, regsectionbuf, hInf);
939 ret = SETUPX_LookupRegistryString(sectionbuf, buffer, MAX_PATH);
940 TRACE("return '%s'\n", buffer);
942 ldd.pszPath = buffer;
945 SETUPX_FreeSubStrings(pSub);
946 if (sectionbuf) HeapFree(GetProcessHeap(), 0, sectionbuf);
947 if (entrybuf) HeapFree(GetProcessHeap(), 0, entrybuf);
948 if (regsectionbuf) HeapFree(GetProcessHeap(), 0, regsectionbuf);
953 * Translate a logical disk identifier (LDID) into its string representation
954 * I'm afraid this can be totally replaced by CtlGetLddPath().
956 static BOOL SETUPX_IP_TranslateLDID(int ldid, LPSTR *p, HINF16 hInf)
958 BOOL handled = FALSE;
961 ldd.cbSize = sizeof(LOGDISKDESC_S);
963 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
965 /* hmm, it seems the installers already do the work for us
966 * (by calling CtlSetLddPath) that SETUPX_AddCustomLDID
967 * is supposed to do. Grmbl ;-)
968 * Well, I'll leave it here anyway, but print error... */
969 ERR("hmm, LDID %d not registered yet !?\n", ldid);
970 handled = SETUPX_AddCustomLDID(ldid, hInf);
979 FIXME("What is LDID %d ??\n", ldid);
988 /***********************************************************************
989 * GenFormStrWithoutPlaceHolders (SETUPX.103)
991 * ought to be pretty much implemented, I guess...
993 void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
995 LPCSTR pSrc = szSrc, pSrcEnd = szSrc + strlen(szSrc);
996 LPSTR pDst = szDst, p, pPHBegin;
999 TRACE("(%p, '%s', %04x);\n", szDst, szSrc, hInf);
1000 while (pSrc < pSrcEnd)
1002 p = strchr(pSrc, '%');
1005 count = (int)p - (int)pSrc;
1006 strncpy(pDst, pSrc, count);
1010 p = strchr(pPHBegin, '%');
1013 char placeholder[80]; /* that really ought to be enough ;) */
1016 count = (int)p - (int)pPHBegin;
1017 strncpy(placeholder, pPHBegin, count);
1018 placeholder[count] = '\0';
1019 ldid = atoi(placeholder);
1023 done = SETUPX_IP_TranslateLDID(ldid, &p, hInf);
1026 pDst += strlen(pDst);
1029 { /* hmm, string placeholder. Need to look up
1030 in the [strings] section of the hInf */
1032 char buf[256]; /* long enough ? */
1034 ret = GetPrivateProfileStringA("strings", placeholder, "",
1035 buf, 256, IP_GetFileName(hInf));
1039 pDst += strlen(buf);
1043 ERR("placeholder string '%s' not found !\n", placeholder);
1048 { /* copy raw placeholder string over */
1049 count = (int)p - (int)pPHBegin + 2;
1050 strncpy(pDst, pPHBegin-1, count);
1059 /* copy the remaining source string over */
1060 strncpy(pDst, pSrc, (int)pSrcEnd - (int)pSrc + 1);
1063 TRACE("ret '%s'\n", szDst);
1067 * Copy all items in a CopyFiles entry over to the destination
1069 * - VNLP_xxx is what is given as flags for a .INF CopyFiles section
1071 static BOOL SETUPX_CopyFiles(LPSTR *pSub, HINF16 hInf)
1073 BOOL bSingle = FALSE;
1075 LPCSTR filename = IP_GetFileName(hInf);
1077 char pDstStr[MAX_PATH];
1078 LPSTR pSrcDir, pDstDir;
1079 LPSTR pFileEntries, p;
1083 LPSTR pSrcFile, pDstFile;
1086 for (n=0; n < *(DWORD *)pSub; n++)
1088 pCopyEntry = *(pSub+1+n);
1089 if (*pCopyEntry == '@')
1097 /* get source directory for that entry */
1098 INIT_LDD(ldd, LDID_SRCPATH);
1099 SETUPX_GetLdd(&ldd);
1100 pSrcDir = ldd.pszPath;
1102 /* get destination directory for that entry */
1103 if (!(GetPrivateProfileStringA("DestinationDirs", pCopyEntry, "",
1104 pDstStr, sizeof(pDstStr), filename)))
1106 /* hmm, not found; try the default entry */
1107 if (!(GetPrivateProfileStringA("DestinationDirs", "DefaultDestDir", "", pDstStr, sizeof(pDstStr), filename)))
1109 WARN("DefaultDestDir not found.\n");
1114 /* translate destination dir if given as LDID */
1115 ldid = atoi(pDstStr);
1118 if (!(SETUPX_IP_TranslateLDID(ldid, &pDstDir, hInf)))
1124 /* now that we have the destination dir, register file copying */
1128 VcpQueueCopy16(pCopyEntry, pCopyEntry, pSrcDir, pDstDir, LDID_SRCPATH, ldid ? ldid : 0xffff, 0, VFNL_COPY, 0);
1132 /* entry wasn't a single file, so let's iterate over section */
1133 pFileEntries = SETUPX_GetSectionEntries(filename, pCopyEntry);
1134 for (p=pFileEntries; *p; p +=strlen(p)+1)
1136 pSubFile = SETUPX_GetSubStrings(p, ',');
1137 pSrcFile = *(pSubFile+1);
1138 pDstFile = (*(DWORD *)pSubFile > 1) ? *(pSubFile+2) : pSrcFile;
1139 TRACE("copying file '%s\\%s' to '%s\\%s'\n", pSrcDir, pSrcFile, pDstDir, pDstFile);
1141 if (*(DWORD *)pSubFile > 2)
1143 if ((flag = atoi(*(pSubFile+3)))) /* ah, flag */
1146 FIXME("VNLP_xxx flag %d not handled yet.\n", flag);
1150 FIXME("temp file name '%s' given. Need to register in wininit.ini !\n", *(pSubFile+3));
1151 /* we probably need to set VIRTNODE.vhstrDstFinalName to
1152 * the final destination name, and the temp name is merely
1153 * the copy destination */
1156 VcpQueueCopy16(pSrcFile, pDstFile, pSrcDir, pDstDir, LDID_SRCPATH, ldid ? ldid : 0xffff, 0, VFNL_COPY|flag, 0);
1157 SETUPX_FreeSubStrings(pSubFile);
1164 /***********************************************************************
1165 * GenInstall (SETUPX.101)
1167 * generic installer function for .INF file sections
1169 * This is not perfect - patch whenever you can !
1171 * wFlags == GENINSTALL_DO_xxx
1173 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
1174 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
1176 RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
1178 LPCSTR filename = IP_GetFileName(hInfFile);
1179 LPSTR pEntries, p, pEnd;
1183 FIXME("(%04x, '%s', %04x), semi-stub. Please implement additional operations here !\n", hInfFile, szInstallSection, wFlags);
1184 pEntries = SETUPX_GetSectionEntries(filename, szInstallSection);
1187 ERR("couldn't find entries for section '%s' !\n", szInstallSection);
1188 return ERR_IP_SECT_NOT_FOUND;
1190 for (p=pEntries; *p; p +=strlen(p)+1)
1192 pEnd = strchr(p, '=');
1193 if (!pEnd) continue;
1194 pSub = SETUPX_GetSubStrings(pEnd+1, ','); /* split entries after the '=' */
1195 SETUPX_IsolateSubString(&p, &pEnd);
1196 len = (int)pEnd - (int)p;
1198 if (wFlags & GENINSTALL_DO_FILES)
1200 if (!strncasecmp(p, "CopyFiles", len))
1202 SETUPX_CopyFiles(pSub, hInfFile);
1207 if (!strncasecmp(p, "DelFiles", len))
1209 SETUPX_DelFiles(filename, szInstallSection, pSub);
1214 if (wFlags & GENINSTALL_DO_INI)
1217 if (!strncasecmp(p, "UpdateInis", len))
1219 SETUPX_UpdateInis(filename, szInstallSection, pSub);
1224 if (wFlags & GENINSTALL_DO_REG)
1227 /* probably use SUReg*() functions here */
1228 if (!strncasecmp(p, "AddReg", len))
1230 SETUPX_AddReg(filename, szInstallSection, pSub);
1234 if (!strncasecmp(p, "DelReg", len))
1236 SETUPX_DelReg(filename, szInstallSection, pSub);
1242 SETUPX_FreeSubStrings(pSub);
1244 HeapFree(GetProcessHeap(), 0, pEntries);