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"
53 #include "debugtools.h"
55 DEFAULT_DEBUG_CHANNEL(setupapi);
57 /***********************************************************************
58 * SURegOpenKey (SETUPX.47)
60 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, LPHKEY retkey )
62 FIXME("(%x,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
63 return RegOpenKeyA( hkey, lpszSubKey, retkey );
66 /***********************************************************************
67 * SURegQueryValueEx (SETUPX.50)
69 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
70 LPDWORD lpdwReserved, LPDWORD lpdwType,
71 LPBYTE lpbData, LPDWORD lpcbData )
73 FIXME("(%x,%s,%p,%p,%p,%ld), semi-stub.\n",hkey,debugstr_a(lpszValueName),
74 lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
75 return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
80 * Returns pointer to a string list with the first entry being number
83 * Hmm. Should this be InitSubstrData(), GetFirstSubstr() and GetNextSubstr()
86 static LPSTR *SETUPX_GetSubStrings(LPSTR start, char delimiter)
97 /* find beginning of real substring */
98 while ( (*p == ' ') || (*p == '\t') || (*p == '"') ) p++;
100 /* find end of real substring */
103 && (*q != ' ') && (*q != '\t') && (*q != '"')
104 && (*q != ';') && (*q != delimiter) ) q++;
107 len = (int)q - (int)p;
109 /* alloc entry for new substring in steps of 32 units and copy over */
111 { /* 1 for count field + current count + 32 */
112 res = HeapReAlloc(GetProcessHeap(), 0, res, (1+count+32)*sizeof(LPSTR));
114 *(res+1+count) = HeapAlloc(GetProcessHeap(), 0, len+1);
115 strncpy(*(res+1+count), p, len);
116 (*(res+1+count))[len] = '\0';
119 /* we are still within last substring (before delimiter),
120 * so get out of it */
121 while ((*q) && (*q != ';') && (*q != delimiter)) q++;
122 if ((!*q) || (*q == ';'))
127 /* put number of entries at beginning of list */
128 *(DWORD *)res = count;
132 static void SETUPX_FreeSubStrings(LPSTR *substr)
134 DWORD count = *(DWORD *)substr;
135 LPSTR *pStrings = substr+1;
138 for (n=0; n < count; n++)
139 HeapFree(GetProcessHeap(), 0, *pStrings++);
141 HeapFree(GetProcessHeap(), 0, substr);
144 static void SETUPX_IsolateSubString(LPSTR *begin, LPSTR *end)
151 while ((p < q) && ((*p == ' ') || (*p == '\t'))) p++;
152 while ((p < q) && (*p == '"')) p++;
154 while ((q-1 >= p) && ((*(q-1) == ' ') || (*(q-1) == '\t'))) q--;
155 while ((q-1 >= p) && (*(q-1) == '"')) q--;
162 * Example: HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
163 * FIXME: use SETUPX_GetSubStrings() instead.
164 * Hmm, but on the other hand SETUPX_GetSubStrings() will probably
165 * soon be replaced by InitSubstrData() etc. anyway.
168 static BOOL SETUPX_LookupRegistryString(LPSTR regstr, LPSTR buffer, DWORD buflen)
170 HANDLE heap = GetProcessHeap();
177 TRACE("retrieving '%s'\n", regstr);
181 /* isolate root key, subkey, value, flag, defval */
182 for (n=0; n < 5; n++)
195 SETUPX_IsolateSubString(&p, &q);
196 len = (int)q - (int)p;
197 items[n] = HeapAlloc(heap, 0, len+1);
198 strncpy(items[n], p, len);
199 items[n][len] = '\0';
202 TRACE("got '%s','%s','%s','%s','%s'\n",
203 items[0], items[1], items[2], items[3], items[4]);
206 if (!strcasecmp(items[0], "HKCR"))
207 hkey = HKEY_CLASSES_ROOT;
209 if (!strcasecmp(items[0], "HKCU"))
210 hkey = HKEY_CURRENT_USER;
212 if (!strcasecmp(items[0], "HKLM"))
213 hkey = HKEY_LOCAL_MACHINE;
215 if (!strcasecmp(items[0], "HKU"))
218 { /* HKR ? -> relative to key passed to GenInstallEx */
219 FIXME("unsupported regkey '%s'\n", items[0]);
223 if (RegOpenKeyA(hkey, items[1], &hsubkey) != ERROR_SUCCESS)
226 if (RegQueryValueExA(hsubkey, items[2], NULL, &dwType, buffer, &buflen)
232 if (buffer) strcpy(buffer, items[4]); /* I don't care about buflen */
234 for (n=0; n < 5; n++)
235 HeapFree(heap, 0, items[n]);
237 TRACE("return '%s'\n", buffer);
241 static LPSTR SETUPX_GetSections(LPCSTR filename)
244 DWORD len = 1024, res;
247 buf = HeapReAlloc(GetProcessHeap(), 0, buf, len);
248 res = GetPrivateProfileStringA(NULL, NULL, NULL, buf, len, filename);
250 } while ((!res) && (len < 1048576));
253 HeapFree(GetProcessHeap(), 0, buf);
259 static LPSTR SETUPX_GetSectionEntries(LPCSTR filename, LPCSTR section)
262 DWORD len = 1024, res;
265 buf = HeapReAlloc(GetProcessHeap(), 0, buf, len);
266 res = GetPrivateProfileSectionA(section, buf, len, filename);
268 } while ((!res) && (len < 1048576));
271 HeapFree(GetProcessHeap(), 0, buf);
278 /***********************************************************************
281 * hwnd = parent window
282 * hinst = instance of SETUPX.DLL
283 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
284 * Here "DefaultInstall" is the .inf file section to be installed (optional).
285 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
287 * nCmdShow = nCmdShow of CreateProcess
289 typedef INT WINAPI (*MSGBOX_PROC)( HWND, LPCSTR, LPCSTR, UINT );
290 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
295 RETERR16 res = OK, tmp;
299 MSGBOX_PROC pMessageBoxA;
301 TRACE("(%04x, %04x, %s, %d);\n", hwnd, hinst, lpszCmdLine, nCmdShow);
303 pSub = SETUPX_GetSubStrings((LPSTR)lpszCmdLine, ' ');
305 count = *(DWORD *)pSub;
306 if (count < 2) /* invalid number of arguments ? */
308 if (IpOpen16(*(pSub+count), &hInf) != OK)
310 res = ERROR_FILE_NOT_FOUND; /* yes, correct */
313 if (VcpOpen16(NULL, 0))
315 if (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
317 wFlags = atoi(*(pSub+count-1)) & ~128;
320 case HOW_ALWAYS_SILENT_REBOOT:
321 case HOW_SILENT_REBOOT:
324 case HOW_ALWAYS_PROMPT_REBOOT:
325 case HOW_PROMPT_REBOOT:
326 if ((hMod = GetModuleHandleA("user32.dll")))
328 if ((pMessageBoxA = (MSGBOX_PROC)GetProcAddress( hMod, "MessageBoxA" )))
331 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)
337 ERR("invalid flags %d !\n", wFlags);
343 tmp = VcpClose16(VCPFL_ALL, NULL);
346 tmp = IpClose16(hInf);
349 SETUPX_FreeSubStrings(pSub);
352 /* FIXME: we should have a means of terminating all wine + wineserver */
353 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
363 LPCSTR StdString; /* fallback string; sub dir of windows directory */
366 static const LDID_DATA LDID_Data[34] =
368 { /* 0 (LDID_NULL) -- not defined */
372 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
373 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
376 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
380 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
384 { /* 4 (LDID_BACKUP) = backup dir */
388 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
392 { /* 6 -- not defined */
396 { /* 7 -- not defined */
400 { /* 8 -- not defined */
404 { /* 9 -- not defined */
408 { /* 10 (LDID_WIN) = windows dir */
412 { /* 11 (LDID_SYS) = system dir */
414 NULL /* call GetSystemDirectory() instead */
416 { /* 12 (LDID_IOS) = IOSubSys dir */
417 NULL, /* FIXME: registry string ? */
420 { /* 13 (LDID_CMD) = COMMAND dir */
421 NULL, /* FIXME: registry string ? */
424 { /* 14 (LDID_CPL) = control panel dir */
428 { /* 15 (LDID_PRINT) = windows printer dir */
430 "SYSTEM" /* correct ?? */
432 { /* 16 (LDID_MAIL) = destination mail dir */
436 { /* 17 (LDID_INF) = INF dir */
437 "SetupScratchDir", /* correct ? */
440 { /* 18 (LDID_HELP) = HELP dir */
444 { /* 19 (LDID_WINADMIN) = Admin dir */
448 { /* 20 (LDID_FONTS) = Fonts dir */
452 { /* 21 (LDID_VIEWERS) = Viewers */
456 { /* 22 (LDID_VMM32) = VMM32 dir */
460 { /* 23 (LDID_COLOR) = ICM dir */
464 { /* 24 (LDID_APPS) = root of boot drive ? */
468 { /* 25 (LDID_SHARED) = shared dir */
472 { /* 26 (LDID_WINBOOT) = Windows boot dir */
476 { /* 27 (LDID_MACHINE) = machine specific files */
480 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
484 { /* 29 -- not defined */
488 { /* 30 (LDID_BOOT) = Root of boot drive */
492 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
496 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
500 { /* 33 (LDID_OLD_WIN) = old win dir */
504 /* the rest (34-38) isn't too interesting, so I'll forget about it */
508 * LDD == Logical Device Descriptor
509 * LDID == Logical Device ID
511 * The whole LDD/LDID business might go into a separate file named
513 * At the moment I don't know what the hell these functions are really doing.
514 * That's why I added reporting stubs.
515 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
516 * That's why I implemented them in a way that's suitable for my purpose.
518 static LDD_LIST *pFirstLDD = NULL;
520 static BOOL std_LDDs_done = FALSE;
522 void SETUPX_CreateStandardLDDs(void)
528 char buffer[MAX_PATH];
530 /* has to be here, otherwise loop */
531 std_LDDs_done = TRUE;
533 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
535 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
540 if ( (hKey) && (LDID_Data[n].RegValName)
541 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
542 NULL, &type, buffer, &len) == ERROR_SUCCESS)
543 && (type == REG_SZ) )
545 TRACE("found value '%s' for LDID %d\n", buffer, n);
551 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
552 strcpy(buffer, "X:\\FIXME");
555 GetSystemDirectoryA(buffer, MAX_PATH);
559 case LDID_HOST_WINBOOT:
562 strcpy(buffer, "C:\\");
565 if (LDID_Data[n].StdString)
567 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
571 strcpy(p, LDID_Data[n].StdString);
578 ldd.pszPath = buffer;
579 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
583 if (hKey) RegCloseKey(hKey);
586 /***********************************************************************
587 * CtlDelLdd (SETUPX.37)
590 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
592 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
594 LDD_LIST *pCurr, *pPrev = NULL;
596 TRACE("(%d)\n", ldid);
599 SETUPX_CreateStandardLDDs();
601 if (ldid < LDID_ASSIGN_START)
602 return ERR_VCP_LDDINVALID;
605 /* search until we find the appropriate LDD or hit the end */
606 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
611 if ( (pCurr == NULL) /* hit end of list */
612 || (ldid != pCurr->pldd->ldid) )
613 return ERR_VCP_LDDFIND; /* correct ? */
615 /* ok, found our victim: eliminate it */
618 pPrev->next = pCurr->next;
620 if (pCurr == pFirstLDD)
622 HeapFree(GetProcessHeap(), 0, pCurr);
627 /***********************************************************************
628 * CtlDelLdd (SETUPX.37)
630 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
632 FIXME("(%d); - please report to a.mohr@mailto.de !!!\n", ldid);
633 return SETUPX_DelLdd(ldid);
636 /***********************************************************************
637 * CtlFindLdd (SETUPX.35)
639 * doesn't check pldd ptr validity: crash (W98SE)
642 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
643 * 1 in all other cases ??
646 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
648 LDD_LIST *pCurr, *pPrev = NULL;
650 TRACE("(%p)\n", pldd);
653 SETUPX_CreateStandardLDDs();
655 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
656 return ERR_VCP_LDDINVALID;
659 /* search until we find the appropriate LDD or hit the end */
660 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
665 if ( (pCurr == NULL) /* hit end of list */
666 || (pldd->ldid != pCurr->pldd->ldid) )
667 return ERR_VCP_LDDFIND; /* correct ? */
669 memcpy(pldd, pCurr->pldd, pldd->cbSize);
670 /* hmm, we probably ought to strcpy() the string ptrs here */
672 return 1; /* what is this ?? */
675 /***********************************************************************
676 * CtlSetLdd (SETUPX.33)
681 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
684 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
686 LDD_LIST *pCurr, *pPrev = NULL;
687 LPLOGDISKDESC pCurrLDD;
691 TRACE("(%p)\n", pldd);
694 SETUPX_CreateStandardLDDs();
696 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
697 return ERR_VCP_LDDINVALID;
699 heap = GetProcessHeap();
701 /* search until we find the appropriate LDD or hit the end */
702 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
707 if (pCurr == NULL) /* hit end of list */
710 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
711 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
713 pCurrLDD = pCurr->pldd;
717 pCurrLDD = pCurr->pldd;
718 if (pCurrLDD->pszPath) HeapFree(heap, 0, pCurrLDD->pszPath);
719 if (pCurrLDD->pszVolLabel) HeapFree(heap, 0, pCurrLDD->pszVolLabel);
720 if (pCurrLDD->pszDiskName) HeapFree(heap, 0, pCurrLDD->pszDiskName);
723 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
726 pCurrLDD->pszPath = HEAP_strdupA(heap, 0, pldd->pszPath);
727 if (pldd->pszVolLabel)
728 pCurrLDD->pszVolLabel = HEAP_strdupA(heap, 0, pldd->pszVolLabel);
729 if (pldd->pszDiskName)
730 pCurrLDD->pszDiskName = HEAP_strdupA(heap, 0, pldd->pszDiskName);
732 if (is_new) /* link into list */
736 pCurr->next = pPrev->next;
747 /***********************************************************************
748 * CtlAddLdd (SETUPX.36)
750 * doesn't check pldd ptr validity: crash (W98SE)
753 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
754 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
756 pldd->ldid = ldid_to_add++;
757 return CtlSetLdd16(pldd);
760 /***********************************************************************
761 * CtlGetLdd (SETUPX.34)
763 * doesn't check pldd ptr validity: crash (W98SE)
764 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
767 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
770 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
772 LDD_LIST *pCurr, *pPrev = NULL;
775 SETUPX_CreateStandardLDDs();
777 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
778 return ERR_VCP_LDDINVALID;
781 /* search until we find the appropriate LDD or hit the end */
782 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
787 if (pCurr == NULL) /* hit end of list */
788 return ERR_VCP_LDDFIND; /* correct ? */
790 memcpy(pldd, pCurr->pldd, pldd->cbSize);
791 /* hmm, we probably ought to strcpy() the string ptrs here */
796 /**********************************************************************/
798 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
800 FIXME("(%p); - please report to a.mohr@mailto.de !!!\n", pldd);
801 return SETUPX_GetLdd(pldd);
804 /***********************************************************************
805 * CtlGetLddPath (SETUPX.38)
807 * Gets the path of an LDD.
808 * No crash if szPath == NULL.
809 * szPath has to be at least MAX_PATH_LEN bytes long.
811 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
813 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
815 TRACE("(%d, %p);\n", ldid, szPath);
821 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
822 return ERR_VCP_LDDUNINIT;
824 strcpy(szPath, ldd.pszPath);
825 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
830 /***********************************************************************
831 * CtlSetLddPath (SETUPX.508)
833 * Sets the path of an LDD.
834 * Creates LDD for LDID if not existing yet.
836 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
839 TRACE("(%d, '%s');\n", ldid, szPath);
842 ldd.pszPath = szPath;
843 return CtlSetLdd16(&ldd);
847 * Find the value of a custom LDID in a .inf file
849 * 49300,49301=ProgramFilesDir,5
850 * -- profile section lookup -->
852 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"%24%"
853 * -- GenFormStrWithoutPlaceHolders16 -->
854 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
855 * -- registry lookup -->
856 * C:\Program Files (or C:\ if not found in registry)
859 * - maybe we ought to add a caching array for speed ? - I don't care :)
860 * - not sure whether the processing is correct - sometimes there are equal
861 * LDIDs for both install and removal sections.
862 * - probably the whole function can be removed as installers add that on their
865 static BOOL SETUPX_AddCustomLDID(int ldid, INT16 hInf)
868 LPSTR sectionbuf = NULL, entrybuf = NULL, regsectionbuf = NULL;
870 LPSTR pSec, pEnt, pEqual, p, *pSub = NULL;
872 char buffer[MAX_PATH];
875 sprintf(ldidstr, "%d", ldid);
876 filename = IP_GetFileName(hInf);
877 if (!(sectionbuf = SETUPX_GetSections(filename)))
879 ERR("couldn't get sections !\n");
882 for (pSec=sectionbuf; *pSec; pSec += strlen(pSec)+1)
884 if (!(entrybuf = SETUPX_GetSectionEntries(filename, pSec)))
886 ERR("couldn't get section entries !\n");
889 for (pEnt=entrybuf; *pEnt; pEnt += strlen(pEnt)+1)
891 if (strstr(pEnt, ldidstr))
893 pEqual = strchr(pEnt, '=');
894 if (!pEqual) /* crippled entry ?? */
897 /* make sure we found the LDID on left side of the equation */
898 if (pEnt+strlen(ldidstr) <= pEqual)
901 /* but we don't want entries in the strings section */
902 if (!strcasecmp(pSec, "Strings"))
913 TRACE("found entry '%s'\n", p);
914 pSub = SETUPX_GetSubStrings(p, ',');
915 if (*(DWORD *)pSub > 2)
917 ERR("malformed entry '%s' ?\n", p);
920 TRACE("found section '%s'\n", *(pSub+1));
921 /* FIXME: what are the optional flags at the end of an entry used for ?? */
923 /* get the location of the registry key from that section */
924 if (!(regsectionbuf = SETUPX_GetSectionEntries(filename, *(pSub+1))))
926 ERR("couldn't get registry section entries !\n");
929 /* sectionbuf is > 1024 bytes anyway, so use it */
930 GenFormStrWithoutPlaceHolders16(sectionbuf, regsectionbuf, hInf);
931 ret = SETUPX_LookupRegistryString(sectionbuf, buffer, MAX_PATH);
932 TRACE("return '%s'\n", buffer);
934 ldd.pszPath = buffer;
937 SETUPX_FreeSubStrings(pSub);
938 if (sectionbuf) HeapFree(GetProcessHeap(), 0, sectionbuf);
939 if (entrybuf) HeapFree(GetProcessHeap(), 0, entrybuf);
940 if (regsectionbuf) HeapFree(GetProcessHeap(), 0, regsectionbuf);
945 * Translate a logical disk identifier (LDID) into its string representation
946 * I'm afraid this can be totally replaced by CtlGetLddPath().
948 static BOOL SETUPX_IP_TranslateLDID(int ldid, LPSTR *p, HINF16 hInf)
950 BOOL handled = FALSE;
953 ldd.cbSize = sizeof(LOGDISKDESC_S);
955 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
957 /* hmm, it seems the installers already do the work for us
958 * (by calling CtlSetLddPath) that SETUPX_AddCustomLDID
959 * is supposed to do. Grmbl ;-)
960 * Well, I'll leave it here anyway, but print error... */
961 ERR("hmm, LDID %d not registered yet !?\n", ldid);
962 handled = SETUPX_AddCustomLDID(ldid, hInf);
971 FIXME("What is LDID %d ??\n", ldid);
980 /***********************************************************************
981 * GenFormStrWithoutPlaceHolders
983 * ought to be pretty much implemented, I guess...
985 void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
987 LPCSTR pSrc = szSrc, pSrcEnd = szSrc + strlen(szSrc);
988 LPSTR pDst = szDst, p, pPHBegin;
991 TRACE("(%p, '%s', %04x);\n", szDst, szSrc, hInf);
992 while (pSrc < pSrcEnd)
994 p = strchr(pSrc, '%');
997 count = (int)p - (int)pSrc;
998 strncpy(pDst, pSrc, count);
1002 p = strchr(pPHBegin, '%');
1005 char placeholder[80]; /* that really ought to be enough ;) */
1008 count = (int)p - (int)pPHBegin;
1009 strncpy(placeholder, pPHBegin, count);
1010 placeholder[count] = '\0';
1011 ldid = atoi(placeholder);
1015 done = SETUPX_IP_TranslateLDID(ldid, &p, hInf);
1018 pDst += strlen(pDst);
1021 { /* hmm, string placeholder. Need to look up
1022 in the [strings] section of the hInf */
1024 char buf[256]; /* long enough ? */
1026 ret = GetPrivateProfileStringA("strings", placeholder, "",
1027 buf, 256, IP_GetFileName(hInf));
1031 pDst += strlen(buf);
1035 ERR("placeholder string '%s' not found !\n", placeholder);
1040 { /* copy raw placeholder string over */
1041 count = (int)p - (int)pPHBegin + 2;
1042 strncpy(pDst, pPHBegin-1, count);
1051 /* copy the remaining source string over */
1052 strncpy(pDst, pSrc, (int)pSrcEnd - (int)pSrc + 1);
1055 TRACE("ret '%s'\n", szDst);
1059 * Copy all items in a CopyFiles entry over to the destination
1061 * - VNLP_xxx is what is given as flags for a .INF CopyFiles section
1063 static BOOL SETUPX_CopyFiles(LPSTR *pSub, HINF16 hInf)
1065 BOOL bSingle = FALSE;
1067 LPCSTR filename = IP_GetFileName(hInf);
1069 char pDstStr[MAX_PATH];
1070 LPSTR pSrcDir, pDstDir;
1071 LPSTR pFileEntries, p;
1075 LPSTR pSrcFile, pDstFile;
1078 for (n=0; n < *(DWORD *)pSub; n++)
1080 pCopyEntry = *(pSub+1+n);
1081 if (*pCopyEntry == '@')
1089 /* get source directory for that entry */
1090 INIT_LDD(ldd, LDID_SRCPATH);
1091 SETUPX_GetLdd(&ldd);
1092 pSrcDir = ldd.pszPath;
1094 /* get destination directory for that entry */
1095 if (!(GetPrivateProfileStringA("DestinationDirs", pCopyEntry, "",
1096 pDstStr, sizeof(pDstStr), filename)))
1098 /* hmm, not found; try the default entry */
1099 if (!(GetPrivateProfileStringA("DestinationDirs", "DefaultDestDir", "", pDstStr, sizeof(pDstStr), filename)))
1101 WARN("DefaultDestDir not found.\n");
1106 /* translate destination dir if given as LDID */
1107 ldid = atoi(pDstStr);
1110 if (!(SETUPX_IP_TranslateLDID(ldid, &pDstDir, hInf)))
1116 /* now that we have the destination dir, register file copying */
1120 VcpQueueCopy16(pCopyEntry, pCopyEntry, pSrcDir, pDstDir, LDID_SRCPATH, ldid ? ldid : 0xffff, 0, VFNL_COPY, 0);
1124 /* entry wasn't a single file, so let's iterate over section */
1125 pFileEntries = SETUPX_GetSectionEntries(filename, pCopyEntry);
1126 for (p=pFileEntries; *p; p +=strlen(p)+1)
1128 pSubFile = SETUPX_GetSubStrings(p, ',');
1129 pSrcFile = *(pSubFile+1);
1130 pDstFile = (*(DWORD *)pSubFile > 1) ? *(pSubFile+2) : pSrcFile;
1131 TRACE("copying file '%s\\%s' to '%s\\%s'\n", pSrcDir, pSrcFile, pDstDir, pDstFile);
1133 if (*(DWORD *)pSubFile > 2)
1135 if ((flag = atoi(*(pSubFile+3)))) /* ah, flag */
1138 FIXME("VNLP_xxx flag %d not handled yet.\n", flag);
1142 FIXME("temp file name '%s' given. Need to register in wininit.ini !\n", *(pSubFile+3));
1143 /* we probably need to set VIRTNODE.vhstrDstFinalName to
1144 * the final destination name, and the temp name is merely
1145 * the copy destination */
1148 VcpQueueCopy16(pSrcFile, pDstFile, pSrcDir, pDstDir, LDID_SRCPATH, ldid ? ldid : 0xffff, 0, VFNL_COPY|flag, 0);
1149 SETUPX_FreeSubStrings(pSubFile);
1156 /***********************************************************************
1159 * generic installer function for .INF file sections
1161 * This is not perfect - patch whenever you can !
1163 * wFlags == GENINSTALL_DO_xxx
1165 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
1166 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
1168 RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
1170 LPCSTR filename = IP_GetFileName(hInfFile);
1171 LPSTR pEntries, p, pEnd;
1175 FIXME("(%04x, '%s', %04x), semi-stub. Please implement additional operations here !\n", hInfFile, szInstallSection, wFlags);
1176 pEntries = SETUPX_GetSectionEntries(filename, szInstallSection);
1179 ERR("couldn't find entries for section '%s' !\n", szInstallSection);
1180 return ERR_IP_SECT_NOT_FOUND;
1182 for (p=pEntries; *p; p +=strlen(p)+1)
1184 pEnd = strchr(p, '=');
1185 if (!pEnd) continue;
1186 pSub = SETUPX_GetSubStrings(pEnd+1, ','); /* split entries after the '=' */
1187 SETUPX_IsolateSubString(&p, &pEnd);
1188 len = (int)pEnd - (int)p;
1190 if (wFlags & GENINSTALL_DO_FILES)
1192 if (!strncasecmp(p, "CopyFiles", len))
1194 SETUPX_CopyFiles(pSub, hInfFile);
1199 if (!strncasecmp(p, "DelFiles", len))
1201 SETUPX_DelFiles(filename, szInstallSection, pSub);
1206 if (wFlags & GENINSTALL_DO_INI)
1209 if (!strncasecmp(p, "UpdateInis", len))
1211 SETUPX_UpdateInis(filename, szInstallSection, pSub);
1216 if (wFlags & GENINSTALL_DO_REG)
1219 /* probably use SUReg*() functions here */
1220 if (!strncasecmp(p, "AddReg", len))
1222 SETUPX_AddReg(filename, szInstallSection, pSub);
1226 if (!strncasecmp(p, "DelReg", len))
1228 SETUPX_DelReg(filename, szInstallSection, pSub);
1234 SETUPX_FreeSubStrings(pSub);
1236 HeapFree(GetProcessHeap(), 0, pEntries);