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 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
293 RETERR16 res = OK, tmp;
297 TRACE("(%04x, %04x, %s, %d);\n", hwnd, hinst, lpszCmdLine, nCmdShow);
299 pSub = SETUPX_GetSubStrings((LPSTR)lpszCmdLine, ' ');
301 count = *(DWORD *)pSub;
302 if (count < 2) /* invalid number of arguments ? */
304 if (IpOpen16(*(pSub+count), &hInf) != OK)
306 res = ERROR_FILE_NOT_FOUND; /* yes, correct */
309 if (VcpOpen16(NULL, 0))
311 if (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
313 wFlags = atoi(*(pSub+count-1)) & ~128;
316 case HOW_ALWAYS_SILENT_REBOOT:
317 case HOW_SILENT_REBOOT:
320 case HOW_ALWAYS_PROMPT_REBOOT:
321 case HOW_PROMPT_REBOOT:
322 if (MessageBoxA(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)
326 ERR("invalid flags %d !\n", wFlags);
332 tmp = VcpClose16(VCPFL_ALL, NULL);
335 tmp = IpClose16(hInf);
338 SETUPX_FreeSubStrings(pSub);
341 /* FIXME: we should have a means of terminating all wine + wineserver */
342 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
352 LPCSTR StdString; /* fallback string; sub dir of windows directory */
355 static const LDID_DATA LDID_Data[34] =
357 { /* 0 (LDID_NULL) -- not defined */
361 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
362 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
365 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
369 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
373 { /* 4 (LDID_BACKUP) = backup dir */
377 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
381 { /* 6 -- not defined */
385 { /* 7 -- not defined */
389 { /* 8 -- not defined */
393 { /* 9 -- not defined */
397 { /* 10 (LDID_WIN) = windows dir */
401 { /* 11 (LDID_SYS) = system dir */
403 NULL /* call GetSystemDirectory() instead */
405 { /* 12 (LDID_IOS) = IOSubSys dir */
406 NULL, /* FIXME: registry string ? */
409 { /* 13 (LDID_CMD) = COMMAND dir */
410 NULL, /* FIXME: registry string ? */
413 { /* 14 (LDID_CPL) = control panel dir */
417 { /* 15 (LDID_PRINT) = windows printer dir */
419 "SYSTEM" /* correct ?? */
421 { /* 16 (LDID_MAIL) = destination mail dir */
425 { /* 17 (LDID_INF) = INF dir */
426 "SetupScratchDir", /* correct ? */
429 { /* 18 (LDID_HELP) = HELP dir */
433 { /* 19 (LDID_WINADMIN) = Admin dir */
437 { /* 20 (LDID_FONTS) = Fonts dir */
441 { /* 21 (LDID_VIEWERS) = Viewers */
445 { /* 22 (LDID_VMM32) = VMM32 dir */
449 { /* 23 (LDID_COLOR) = ICM dir */
453 { /* 24 (LDID_APPS) = root of boot drive ? */
457 { /* 25 (LDID_SHARED) = shared dir */
461 { /* 26 (LDID_WINBOOT) = Windows boot dir */
465 { /* 27 (LDID_MACHINE) = machine specific files */
469 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
473 { /* 29 -- not defined */
477 { /* 30 (LDID_BOOT) = Root of boot drive */
481 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
485 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
489 { /* 33 (LDID_OLD_WIN) = old win dir */
493 /* the rest (34-38) isn't too interesting, so I'll forget about it */
497 * LDD == Logical Device Descriptor
498 * LDID == Logical Device ID
500 * The whole LDD/LDID business might go into a separate file named
502 * At the moment I don't know what the hell these functions are really doing.
503 * That's why I added reporting stubs.
504 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
505 * That's why I implemented them in a way that's suitable for my purpose.
507 static LDD_LIST *pFirstLDD = NULL;
509 static BOOL std_LDDs_done = FALSE;
511 void SETUPX_CreateStandardLDDs(void)
517 char buffer[MAX_PATH];
519 /* has to be here, otherwise loop */
520 std_LDDs_done = TRUE;
522 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
524 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
529 if ( (hKey) && (LDID_Data[n].RegValName)
530 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
531 NULL, &type, buffer, &len) == ERROR_SUCCESS)
532 && (type == REG_SZ) )
534 TRACE("found value '%s' for LDID %d\n", buffer, n);
540 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
541 strcpy(buffer, "X:\\FIXME");
544 GetSystemDirectoryA(buffer, MAX_PATH);
548 case LDID_HOST_WINBOOT:
551 strcpy(buffer, "C:\\");
554 if (LDID_Data[n].StdString)
556 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
560 strcpy(p, LDID_Data[n].StdString);
567 ldd.pszPath = buffer;
568 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
572 if (hKey) RegCloseKey(hKey);
575 /***********************************************************************
576 * CtlDelLdd (SETUPX.37)
579 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
581 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
583 LDD_LIST *pCurr, *pPrev = NULL;
585 TRACE("(%d)\n", ldid);
588 SETUPX_CreateStandardLDDs();
590 if (ldid < LDID_ASSIGN_START)
591 return ERR_VCP_LDDINVALID;
594 /* search until we find the appropriate LDD or hit the end */
595 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
600 if ( (pCurr == NULL) /* hit end of list */
601 || (ldid != pCurr->pldd->ldid) )
602 return ERR_VCP_LDDFIND; /* correct ? */
604 /* ok, found our victim: eliminate it */
607 pPrev->next = pCurr->next;
609 if (pCurr == pFirstLDD)
611 HeapFree(GetProcessHeap(), 0, pCurr);
616 /***********************************************************************
617 * CtlDelLdd (SETUPX.37)
619 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
621 FIXME("(%d); - please report to a.mohr@mailto.de !!!\n", ldid);
622 return SETUPX_DelLdd(ldid);
625 /***********************************************************************
626 * CtlFindLdd (SETUPX.35)
628 * doesn't check pldd ptr validity: crash (W98SE)
631 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
632 * 1 in all other cases ??
635 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
637 LDD_LIST *pCurr, *pPrev = NULL;
639 TRACE("(%p)\n", pldd);
642 SETUPX_CreateStandardLDDs();
644 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
645 return ERR_VCP_LDDINVALID;
648 /* search until we find the appropriate LDD or hit the end */
649 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
654 if ( (pCurr == NULL) /* hit end of list */
655 || (pldd->ldid != pCurr->pldd->ldid) )
656 return ERR_VCP_LDDFIND; /* correct ? */
658 memcpy(pldd, pCurr->pldd, pldd->cbSize);
659 /* hmm, we probably ought to strcpy() the string ptrs here */
661 return 1; /* what is this ?? */
664 /***********************************************************************
665 * CtlSetLdd (SETUPX.33)
670 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
673 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
675 LDD_LIST *pCurr, *pPrev = NULL;
676 LPLOGDISKDESC pCurrLDD;
680 TRACE("(%p)\n", pldd);
683 SETUPX_CreateStandardLDDs();
685 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
686 return ERR_VCP_LDDINVALID;
688 heap = GetProcessHeap();
690 /* search until we find the appropriate LDD or hit the end */
691 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
696 if (pCurr == NULL) /* hit end of list */
699 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
700 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
702 pCurrLDD = pCurr->pldd;
706 pCurrLDD = pCurr->pldd;
707 if (pCurrLDD->pszPath) HeapFree(heap, 0, pCurrLDD->pszPath);
708 if (pCurrLDD->pszVolLabel) HeapFree(heap, 0, pCurrLDD->pszVolLabel);
709 if (pCurrLDD->pszDiskName) HeapFree(heap, 0, pCurrLDD->pszDiskName);
712 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
716 pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
717 strcpy( pCurrLDD->pszPath, pldd->pszPath );
719 if (pldd->pszVolLabel)
721 pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
722 strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
724 if (pldd->pszDiskName)
726 pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
727 strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
730 if (is_new) /* link into list */
734 pCurr->next = pPrev->next;
745 /***********************************************************************
746 * CtlAddLdd (SETUPX.36)
748 * doesn't check pldd ptr validity: crash (W98SE)
751 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
752 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
754 pldd->ldid = ldid_to_add++;
755 return CtlSetLdd16(pldd);
758 /***********************************************************************
759 * CtlGetLdd (SETUPX.34)
761 * doesn't check pldd ptr validity: crash (W98SE)
762 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
765 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
768 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
770 LDD_LIST *pCurr, *pPrev = NULL;
773 SETUPX_CreateStandardLDDs();
775 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
776 return ERR_VCP_LDDINVALID;
779 /* search until we find the appropriate LDD or hit the end */
780 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
785 if (pCurr == NULL) /* hit end of list */
786 return ERR_VCP_LDDFIND; /* correct ? */
788 memcpy(pldd, pCurr->pldd, pldd->cbSize);
789 /* hmm, we probably ought to strcpy() the string ptrs here */
794 /**********************************************************************/
796 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
798 FIXME("(%p); - please report to a.mohr@mailto.de !!!\n", pldd);
799 return SETUPX_GetLdd(pldd);
802 /***********************************************************************
803 * CtlGetLddPath (SETUPX.38)
805 * Gets the path of an LDD.
806 * No crash if szPath == NULL.
807 * szPath has to be at least MAX_PATH_LEN bytes long.
809 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
811 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
813 TRACE("(%d, %p);\n", ldid, szPath);
819 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
820 return ERR_VCP_LDDUNINIT;
822 strcpy(szPath, ldd.pszPath);
823 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
828 /***********************************************************************
829 * CtlSetLddPath (SETUPX.508)
831 * Sets the path of an LDD.
832 * Creates LDD for LDID if not existing yet.
834 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
837 TRACE("(%d, '%s');\n", ldid, szPath);
840 ldd.pszPath = szPath;
841 return CtlSetLdd16(&ldd);
845 * Find the value of a custom LDID in a .inf file
847 * 49300,49301=ProgramFilesDir,5
848 * -- profile section lookup -->
850 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"%24%"
851 * -- GenFormStrWithoutPlaceHolders16 -->
852 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
853 * -- registry lookup -->
854 * C:\Program Files (or C:\ if not found in registry)
857 * - maybe we ought to add a caching array for speed ? - I don't care :)
858 * - not sure whether the processing is correct - sometimes there are equal
859 * LDIDs for both install and removal sections.
860 * - probably the whole function can be removed as installers add that on their
863 static BOOL SETUPX_AddCustomLDID(int ldid, INT16 hInf)
866 LPSTR sectionbuf = NULL, entrybuf = NULL, regsectionbuf = NULL;
868 LPSTR pSec, pEnt, pEqual, p, *pSub = NULL;
870 char buffer[MAX_PATH];
873 sprintf(ldidstr, "%d", ldid);
874 filename = IP_GetFileName(hInf);
875 if (!(sectionbuf = SETUPX_GetSections(filename)))
877 ERR("couldn't get sections !\n");
880 for (pSec=sectionbuf; *pSec; pSec += strlen(pSec)+1)
882 if (!(entrybuf = SETUPX_GetSectionEntries(filename, pSec)))
884 ERR("couldn't get section entries !\n");
887 for (pEnt=entrybuf; *pEnt; pEnt += strlen(pEnt)+1)
889 if (strstr(pEnt, ldidstr))
891 pEqual = strchr(pEnt, '=');
892 if (!pEqual) /* crippled entry ?? */
895 /* make sure we found the LDID on left side of the equation */
896 if (pEnt+strlen(ldidstr) <= pEqual)
899 /* but we don't want entries in the strings section */
900 if (!strcasecmp(pSec, "Strings")) continue;
909 TRACE("found entry '%s'\n", p);
910 pSub = SETUPX_GetSubStrings(p, ',');
911 if (*(DWORD *)pSub > 2)
913 ERR("malformed entry '%s' ?\n", p);
916 TRACE("found section '%s'\n", *(pSub+1));
917 /* FIXME: what are the optional flags at the end of an entry used for ?? */
919 /* get the location of the registry key from that section */
920 if (!(regsectionbuf = SETUPX_GetSectionEntries(filename, *(pSub+1))))
922 ERR("couldn't get registry section entries !\n");
925 /* sectionbuf is > 1024 bytes anyway, so use it */
926 GenFormStrWithoutPlaceHolders16(sectionbuf, regsectionbuf, hInf);
927 ret = SETUPX_LookupRegistryString(sectionbuf, buffer, MAX_PATH);
928 TRACE("return '%s'\n", buffer);
930 ldd.pszPath = buffer;
933 SETUPX_FreeSubStrings(pSub);
934 if (sectionbuf) HeapFree(GetProcessHeap(), 0, sectionbuf);
935 if (entrybuf) HeapFree(GetProcessHeap(), 0, entrybuf);
936 if (regsectionbuf) HeapFree(GetProcessHeap(), 0, regsectionbuf);
941 * Translate a logical disk identifier (LDID) into its string representation
942 * I'm afraid this can be totally replaced by CtlGetLddPath().
944 static BOOL SETUPX_IP_TranslateLDID(int ldid, LPSTR *p, HINF16 hInf)
946 BOOL handled = FALSE;
949 ldd.cbSize = sizeof(LOGDISKDESC_S);
951 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
953 /* hmm, it seems the installers already do the work for us
954 * (by calling CtlSetLddPath) that SETUPX_AddCustomLDID
955 * is supposed to do. Grmbl ;-)
956 * Well, I'll leave it here anyway, but print error... */
957 ERR("hmm, LDID %d not registered yet !?\n", ldid);
958 handled = SETUPX_AddCustomLDID(ldid, hInf);
967 FIXME("What is LDID %d ??\n", ldid);
976 /***********************************************************************
977 * GenFormStrWithoutPlaceHolders (SETUPX.103)
979 * ought to be pretty much implemented, I guess...
981 void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
983 LPCSTR pSrc = szSrc, pSrcEnd = szSrc + strlen(szSrc);
984 LPSTR pDst = szDst, p, pPHBegin;
987 TRACE("(%p, '%s', %04x);\n", szDst, szSrc, hInf);
988 while (pSrc < pSrcEnd)
990 p = strchr(pSrc, '%');
993 count = (int)p - (int)pSrc;
994 strncpy(pDst, pSrc, count);
998 p = strchr(pPHBegin, '%');
1001 char placeholder[80]; /* that really ought to be enough ;) */
1004 count = (int)p - (int)pPHBegin;
1005 strncpy(placeholder, pPHBegin, count);
1006 placeholder[count] = '\0';
1007 ldid = atoi(placeholder);
1011 done = SETUPX_IP_TranslateLDID(ldid, &p, hInf);
1014 pDst += strlen(pDst);
1017 { /* hmm, string placeholder. Need to look up
1018 in the [strings] section of the hInf */
1020 char buf[256]; /* long enough ? */
1022 ret = GetPrivateProfileStringA("strings", placeholder, "",
1023 buf, 256, IP_GetFileName(hInf));
1027 pDst += strlen(buf);
1031 ERR("placeholder string '%s' not found !\n", placeholder);
1036 { /* copy raw placeholder string over */
1037 count = (int)p - (int)pPHBegin + 2;
1038 strncpy(pDst, pPHBegin-1, count);
1047 /* copy the remaining source string over */
1048 strncpy(pDst, pSrc, (int)pSrcEnd - (int)pSrc + 1);
1051 TRACE("ret '%s'\n", szDst);
1055 * Copy all items in a CopyFiles entry over to the destination
1057 * - VNLP_xxx is what is given as flags for a .INF CopyFiles section
1059 static BOOL SETUPX_CopyFiles(LPSTR *pSub, HINF16 hInf)
1061 BOOL bSingle = FALSE;
1063 LPCSTR filename = IP_GetFileName(hInf);
1065 char pDstStr[MAX_PATH];
1066 LPSTR pSrcDir, pDstDir;
1067 LPSTR pFileEntries, p;
1071 LPSTR pSrcFile, pDstFile;
1074 for (n=0; n < *(DWORD *)pSub; n++)
1076 pCopyEntry = *(pSub+1+n);
1077 if (*pCopyEntry == '@')
1085 /* get source directory for that entry */
1086 INIT_LDD(ldd, LDID_SRCPATH);
1087 SETUPX_GetLdd(&ldd);
1088 pSrcDir = ldd.pszPath;
1090 /* get destination directory for that entry */
1091 if (!(GetPrivateProfileStringA("DestinationDirs", pCopyEntry, "",
1092 pDstStr, sizeof(pDstStr), filename)))
1094 /* hmm, not found; try the default entry */
1095 if (!(GetPrivateProfileStringA("DestinationDirs", "DefaultDestDir", "", pDstStr, sizeof(pDstStr), filename)))
1097 WARN("DefaultDestDir not found.\n");
1102 /* translate destination dir if given as LDID */
1103 ldid = atoi(pDstStr);
1106 if (!(SETUPX_IP_TranslateLDID(ldid, &pDstDir, hInf)))
1112 /* now that we have the destination dir, register file copying */
1116 VcpQueueCopy16(pCopyEntry, pCopyEntry, pSrcDir, pDstDir, LDID_SRCPATH, ldid ? ldid : 0xffff, 0, VFNL_COPY, 0);
1120 /* entry wasn't a single file, so let's iterate over section */
1121 pFileEntries = SETUPX_GetSectionEntries(filename, pCopyEntry);
1122 for (p=pFileEntries; *p; p +=strlen(p)+1)
1124 pSubFile = SETUPX_GetSubStrings(p, ',');
1125 pSrcFile = *(pSubFile+1);
1126 pDstFile = (*(DWORD *)pSubFile > 1) ? *(pSubFile+2) : pSrcFile;
1127 TRACE("copying file '%s\\%s' to '%s\\%s'\n", pSrcDir, pSrcFile, pDstDir, pDstFile);
1129 if (*(DWORD *)pSubFile > 2)
1131 if ((flag = atoi(*(pSubFile+3)))) /* ah, flag */
1134 FIXME("VNLP_xxx flag %d not handled yet.\n", flag);
1138 FIXME("temp file name '%s' given. Need to register in wininit.ini !\n", *(pSubFile+3));
1139 /* we probably need to set VIRTNODE.vhstrDstFinalName to
1140 * the final destination name, and the temp name is merely
1141 * the copy destination */
1144 VcpQueueCopy16(pSrcFile, pDstFile, pSrcDir, pDstDir, LDID_SRCPATH, ldid ? ldid : 0xffff, 0, VFNL_COPY|flag, 0);
1145 SETUPX_FreeSubStrings(pSubFile);
1152 /***********************************************************************
1153 * GenInstall (SETUPX.101)
1155 * generic installer function for .INF file sections
1157 * This is not perfect - patch whenever you can !
1159 * wFlags == GENINSTALL_DO_xxx
1161 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
1162 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
1164 RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
1166 LPCSTR filename = IP_GetFileName(hInfFile);
1167 LPSTR pEntries, p, pEnd;
1171 FIXME("(%04x, '%s', %04x), semi-stub. Please implement additional operations here !\n", hInfFile, szInstallSection, wFlags);
1172 pEntries = SETUPX_GetSectionEntries(filename, szInstallSection);
1175 ERR("couldn't find entries for section '%s' !\n", szInstallSection);
1176 return ERR_IP_SECT_NOT_FOUND;
1178 for (p=pEntries; *p; p +=strlen(p)+1)
1180 pEnd = strchr(p, '=');
1181 if (!pEnd) continue;
1182 pSub = SETUPX_GetSubStrings(pEnd+1, ','); /* split entries after the '=' */
1183 SETUPX_IsolateSubString(&p, &pEnd);
1184 len = (int)pEnd - (int)p;
1186 if (wFlags & GENINSTALL_DO_FILES)
1188 if (!strncasecmp(p, "CopyFiles", len))
1190 SETUPX_CopyFiles(pSub, hInfFile);
1195 if (!strncasecmp(p, "DelFiles", len))
1197 SETUPX_DelFiles(filename, szInstallSection, pSub);
1202 if (wFlags & GENINSTALL_DO_INI)
1205 if (!strncasecmp(p, "UpdateInis", len))
1207 SETUPX_UpdateInis(filename, szInstallSection, pSub);
1212 if (wFlags & GENINSTALL_DO_REG)
1215 /* probably use SUReg*() functions here */
1216 if (!strncasecmp(p, "AddReg", len))
1218 SETUPX_AddReg(filename, szInstallSection, pSub);
1222 if (!strncasecmp(p, "DelReg", len))
1224 SETUPX_DelReg(filename, szInstallSection, pSub);
1230 SETUPX_FreeSubStrings(pSub);
1232 HeapFree(GetProcessHeap(), 0, pEntries);