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 ;-)
47 #include "wine/winuser16.h"
49 #include "setupx_private.h"
52 #include "debugtools.h"
54 DEFAULT_DEBUG_CHANNEL(setupx);
56 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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)
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 (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
314 wFlags = atoi(*(pSub+count-1)) & ~128;
317 case HOW_ALWAYS_SILENT_REBOOT:
318 case HOW_SILENT_REBOOT:
321 case HOW_ALWAYS_PROMPT_REBOOT:
322 case HOW_PROMPT_REBOOT:
323 if ((hMod = GetModuleHandleA("user32.dll")))
325 if ((pMessageBoxA = (MSGBOX_PROC)GetProcAddress( hMod, "MessageBoxA" )))
328 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)
334 ERR("invalid flags %d !\n", wFlags);
341 SETUPX_FreeSubStrings(pSub);
344 /* FIXME: we should have a means of terminating all wine + wineserver */
345 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
355 LPCSTR StdString; /* fallback string; sub dir of windows directory */
358 static const LDID_DATA LDID_Data[34] =
360 { /* 0 (LDID_NULL) -- not defined */
364 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
365 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
368 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
372 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
376 { /* 4 (LDID_BACKUP) = backup dir */
380 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
384 { /* 6 -- not defined */
388 { /* 7 -- not defined */
392 { /* 8 -- not defined */
396 { /* 9 -- not defined */
400 { /* 10 (LDID_WIN) = windows dir */
404 { /* 11 (LDID_SYS) = system dir */
406 NULL /* call GetSystemDirectory() instead */
408 { /* 12 (LDID_IOS) = IOSubSys dir */
409 NULL, /* FIXME: registry string ? */
412 { /* 13 (LDID_CMD) = COMMAND dir */
413 NULL, /* FIXME: registry string ? */
416 { /* 14 (LDID_CPL) = control panel dir */
420 { /* 15 (LDID_PRINT) = windows printer dir */
422 "SYSTEM" /* correct ?? */
424 { /* 16 (LDID_MAIL) = destination mail dir */
428 { /* 17 (LDID_INF) = INF dir */
429 "SetupScratchDir", /* correct ? */
432 { /* 18 (LDID_HELP) = HELP dir */
436 { /* 19 (LDID_WINADMIN) = Admin dir */
440 { /* 20 (LDID_FONTS) = Fonts dir */
444 { /* 21 (LDID_VIEWERS) = Viewers */
448 { /* 22 (LDID_VMM32) = VMM32 dir */
452 { /* 23 (LDID_COLOR) = ICM dir */
456 { /* 24 (LDID_APPS) = root of boot drive ? */
460 { /* 25 (LDID_SHARED) = shared dir */
464 { /* 26 (LDID_WINBOOT) = Windows boot dir */
468 { /* 27 (LDID_MACHINE) = machine specific files */
472 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
476 { /* 29 -- not defined */
480 { /* 30 (LDID_BOOT) = Root of boot drive */
484 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
488 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
492 { /* 33 (LDID_OLD_WIN) = old win dir */
496 /* the rest (34-38) isn't too interesting, so I'll forget about it */
500 * LDD == Logical Device Descriptor
501 * LDID == Logical Device ID
503 * The whole LDD/LDID business might go into a separate file named
504 * ldd.c or logdevice.c.
505 * At the moment I don't know what the hell these functions are really doing.
506 * That's why I added reporting stubs.
507 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
508 * That's why I implemented them in a way that's suitable for my purpose.
510 static LDD_LIST *pFirstLDD = NULL;
512 static BOOL std_LDDs_done = FALSE;
514 void SETUPX_CreateStandardLDDs(void)
520 char buffer[MAX_PATH];
522 /* has to be here, otherwise loop */
523 std_LDDs_done = TRUE;
525 RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
527 for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
532 if ( (hKey) && (LDID_Data[n].RegValName)
533 && (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
534 NULL, &type, buffer, &len) == ERROR_SUCCESS)
535 && (type == REG_SZ) )
537 TRACE("found value '%s' for LDID %d\n", buffer, n);
543 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
544 strcpy(buffer, "X:\\FIXME");
547 GetSystemDirectoryA(buffer, MAX_PATH);
551 case LDID_HOST_WINBOOT:
554 strcpy(buffer, "C:\\");
557 if (LDID_Data[n].StdString)
559 DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
563 strcpy(p, LDID_Data[n].StdString);
570 ldd.pszPath = buffer;
571 TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
575 if (hKey) RegCloseKey(hKey);
578 /***********************************************************************
579 * CtlDelLdd (SETUPX.37)
582 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
584 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
586 LDD_LIST *pCurr, *pPrev = NULL;
588 TRACE("(%d)\n", ldid);
591 SETUPX_CreateStandardLDDs();
593 if (ldid < LDID_ASSIGN_START)
594 return ERR_VCP_LDDINVALID;
597 /* search until we find the appropriate LDD or hit the end */
598 while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
603 if ( (pCurr == NULL) /* hit end of list */
604 || (ldid != pCurr->pldd->ldid) )
605 return ERR_VCP_LDDFIND; /* correct ? */
607 /* ok, found our victim: eliminate it */
610 pPrev->next = pCurr->next;
612 if (pCurr == pFirstLDD)
614 HeapFree(GetProcessHeap(), 0, pCurr);
619 /***********************************************************************
620 * CtlDelLdd (SETUPX.37)
622 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
624 FIXME("(%d); - please report to a.mohr@mailto.de !!!\n", ldid);
625 return SETUPX_DelLdd(ldid);
628 /***********************************************************************
629 * CtlFindLdd (SETUPX.35)
631 * doesn't check pldd ptr validity: crash (W98SE)
634 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
635 * 1 in all other cases ??
638 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
640 LDD_LIST *pCurr, *pPrev = NULL;
642 TRACE("(%p)\n", pldd);
645 SETUPX_CreateStandardLDDs();
647 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
648 return ERR_VCP_LDDINVALID;
651 /* search until we find the appropriate LDD or hit the end */
652 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
657 if ( (pCurr == NULL) /* hit end of list */
658 || (pldd->ldid != pCurr->pldd->ldid) )
659 return ERR_VCP_LDDFIND; /* correct ? */
661 memcpy(pldd, pCurr->pldd, pldd->cbSize);
662 /* hmm, we probably ought to strcpy() the string ptrs here */
664 return 1; /* what is this ?? */
667 /***********************************************************************
668 * CtlSetLdd (SETUPX.33)
673 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
676 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
678 LDD_LIST *pCurr, *pPrev = NULL;
679 LPLOGDISKDESC pCurrLDD;
683 TRACE("(%p)\n", pldd);
686 SETUPX_CreateStandardLDDs();
688 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
689 return ERR_VCP_LDDINVALID;
691 heap = GetProcessHeap();
693 /* search until we find the appropriate LDD or hit the end */
694 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
699 if (pCurr == NULL) /* hit end of list */
702 pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
703 pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
705 pCurrLDD = pCurr->pldd;
709 pCurrLDD = pCurr->pldd;
710 if (pCurrLDD->pszPath) HeapFree(heap, 0, pCurrLDD->pszPath);
711 if (pCurrLDD->pszVolLabel) HeapFree(heap, 0, pCurrLDD->pszVolLabel);
712 if (pCurrLDD->pszDiskName) HeapFree(heap, 0, pCurrLDD->pszDiskName);
715 memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
718 pCurrLDD->pszPath = HEAP_strdupA(heap, 0, pldd->pszPath);
719 if (pldd->pszVolLabel)
720 pCurrLDD->pszVolLabel = HEAP_strdupA(heap, 0, pldd->pszVolLabel);
721 if (pldd->pszDiskName)
722 pCurrLDD->pszDiskName = HEAP_strdupA(heap, 0, pldd->pszDiskName);
724 if (is_new) /* link into list */
728 pCurr->next = pPrev->next;
739 /***********************************************************************
740 * CtlAddLdd (SETUPX.36)
742 * doesn't check pldd ptr validity: crash (W98SE)
745 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
746 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
748 pldd->ldid = ldid_to_add++;
749 return CtlSetLdd16(pldd);
752 /***********************************************************************
753 * CtlGetLdd (SETUPX.34)
755 * doesn't check pldd ptr validity: crash (W98SE)
756 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
759 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
762 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
764 LDD_LIST *pCurr, *pPrev = NULL;
767 SETUPX_CreateStandardLDDs();
769 if (pldd->cbSize != sizeof(LOGDISKDESC_S))
770 return ERR_VCP_LDDINVALID;
773 /* search until we find the appropriate LDD or hit the end */
774 while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
779 if (pCurr == NULL) /* hit end of list */
780 return ERR_VCP_LDDFIND; /* correct ? */
782 memcpy(pldd, pCurr->pldd, pldd->cbSize);
783 /* hmm, we probably ought to strcpy() the string ptrs here */
788 /**********************************************************************/
790 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
792 FIXME("(%p); - please report to a.mohr@mailto.de !!!\n", pldd);
793 return SETUPX_GetLdd(pldd);
796 /***********************************************************************
797 * CtlGetLddPath (SETUPX.38)
799 * Gets the path of an LDD.
800 * No crash if szPath == NULL.
801 * szPath has to be at least MAX_PATH_LEN bytes long.
803 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
805 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
807 TRACE("(%d, %p);\n", ldid, szPath);
813 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
814 return ERR_VCP_LDDUNINIT;
816 strcpy(szPath, ldd.pszPath);
817 TRACE("ret '%s' for LDID %d\n", szPath, ldid);
822 /***********************************************************************
823 * CtlSetLddPath (SETUPX.508)
825 * Sets the path of an LDD.
826 * Creates LDD for LDID if not existing yet.
828 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
831 TRACE("(%d, '%s');\n", ldid, szPath);
834 ldd.pszPath = szPath;
835 return CtlSetLdd16(&ldd);
839 * Find the value of a custom LDID in a .inf file
841 * 49300,49301=ProgramFilesDir,5
842 * -- profile section lookup -->
844 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"%24%"
845 * -- GenFormStrWithoutPlaceHolders16 -->
846 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
847 * -- registry lookup -->
848 * C:\Program Files (or C:\ if not found in registry)
851 * - maybe we ought to add a caching array for speed ? - I don't care :)
852 * - not sure whether the processing is correct - sometimes there are equal
853 * LDIDs for both install and removal sections.
854 * - probably the whole function can be removed as installers add that on their
857 static BOOL SETUPX_AddCustomLDID(int ldid, INT16 hInf)
860 LPSTR sectionbuf = NULL, entrybuf = NULL, regsectionbuf = NULL;
862 LPSTR pSec, pEnt, pEqual, p, *pSub = NULL;
864 char buffer[MAX_PATH];
867 sprintf(ldidstr, "%d", ldid);
868 filename = IP_GetFileName(hInf);
869 if (!(sectionbuf = SETUPX_GetSections(filename)))
871 ERR("couldn't get sections !\n");
874 for (pSec=sectionbuf; *pSec; pSec += strlen(pSec)+1)
876 if (!(entrybuf = SETUPX_GetSectionEntries(filename, pSec)))
878 ERR("couldn't get section entries !\n");
881 for (pEnt=entrybuf; *pEnt; pEnt += strlen(pEnt)+1)
883 if (strstr(pEnt, ldidstr))
885 pEqual = strchr(pEnt, '=');
886 if (!pEqual) /* crippled entry ?? */
889 /* make sure we found the LDID on left side of the equation */
890 if (pEnt+strlen(ldidstr) <= pEqual)
893 /* but we don't want entries in the strings section */
894 if (!strcasecmp(pSec, "Strings"))
905 TRACE("found entry '%s'\n", p);
906 pSub = SETUPX_GetSubStrings(p, ',');
907 if (*(DWORD *)pSub > 2)
909 ERR("malformed entry '%s' ?\n", p);
912 TRACE("found section '%s'\n", *(pSub+1));
913 /* FIXME: what are the optional flags at the end of an entry used for ?? */
915 /* get the location of the registry key from that section */
916 if (!(regsectionbuf = SETUPX_GetSectionEntries(filename, *(pSub+1))))
918 ERR("couldn't get registry section entries !\n");
921 /* sectionbuf is > 1024 bytes anyway, so use it */
922 GenFormStrWithoutPlaceHolders16(sectionbuf, regsectionbuf, hInf);
923 ret = SETUPX_LookupRegistryString(sectionbuf, buffer, MAX_PATH);
924 TRACE("return '%s'\n", buffer);
926 ldd.pszPath = buffer;
929 SETUPX_FreeSubStrings(pSub);
930 if (sectionbuf) HeapFree(GetProcessHeap(), 0, sectionbuf);
931 if (entrybuf) HeapFree(GetProcessHeap(), 0, entrybuf);
932 if (regsectionbuf) HeapFree(GetProcessHeap(), 0, regsectionbuf);
937 * Translate a logical disk identifier (LDID) into its string representation
938 * I'm afraid this can be totally replaced by CtlGetLddPath().
940 static BOOL SETUPX_IP_TranslateLDID(int ldid, LPSTR *p, HINF16 hInf)
942 BOOL handled = FALSE;
945 ldd.cbSize = sizeof(LOGDISKDESC_S);
947 if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
949 /* hmm, it seems the installers already do the work for us
950 * (by calling CtlSetLddPath) that SETUPX_AddCustomLDID
951 * is supposed to do. Grmbl ;-)
952 * Well, I'll leave it here anyway, but print error... */
953 ERR("hmm, LDID %d not registered yet !?\n", ldid);
954 handled = SETUPX_AddCustomLDID(ldid, hInf);
963 FIXME("What is LDID %d ??\n", ldid);
972 /***********************************************************************
973 * GenFormStrWithoutPlaceHolders
975 * ought to be pretty much implemented, I guess...
977 void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
979 LPCSTR pSrc = szSrc, pSrcEnd = szSrc + strlen(szSrc);
980 LPSTR pDst = szDst, p, pPHBegin;
983 TRACE("(%p, '%s', %04x);\n", szDst, szSrc, hInf);
984 while (pSrc < pSrcEnd)
986 p = strchr(pSrc, '%');
989 count = (int)p - (int)pSrc;
990 strncpy(pDst, pSrc, count);
994 p = strchr(pPHBegin, '%');
997 char placeholder[80]; /* that really ought to be enough ;) */
1000 count = (int)p - (int)pPHBegin;
1001 strncpy(placeholder, pPHBegin, count);
1002 placeholder[count] = '\0';
1003 ldid = atoi(placeholder);
1007 done = SETUPX_IP_TranslateLDID(ldid, &p, hInf);
1010 pDst += strlen(pDst);
1013 { /* hmm, string placeholder. Need to look up
1014 in the [strings] section of the hInf */
1016 char buf[256]; /* long enough ? */
1018 ret = GetPrivateProfileStringA("strings", placeholder, "",
1019 buf, 256, IP_GetFileName(hInf));
1023 pDst += strlen(buf);
1027 ERR("placeholder string '%s' not found !\n", placeholder);
1032 { /* copy raw placeholder string over */
1033 count = (int)p - (int)pPHBegin + 2;
1034 strncpy(pDst, pPHBegin-1, count);
1043 /* copy the remaining source string over */
1044 strncpy(pDst, pSrc, (int)pSrcEnd - (int)pSrc + 1);
1047 TRACE("ret '%s'\n", szDst);
1050 /***********************************************************************
1053 * No idea what to do here.
1055 RETERR16 WINAPI VcpOpen16(VIFPROC vifproc, LPARAM lparamMsgRef)
1057 FIXME("(%p, %08lx), stub.\n", vifproc, lparamMsgRef);
1061 /***********************************************************************
1064 * Is fl related to VCPDISKINFO.fl ?
1066 RETERR16 WINAPI VcpClose16(WORD fl, LPCSTR lpszBackupDest)
1068 FIXME("(%04x, '%s'), stub.\n", fl, lpszBackupDest);
1073 * Copy all items in a CopyFiles entry over to the destination
1075 * - VNLP_xxx is what is given as flags for a .INF CopyFiles section
1077 static BOOL SETUPX_CopyFiles(LPSTR *pSub, HINF16 hInf)
1081 LPCSTR filename = IP_GetFileName(hInf);
1083 char pDestStr[MAX_PATH];
1084 LPSTR pSrcDir, pDstDir;
1085 LPSTR pFileEntries, p;
1089 LPSTR pSrcFile, pDstFile;
1091 for (n=0; n < *(DWORD *)pSub; n++)
1093 pCopyEntry = *(pSub+1+n);
1094 if (*pCopyEntry == '@')
1096 ERR("single file not handled yet !\n");
1100 /* get source directory for that entry */
1101 INIT_LDD(ldd, LDID_SRCPATH);
1102 SETUPX_GetLdd(&ldd);
1103 pSrcDir = ldd.pszPath;
1105 /* get destination directory for that entry */
1106 if (!(GetPrivateProfileStringA("DestinationDirs", pCopyEntry, "",
1107 pDestStr, sizeof(pDestStr), filename)))
1110 /* translate destination dir if given as LDID */
1111 ldid = atoi(pDestStr);
1114 if (!(SETUPX_IP_TranslateLDID(ldid, &pDstDir, hInf)))
1120 /* now that we have the destination dir, iterate over files to copy */
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);
1128 if (*(DWORD *)pSubFile > 2)
1131 if ((flag = atoi(*(pSubFile+3)))) /* ah, flag */
1134 FIXME("VNLP_xxx flag %d not handled yet.\n", flag);
1137 FIXME("temp file name '%s' given. Need to register in wininit.ini !\n", *(pSubFile+3)); /* strong guess that this is VcpQueueCopy() */
1139 SETUPX_FreeSubStrings(pSubFile);
1140 /* we don't copy ANYTHING yet ! (I'm too lazy and want to verify
1141 * this first before destroying whole partitions ;-) */
1148 /***********************************************************************
1151 * general install function for .INF file sections
1153 * This is not perfect - patch whenever you can !
1155 * wFlags == GENINSTALL_DO_xxx
1157 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
1158 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
1160 RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
1162 LPCSTR filename = IP_GetFileName(hInfFile);
1163 LPSTR pEntries, p, pEnd;
1167 FIXME("(%04x, '%s', %04x), semi-stub. Please implement additional operations here !\n", hInfFile, szInstallSection, wFlags);
1168 pEntries = SETUPX_GetSectionEntries(filename, szInstallSection);
1171 ERR("couldn't find entries for section '%s' !\n", szInstallSection);
1172 return ERR_IP_SECT_NOT_FOUND;
1174 for (p=pEntries; *p; p +=strlen(p)+1)
1176 pEnd = strchr(p, '=');
1177 if (!pEnd) continue;
1178 pSub = SETUPX_GetSubStrings(pEnd+1, ','); /* split entries after the '=' */
1179 SETUPX_IsolateSubString(&p, &pEnd);
1180 len = (int)pEnd - (int)p;
1182 if (wFlags & GENINSTALL_DO_FILES)
1184 if (!strncasecmp(p, "CopyFiles", len))
1186 SETUPX_CopyFiles(pSub, hInfFile);
1191 if (!strncasecmp(p, "DelFiles", len))
1193 SETUPX_DelFiles(filename, szInstallSection, pSub);
1198 if (wFlags & GENINSTALL_DO_INI)
1201 if (!strncasecmp(p, "UpdateInis", len))
1203 SETUPX_UpdateInis(filename, szInstallSection, pSub);
1208 if (wFlags & GENINSTALL_DO_REG)
1211 /* probably use SUReg*() functions here */
1212 if (!strncasecmp(p, "AddReg", len))
1214 SETUPX_AddReg(filename, szInstallSection, pSub);
1218 if (!strncasecmp(p, "DelReg", len))
1220 SETUPX_DelReg(filename, szInstallSection, pSub);
1226 SETUPX_FreeSubStrings(pSub);
1228 HeapFree(GetProcessHeap(), 0, pEntries);