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 "setupx_private.h"
53 #include "debugtools.h"
55 DEFAULT_DEBUG_CHANNEL(setupx);
57 /***********************************************************************
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 /***********************************************************************
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)
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 (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
315 wFlags = atoi(*(pSub+count-1)) & ~128;
318 case HOW_ALWAYS_SILENT_REBOOT:
319 case HOW_SILENT_REBOOT:
322 case HOW_ALWAYS_PROMPT_REBOOT:
323 case HOW_PROMPT_REBOOT:
324 if ((hMod = GetModuleHandleA("user32.dll")))
326 if ((pMessageBoxA = (MSGBOX_PROC)GetProcAddress( hMod, "MessageBoxA" )))
329 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)
335 ERR("invalid flags %d !\n", wFlags);
342 SETUPX_FreeSubStrings(pSub);
345 /* FIXME: we should have a means of terminating all wine + wineserver */
346 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
356 LPCSTR StdString; /* fallback string; sub dir of windows directory */
359 static const LDID_DATA LDID_Data[34] =
361 { /* 0 (LDID_NULL) -- not defined */
365 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
366 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
369 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
373 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
377 { /* 4 (LDID_BACKUP) = backup dir */
381 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
385 { /* 6 -- not defined */
389 { /* 7 -- not defined */
393 { /* 8 -- not defined */
397 { /* 9 -- not defined */
401 { /* 10 (LDID_WIN) = windows dir */
405 { /* 11 (LDID_SYS) = system dir */
407 NULL /* call GetSystemDirectory() instead */
409 { /* 12 (LDID_IOS) = IOSubSys dir */
410 NULL, /* FIXME: registry string ? */
413 { /* 13 (LDID_CMD) = COMMAND dir */
414 NULL, /* FIXME: registry string ? */
417 { /* 14 (LDID_CPL) = control panel dir */
421 { /* 15 (LDID_PRINT) = windows printer dir */
423 "SYSTEM" /* correct ?? */
425 { /* 16 (LDID_MAIL) = destination mail dir */
429 { /* 17 (LDID_INF) = INF dir */
430 "SetupScratchDir", /* correct ? */
433 { /* 18 (LDID_HELP) = HELP dir */
437 { /* 19 (LDID_WINADMIN) = Admin dir */
441 { /* 20 (LDID_FONTS) = Fonts dir */
445 { /* 21 (LDID_VIEWERS) = Viewers */
449 { /* 22 (LDID_VMM32) = VMM32 dir */
453 { /* 23 (LDID_COLOR) = ICM dir */
457 { /* 24 (LDID_APPS) = root of boot drive ? */
461 { /* 25 (LDID_SHARED) = shared dir */
465 { /* 26 (LDID_WINBOOT) = Windows boot dir */
469 { /* 27 (LDID_MACHINE) = machine specific files */
473 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
477 { /* 29 -- not defined */
481 { /* 30 (LDID_BOOT) = Root of boot drive */
485 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
489 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
493 { /* 33 (LDID_OLD_WIN) = old win dir */
497 /* the rest (34-38) isn't too interesting, so I'll forget about it */
501 * LDD == Logical Device Descriptor
502 * LDID == Logical Device ID
504 * The whole LDD/LDID business might go into a separate file named
505 * ldd.c or logdevice.c.
506 * At the moment I don't know what the hell these functions are really doing.
507 * That's why I added reporting stubs.
508 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
509 * That's why I implemented them in a way that's suitable for my purpose.
511 static LDD_LIST *pFirstLDD = NULL;
513 static BOOL std_LDDs_done = FALSE;
515 void SETUPX_CreateStandardLDDs(void)
521 char buffer[MAX_PATH];
523 /* has to be here, otherwise loop */
524 std_LDDs_done = TRUE;
526 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
528 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
533 if ( (hKey) && (LDID_Data[n].RegValName)
534 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
535 NULL, &type, buffer, &len) == ERROR_SUCCESS)
536 && (type == REG_SZ) )
538 TRACE("found value '%s' for LDID %d\n", buffer, n);
544 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
545 strcpy(buffer, "X:\\FIXME");
548 GetSystemDirectoryA(buffer, MAX_PATH);
552 case LDID_HOST_WINBOOT:
555 strcpy(buffer, "C:\\");
558 if (LDID_Data[n].StdString)
560 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
564 strcpy(p, LDID_Data[n].StdString);
571 ldd.pszPath = buffer;
572 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
576 if (hKey) RegCloseKey(hKey);
579 /***********************************************************************
580 * CtlDelLdd (SETUPX.37)
583 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
585 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
587 LDD_LIST *pCurr, *pPrev = NULL;
589 TRACE("(%d)\n", ldid);
592 SETUPX_CreateStandardLDDs();
594 if (ldid < LDID_ASSIGN_START)
595 return ERR_VCP_LDDINVALID;
598 /* search until we find the appropriate LDD or hit the end */
599 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
604 if ( (pCurr == NULL) /* hit end of list */
605 || (ldid != pCurr->pldd->ldid) )
606 return ERR_VCP_LDDFIND; /* correct ? */
608 /* ok, found our victim: eliminate it */
611 pPrev->next = pCurr->next;
613 if (pCurr == pFirstLDD)
615 HeapFree(GetProcessHeap(), 0, pCurr);
620 /***********************************************************************
621 * CtlDelLdd (SETUPX.37)
623 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
625 FIXME("(%d); - please report to a.mohr@mailto.de !!!\n", ldid);
626 return SETUPX_DelLdd(ldid);
629 /***********************************************************************
630 * CtlFindLdd (SETUPX.35)
632 * doesn't check pldd ptr validity: crash (W98SE)
635 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
636 * 1 in all other cases ??
639 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
641 LDD_LIST *pCurr, *pPrev = NULL;
643 TRACE("(%p)\n", pldd);
646 SETUPX_CreateStandardLDDs();
648 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
649 return ERR_VCP_LDDINVALID;
652 /* search until we find the appropriate LDD or hit the end */
653 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
658 if ( (pCurr == NULL) /* hit end of list */
659 || (pldd->ldid != pCurr->pldd->ldid) )
660 return ERR_VCP_LDDFIND; /* correct ? */
662 memcpy(pldd, pCurr->pldd, pldd->cbSize);
663 /* hmm, we probably ought to strcpy() the string ptrs here */
665 return 1; /* what is this ?? */
668 /***********************************************************************
669 * CtlSetLdd (SETUPX.33)
674 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
677 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
679 LDD_LIST *pCurr, *pPrev = NULL;
680 LPLOGDISKDESC pCurrLDD;
684 TRACE("(%p)\n", pldd);
687 SETUPX_CreateStandardLDDs();
689 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
690 return ERR_VCP_LDDINVALID;
692 heap = GetProcessHeap();
694 /* search until we find the appropriate LDD or hit the end */
695 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
700 if (pCurr == NULL) /* hit end of list */
703 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
704 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
706 pCurrLDD = pCurr->pldd;
710 pCurrLDD = pCurr->pldd;
711 if (pCurrLDD->pszPath) HeapFree(heap, 0, pCurrLDD->pszPath);
712 if (pCurrLDD->pszVolLabel) HeapFree(heap, 0, pCurrLDD->pszVolLabel);
713 if (pCurrLDD->pszDiskName) HeapFree(heap, 0, pCurrLDD->pszDiskName);
716 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
719 pCurrLDD->pszPath = HEAP_strdupA(heap, 0, pldd->pszPath);
720 if (pldd->pszVolLabel)
721 pCurrLDD->pszVolLabel = HEAP_strdupA(heap, 0, pldd->pszVolLabel);
722 if (pldd->pszDiskName)
723 pCurrLDD->pszDiskName = HEAP_strdupA(heap, 0, pldd->pszDiskName);
725 if (is_new) /* link into list */
729 pCurr->next = pPrev->next;
740 /***********************************************************************
741 * CtlAddLdd (SETUPX.36)
743 * doesn't check pldd ptr validity: crash (W98SE)
746 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
747 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
749 pldd->ldid = ldid_to_add++;
750 return CtlSetLdd16(pldd);
753 /***********************************************************************
754 * CtlGetLdd (SETUPX.34)
756 * doesn't check pldd ptr validity: crash (W98SE)
757 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
760 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
763 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
765 LDD_LIST *pCurr, *pPrev = NULL;
768 SETUPX_CreateStandardLDDs();
770 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
771 return ERR_VCP_LDDINVALID;
774 /* search until we find the appropriate LDD or hit the end */
775 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
780 if (pCurr == NULL) /* hit end of list */
781 return ERR_VCP_LDDFIND; /* correct ? */
783 memcpy(pldd, pCurr->pldd, pldd->cbSize);
784 /* hmm, we probably ought to strcpy() the string ptrs here */
789 /**********************************************************************/
791 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
793 FIXME("(%p); - please report to a.mohr@mailto.de !!!\n", pldd);
794 return SETUPX_GetLdd(pldd);
797 /***********************************************************************
798 * CtlGetLddPath (SETUPX.38)
800 * Gets the path of an LDD.
801 * No crash if szPath == NULL.
802 * szPath has to be at least MAX_PATH_LEN bytes long.
804 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
806 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
808 TRACE("(%d, %p);\n", ldid, szPath);
814 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
815 return ERR_VCP_LDDUNINIT;
817 strcpy(szPath, ldd.pszPath);
818 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
823 /***********************************************************************
824 * CtlSetLddPath (SETUPX.508)
826 * Sets the path of an LDD.
827 * Creates LDD for LDID if not existing yet.
829 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
832 TRACE("(%d, '%s');\n", ldid, szPath);
835 ldd.pszPath = szPath;
836 return CtlSetLdd16(&ldd);
840 * Find the value of a custom LDID in a .inf file
842 * 49300,49301=ProgramFilesDir,5
843 * -- profile section lookup -->
845 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"%24%"
846 * -- GenFormStrWithoutPlaceHolders16 -->
847 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
848 * -- registry lookup -->
849 * C:\Program Files (or C:\ if not found in registry)
852 * - maybe we ought to add a caching array for speed ? - I don't care :)
853 * - not sure whether the processing is correct - sometimes there are equal
854 * LDIDs for both install and removal sections.
855 * - probably the whole function can be removed as installers add that on their
858 static BOOL SETUPX_AddCustomLDID(int ldid, INT16 hInf)
861 LPSTR sectionbuf = NULL, entrybuf = NULL, regsectionbuf = NULL;
863 LPSTR pSec, pEnt, pEqual, p, *pSub = NULL;
865 char buffer[MAX_PATH];
868 sprintf(ldidstr, "%d", ldid);
869 filename = IP_GetFileName(hInf);
870 if (!(sectionbuf = SETUPX_GetSections(filename)))
872 ERR("couldn't get sections !\n");
875 for (pSec=sectionbuf; *pSec; pSec += strlen(pSec)+1)
877 if (!(entrybuf = SETUPX_GetSectionEntries(filename, pSec)))
879 ERR("couldn't get section entries !\n");
882 for (pEnt=entrybuf; *pEnt; pEnt += strlen(pEnt)+1)
884 if (strstr(pEnt, ldidstr))
886 pEqual = strchr(pEnt, '=');
887 if (!pEqual) /* crippled entry ?? */
890 /* make sure we found the LDID on left side of the equation */
891 if (pEnt+strlen(ldidstr) <= pEqual)
894 /* but we don't want entries in the strings section */
895 if (!strcasecmp(pSec, "Strings"))
906 TRACE("found entry '%s'\n", p);
907 pSub = SETUPX_GetSubStrings(p, ',');
908 if (*(DWORD *)pSub > 2)
910 ERR("malformed entry '%s' ?\n", p);
913 TRACE("found section '%s'\n", *(pSub+1));
914 /* FIXME: what are the optional flags at the end of an entry used for ?? */
916 /* get the location of the registry key from that section */
917 if (!(regsectionbuf = SETUPX_GetSectionEntries(filename, *(pSub+1))))
919 ERR("couldn't get registry section entries !\n");
922 /* sectionbuf is > 1024 bytes anyway, so use it */
923 GenFormStrWithoutPlaceHolders16(sectionbuf, regsectionbuf, hInf);
924 ret = SETUPX_LookupRegistryString(sectionbuf, buffer, MAX_PATH);
925 TRACE("return '%s'\n", buffer);
927 ldd.pszPath = buffer;
930 SETUPX_FreeSubStrings(pSub);
931 if (sectionbuf) HeapFree(GetProcessHeap(), 0, sectionbuf);
932 if (entrybuf) HeapFree(GetProcessHeap(), 0, entrybuf);
933 if (regsectionbuf) HeapFree(GetProcessHeap(), 0, regsectionbuf);
938 * Translate a logical disk identifier (LDID) into its string representation
939 * I'm afraid this can be totally replaced by CtlGetLddPath().
941 static BOOL SETUPX_IP_TranslateLDID(int ldid, LPSTR *p, HINF16 hInf)
943 BOOL handled = FALSE;
946 ldd.cbSize = sizeof(LOGDISKDESC_S);
948 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
950 /* hmm, it seems the installers already do the work for us
951 * (by calling CtlSetLddPath) that SETUPX_AddCustomLDID
952 * is supposed to do. Grmbl ;-)
953 * Well, I'll leave it here anyway, but print error... */
954 ERR("hmm, LDID %d not registered yet !?\n", ldid);
955 handled = SETUPX_AddCustomLDID(ldid, hInf);
964 FIXME("What is LDID %d ??\n", ldid);
973 /***********************************************************************
974 * GenFormStrWithoutPlaceHolders
976 * ought to be pretty much implemented, I guess...
978 void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
980 LPCSTR pSrc = szSrc, pSrcEnd = szSrc + strlen(szSrc);
981 LPSTR pDst = szDst, p, pPHBegin;
984 TRACE("(%p, '%s', %04x);\n", szDst, szSrc, hInf);
985 while (pSrc < pSrcEnd)
987 p = strchr(pSrc, '%');
990 count = (int)p - (int)pSrc;
991 strncpy(pDst, pSrc, count);
995 p = strchr(pPHBegin, '%');
998 char placeholder[80]; /* that really ought to be enough ;) */
1001 count = (int)p - (int)pPHBegin;
1002 strncpy(placeholder, pPHBegin, count);
1003 placeholder[count] = '\0';
1004 ldid = atoi(placeholder);
1008 done = SETUPX_IP_TranslateLDID(ldid, &p, hInf);
1011 pDst += strlen(pDst);
1014 { /* hmm, string placeholder. Need to look up
1015 in the [strings] section of the hInf */
1017 char buf[256]; /* long enough ? */
1019 ret = GetPrivateProfileStringA("strings", placeholder, "",
1020 buf, 256, IP_GetFileName(hInf));
1024 pDst += strlen(buf);
1028 ERR("placeholder string '%s' not found !\n", placeholder);
1033 { /* copy raw placeholder string over */
1034 count = (int)p - (int)pPHBegin + 2;
1035 strncpy(pDst, pPHBegin-1, count);
1044 /* copy the remaining source string over */
1045 strncpy(pDst, pSrc, (int)pSrcEnd - (int)pSrc + 1);
1048 TRACE("ret '%s'\n", szDst);
1051 /***********************************************************************
1054 * No idea what to do here.
1056 RETERR16 WINAPI VcpOpen16(VIFPROC vifproc, LPARAM lparamMsgRef)
1058 FIXME("(%p, %08lx), stub.\n", vifproc, lparamMsgRef);
1062 /***********************************************************************
1065 * Is fl related to VCPDISKINFO.fl ?
1067 RETERR16 WINAPI VcpClose16(WORD fl, LPCSTR lpszBackupDest)
1069 FIXME("(%04x, '%s'), stub.\n", fl, lpszBackupDest);
1074 * Copy all items in a CopyFiles entry over to the destination
1076 * - VNLP_xxx is what is given as flags for a .INF CopyFiles section
1078 static BOOL SETUPX_CopyFiles(LPSTR *pSub, HINF16 hInf)
1082 LPCSTR filename = IP_GetFileName(hInf);
1084 char pDestStr[MAX_PATH];
1085 LPSTR pSrcDir, pDstDir;
1086 LPSTR pFileEntries, p;
1090 LPSTR pSrcFile, pDstFile;
1092 for (n=0; n < *(DWORD *)pSub; n++)
1094 pCopyEntry = *(pSub+1+n);
1095 if (*pCopyEntry == '@')
1097 ERR("single file not handled yet !\n");
1101 /* get source directory for that entry */
1102 INIT_LDD(ldd, LDID_SRCPATH);
1103 SETUPX_GetLdd(&ldd);
1104 pSrcDir = ldd.pszPath;
1106 /* get destination directory for that entry */
1107 if (!(GetPrivateProfileStringA("DestinationDirs", pCopyEntry, "",
1108 pDestStr, sizeof(pDestStr), filename)))
1111 /* translate destination dir if given as LDID */
1112 ldid = atoi(pDestStr);
1115 if (!(SETUPX_IP_TranslateLDID(ldid, &pDstDir, hInf)))
1121 /* now that we have the destination dir, iterate over files to copy */
1122 pFileEntries = SETUPX_GetSectionEntries(filename, pCopyEntry);
1123 for (p=pFileEntries; *p; p +=strlen(p)+1)
1125 pSubFile = SETUPX_GetSubStrings(p, ',');
1126 pSrcFile = *(pSubFile+1);
1127 pDstFile = (*(DWORD *)pSubFile > 1) ? *(pSubFile+2) : pSrcFile;
1128 TRACE("copying file '%s\\%s' to '%s\\%s'\n", pSrcDir, pSrcFile, pDstDir, pDstFile);
1129 if (*(DWORD *)pSubFile > 2)
1132 if ((flag = atoi(*(pSubFile+3)))) /* ah, flag */
1135 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)); /* strong guess that this is VcpQueueCopy() */
1140 SETUPX_FreeSubStrings(pSubFile);
1141 /* we don't copy ANYTHING yet ! (I'm too lazy and want to verify
1142 * this first before destroying whole partitions ;-) */
1149 /***********************************************************************
1152 * general install function for .INF file sections
1154 * This is not perfect - patch whenever you can !
1156 * wFlags == GENINSTALL_DO_xxx
1158 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
1159 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
1161 RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
1163 LPCSTR filename = IP_GetFileName(hInfFile);
1164 LPSTR pEntries, p, pEnd;
1168 FIXME("(%04x, '%s', %04x), semi-stub. Please implement additional operations here !\n", hInfFile, szInstallSection, wFlags);
1169 pEntries = SETUPX_GetSectionEntries(filename, szInstallSection);
1172 ERR("couldn't find entries for section '%s' !\n", szInstallSection);
1173 return ERR_IP_SECT_NOT_FOUND;
1175 for (p=pEntries; *p; p +=strlen(p)+1)
1177 pEnd = strchr(p, '=');
1178 if (!pEnd) continue;
1179 pSub = SETUPX_GetSubStrings(pEnd+1, ','); /* split entries after the '=' */
1180 SETUPX_IsolateSubString(&p, &pEnd);
1181 len = (int)pEnd - (int)p;
1183 if (wFlags & GENINSTALL_DO_FILES)
1185 if (!strncasecmp(p, "CopyFiles", len))
1187 SETUPX_CopyFiles(pSub, hInfFile);
1192 if (!strncasecmp(p, "DelFiles", len))
1194 SETUPX_DelFiles(filename, szInstallSection, pSub);
1199 if (wFlags & GENINSTALL_DO_INI)
1202 if (!strncasecmp(p, "UpdateInis", len))
1204 SETUPX_UpdateInis(filename, szInstallSection, pSub);
1209 if (wFlags & GENINSTALL_DO_REG)
1212 /* probably use SUReg*() functions here */
1213 if (!strncasecmp(p, "AddReg", len))
1215 SETUPX_AddReg(filename, szInstallSection, pSub);
1219 if (!strncasecmp(p, "DelReg", len))
1221 SETUPX_DelReg(filename, szInstallSection, pSub);
1227 SETUPX_FreeSubStrings(pSub);
1229 HeapFree(GetProcessHeap(), 0, pEntries);