4 * Copyright 1998,2000 Andreas Mohr
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * FIXME: Rather non-functional functions for now.
23 * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
24 * http://willemer.de/informatik/windows/inf_info.htm (German)
25 * http://www.microsoft.com/ddk/ddkdocs/win98ddk/devinst_12uw.htm
27 * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
28 * http://www.rdrop.com/~cary/html/inf_faq.html
29 * http://support.microsoft.com/support/kb/articles/q194/6/40.asp
32 * - rs405deu.exe (German Acroread 4.05 setup)
37 * - string handling is... weird ;) (buflen etc.)
39 * - separate that mess (but probably only when it's done completely)
41 * SETUPX consists of several parts with the following acronyms/prefixes:
42 * Di device installer (devinst.c ?)
43 * Gen generic installer (geninst.c ?)
44 * Ip .INF parsing (infparse.c)
45 * LDD logical device descriptor (ldd.c ?)
46 * LDID logical device ID
47 * SU setup (setup.c ?)
48 * Tp text processing (textproc.c ?)
49 * Vcp virtual copy module (vcp.c ?)
52 * The SETUPX DLL is NOT thread-safe. That's why many installers urge you to
53 * "close all open applications".
54 * All in all the design of it seems to be a bit weak.
55 * Not sure whether my implementation of it is better, though ;-)
62 #include "wine/winuser16.h"
64 #include "setupapi_private.h"
66 #include "wine/debug.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
70 /***********************************************************************
71 * SURegOpenKey (SETUPX.47)
73 DWORD WINAPI
SURegOpenKey( HKEY hkey
, LPCSTR lpszSubKey
, LPHKEY retkey
)
75 FIXME("(%x,%s,%p), semi-stub.\n",hkey
,debugstr_a(lpszSubKey
),retkey
);
76 return RegOpenKeyA( hkey
, lpszSubKey
, retkey
);
79 /***********************************************************************
80 * SURegQueryValueEx (SETUPX.50)
82 DWORD WINAPI
SURegQueryValueEx( HKEY hkey
, LPSTR lpszValueName
,
83 LPDWORD lpdwReserved
, LPDWORD lpdwType
,
84 LPBYTE lpbData
, LPDWORD lpcbData
)
86 FIXME("(%x,%s,%p,%p,%p,%ld), semi-stub.\n",hkey
,debugstr_a(lpszValueName
),
87 lpdwReserved
,lpdwType
,lpbData
,lpcbData
?*lpcbData
:0);
88 return RegQueryValueExA( hkey
, lpszValueName
, lpdwReserved
, lpdwType
,
93 * Returns pointer to a string list with the first entry being number
96 * Hmm. Should this be InitSubstrData(), GetFirstSubstr() and GetNextSubstr()
99 static LPSTR
*SETUPX_GetSubStrings(LPSTR start
, char delimiter
)
110 /* find beginning of real substring */
111 while ( (*p
== ' ') || (*p
== '\t') || (*p
== '"') ) p
++;
113 /* find end of real substring */
116 && (*q
!= ' ') && (*q
!= '\t') && (*q
!= '"')
117 && (*q
!= ';') && (*q
!= delimiter
) ) q
++;
120 len
= (int)q
- (int)p
;
122 /* alloc entry for new substring in steps of 32 units and copy over */
124 { /* 1 for count field + current count + 32 */
125 res
= HeapReAlloc(GetProcessHeap(), 0, res
, (1+count
+32)*sizeof(LPSTR
));
127 *(res
+1+count
) = HeapAlloc(GetProcessHeap(), 0, len
+1);
128 strncpy(*(res
+1+count
), p
, len
);
129 (*(res
+1+count
))[len
] = '\0';
132 /* we are still within last substring (before delimiter),
133 * so get out of it */
134 while ((*q
) && (*q
!= ';') && (*q
!= delimiter
)) q
++;
135 if ((!*q
) || (*q
== ';'))
140 /* put number of entries at beginning of list */
141 *(DWORD
*)res
= count
;
145 static void SETUPX_FreeSubStrings(LPSTR
*substr
)
147 DWORD count
= *(DWORD
*)substr
;
148 LPSTR
*pStrings
= substr
+1;
151 for (n
=0; n
< count
; n
++)
152 HeapFree(GetProcessHeap(), 0, *pStrings
++);
154 HeapFree(GetProcessHeap(), 0, substr
);
157 static void SETUPX_IsolateSubString(LPSTR
*begin
, LPSTR
*end
)
164 while ((p
< q
) && ((*p
== ' ') || (*p
== '\t'))) p
++;
165 while ((p
< q
) && (*p
== '"')) p
++;
167 while ((q
-1 >= p
) && ((*(q
-1) == ' ') || (*(q
-1) == '\t'))) q
--;
168 while ((q
-1 >= p
) && (*(q
-1) == '"')) q
--;
175 * Example: HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
176 * FIXME: use SETUPX_GetSubStrings() instead.
177 * Hmm, but on the other hand SETUPX_GetSubStrings() will probably
178 * soon be replaced by InitSubstrData() etc. anyway.
181 static BOOL
SETUPX_LookupRegistryString(LPSTR regstr
, LPSTR buffer
, DWORD buflen
)
183 HANDLE heap
= GetProcessHeap();
190 TRACE("retrieving '%s'\n", regstr
);
194 /* isolate root key, subkey, value, flag, defval */
195 for (n
=0; n
< 5; n
++)
208 SETUPX_IsolateSubString(&p
, &q
);
209 len
= (int)q
- (int)p
;
210 items
[n
] = HeapAlloc(heap
, 0, len
+1);
211 strncpy(items
[n
], p
, len
);
212 items
[n
][len
] = '\0';
215 TRACE("got '%s','%s','%s','%s','%s'\n",
216 items
[0], items
[1], items
[2], items
[3], items
[4]);
219 if (!strcasecmp(items
[0], "HKCR"))
220 hkey
= HKEY_CLASSES_ROOT
;
222 if (!strcasecmp(items
[0], "HKCU"))
223 hkey
= HKEY_CURRENT_USER
;
225 if (!strcasecmp(items
[0], "HKLM"))
226 hkey
= HKEY_LOCAL_MACHINE
;
228 if (!strcasecmp(items
[0], "HKU"))
231 { /* HKR ? -> relative to key passed to GenInstallEx */
232 FIXME("unsupported regkey '%s'\n", items
[0]);
236 if (RegOpenKeyA(hkey
, items
[1], &hsubkey
) != ERROR_SUCCESS
)
239 if (RegQueryValueExA(hsubkey
, items
[2], NULL
, &dwType
, buffer
, &buflen
)
245 if (buffer
) strcpy(buffer
, items
[4]); /* I don't care about buflen */
247 for (n
=0; n
< 5; n
++)
248 HeapFree(heap
, 0, items
[n
]);
250 TRACE("return '%s'\n", buffer
);
254 static LPSTR
SETUPX_GetSections(LPCSTR filename
)
257 DWORD len
= 1024, res
;
260 buf
= HeapReAlloc(GetProcessHeap(), 0, buf
, len
);
261 res
= GetPrivateProfileStringA(NULL
, NULL
, NULL
, buf
, len
, filename
);
263 } while ((!res
) && (len
< 1048576));
266 HeapFree(GetProcessHeap(), 0, buf
);
272 static LPSTR
SETUPX_GetSectionEntries(LPCSTR filename
, LPCSTR section
)
275 DWORD len
= 1024, res
;
278 buf
= HeapReAlloc(GetProcessHeap(), 0, buf
, len
);
279 res
= GetPrivateProfileSectionA(section
, buf
, len
, filename
);
281 } while ((!res
) && (len
< 1048576));
284 HeapFree(GetProcessHeap(), 0, buf
);
291 /***********************************************************************
292 * InstallHinfSection (SETUPX.527)
294 * hwnd = parent window
295 * hinst = instance of SETUPX.DLL
296 * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
297 * Here "DefaultInstall" is the .inf file section to be installed (optional).
298 * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
300 * nCmdShow = nCmdShow of CreateProcess
302 RETERR16 WINAPI
InstallHinfSection16( HWND16 hwnd
, HINSTANCE16 hinst
, LPCSTR lpszCmdLine
, INT16 nCmdShow
)
307 RETERR16 res
= OK
, tmp
;
311 TRACE("(%04x, %04x, %s, %d);\n", hwnd
, hinst
, lpszCmdLine
, nCmdShow
);
313 pSub
= SETUPX_GetSubStrings((LPSTR
)lpszCmdLine
, ' ');
315 count
= *(DWORD
*)pSub
;
316 if (count
< 2) /* invalid number of arguments ? */
318 if (IpOpen16(*(pSub
+count
), &hInf
) != OK
)
320 res
= ERROR_FILE_NOT_FOUND
; /* yes, correct */
323 if (VcpOpen16(NULL
, 0))
325 if (GenInstall16(hInf
, *(pSub
+count
-2), GENINSTALL_DO_ALL
) != OK
)
327 wFlags
= atoi(*(pSub
+count
-1)) & ~128;
330 case HOW_ALWAYS_SILENT_REBOOT
:
331 case HOW_SILENT_REBOOT
:
334 case HOW_ALWAYS_PROMPT_REBOOT
:
335 case HOW_PROMPT_REBOOT
:
336 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
)
340 ERR("invalid flags %d !\n", wFlags
);
346 tmp
= VcpClose16(VCPFL_ALL
, NULL
);
349 tmp
= IpClose16(hInf
);
352 SETUPX_FreeSubStrings(pSub
);
355 /* FIXME: we should have a means of terminating all wine + wineserver */
356 MESSAGE("Program or user told me to restart. Exiting Wine...\n");
366 LPCSTR StdString
; /* fallback string; sub dir of windows directory */
369 static const LDID_DATA LDID_Data
[34] =
371 { /* 0 (LDID_NULL) -- not defined */
375 { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
376 "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
379 { /* 2 (LDID_SETUPTEMP) = setup temp dir */
383 { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
387 { /* 4 (LDID_BACKUP) = backup dir */
391 { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
395 { /* 6 -- not defined */
399 { /* 7 -- not defined */
403 { /* 8 -- not defined */
407 { /* 9 -- not defined */
411 { /* 10 (LDID_WIN) = windows dir */
415 { /* 11 (LDID_SYS) = system dir */
417 NULL
/* call GetSystemDirectory() instead */
419 { /* 12 (LDID_IOS) = IOSubSys dir */
420 NULL
, /* FIXME: registry string ? */
423 { /* 13 (LDID_CMD) = COMMAND dir */
424 NULL
, /* FIXME: registry string ? */
427 { /* 14 (LDID_CPL) = control panel dir */
431 { /* 15 (LDID_PRINT) = windows printer dir */
433 "SYSTEM" /* correct ?? */
435 { /* 16 (LDID_MAIL) = destination mail dir */
439 { /* 17 (LDID_INF) = INF dir */
440 "SetupScratchDir", /* correct ? */
443 { /* 18 (LDID_HELP) = HELP dir */
447 { /* 19 (LDID_WINADMIN) = Admin dir */
451 { /* 20 (LDID_FONTS) = Fonts dir */
455 { /* 21 (LDID_VIEWERS) = Viewers */
459 { /* 22 (LDID_VMM32) = VMM32 dir */
463 { /* 23 (LDID_COLOR) = ICM dir */
467 { /* 24 (LDID_APPS) = root of boot drive ? */
471 { /* 25 (LDID_SHARED) = shared dir */
475 { /* 26 (LDID_WINBOOT) = Windows boot dir */
479 { /* 27 (LDID_MACHINE) = machine specific files */
483 { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
487 { /* 29 -- not defined */
491 { /* 30 (LDID_BOOT) = Root of boot drive */
495 { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
499 { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
503 { /* 33 (LDID_OLD_WIN) = old win dir */
507 /* the rest (34-38) isn't too interesting, so I'll forget about it */
511 * LDD == Logical Device Descriptor
512 * LDID == Logical Device ID
514 * The whole LDD/LDID business might go into a separate file named
516 * At the moment I don't know what the hell these functions are really doing.
517 * That's why I added reporting stubs.
518 * The only thing I do know is that I need them for the LDD/LDID infrastructure.
519 * That's why I implemented them in a way that's suitable for my purpose.
521 static LDD_LIST
*pFirstLDD
= NULL
;
523 static BOOL std_LDDs_done
= FALSE
;
525 void SETUPX_CreateStandardLDDs(void)
531 char buffer
[MAX_PATH
];
533 /* has to be here, otherwise loop */
534 std_LDDs_done
= TRUE
;
536 RegOpenKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey
);
538 for (n
=0; n
< sizeof(LDID_Data
)/sizeof(LDID_DATA
); n
++)
543 if ( (hKey
) && (LDID_Data
[n
].RegValName
)
544 && (RegQueryValueExA(hKey
, LDID_Data
[n
].RegValName
,
545 NULL
, &type
, buffer
, &len
) == ERROR_SUCCESS
)
546 && (type
== REG_SZ
) )
548 TRACE("found value '%s' for LDID %d\n", buffer
, n
);
554 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
555 strcpy(buffer
, "X:\\FIXME");
558 GetSystemDirectoryA(buffer
, MAX_PATH
);
562 case LDID_HOST_WINBOOT
:
565 strcpy(buffer
, "C:\\");
568 if (LDID_Data
[n
].StdString
)
570 DWORD len
= GetWindowsDirectoryA(buffer
, MAX_PATH
);
574 strcpy(p
, LDID_Data
[n
].StdString
);
581 ldd
.pszPath
= buffer
;
582 TRACE("LDID %d -> '%s'\n", ldd
.ldid
, ldd
.pszPath
);
586 if (hKey
) RegCloseKey(hKey
);
589 /***********************************************************************
590 * CtlDelLdd (SETUPX.37)
593 * ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
595 RETERR16
SETUPX_DelLdd(LOGDISKID16 ldid
)
597 LDD_LIST
*pCurr
, *pPrev
= NULL
;
599 TRACE("(%d)\n", ldid
);
602 SETUPX_CreateStandardLDDs();
604 if (ldid
< LDID_ASSIGN_START
)
605 return ERR_VCP_LDDINVALID
;
608 /* search until we find the appropriate LDD or hit the end */
609 while ((pCurr
!= NULL
) && (ldid
> pCurr
->pldd
->ldid
))
614 if ( (pCurr
== NULL
) /* hit end of list */
615 || (ldid
!= pCurr
->pldd
->ldid
) )
616 return ERR_VCP_LDDFIND
; /* correct ? */
618 /* ok, found our victim: eliminate it */
621 pPrev
->next
= pCurr
->next
;
623 if (pCurr
== pFirstLDD
)
625 HeapFree(GetProcessHeap(), 0, pCurr
);
630 /***********************************************************************
631 * CtlDelLdd (SETUPX.37)
633 RETERR16 WINAPI
CtlDelLdd16(LOGDISKID16 ldid
)
635 FIXME("(%d); - please report to a.mohr@mailto.de !!!\n", ldid
);
636 return SETUPX_DelLdd(ldid
);
639 /***********************************************************************
640 * CtlFindLdd (SETUPX.35)
642 * doesn't check pldd ptr validity: crash (W98SE)
645 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
646 * 1 in all other cases ??
649 RETERR16 WINAPI
CtlFindLdd16(LPLOGDISKDESC pldd
)
651 LDD_LIST
*pCurr
, *pPrev
= NULL
;
653 TRACE("(%p)\n", pldd
);
656 SETUPX_CreateStandardLDDs();
658 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
659 return ERR_VCP_LDDINVALID
;
662 /* search until we find the appropriate LDD or hit the end */
663 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
668 if ( (pCurr
== NULL
) /* hit end of list */
669 || (pldd
->ldid
!= pCurr
->pldd
->ldid
) )
670 return ERR_VCP_LDDFIND
; /* correct ? */
672 memcpy(pldd
, pCurr
->pldd
, pldd
->cbSize
);
673 /* hmm, we probably ought to strcpy() the string ptrs here */
675 return 1; /* what is this ?? */
678 /***********************************************************************
679 * CtlSetLdd (SETUPX.33)
684 * ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
687 RETERR16 WINAPI
CtlSetLdd16(LPLOGDISKDESC pldd
)
689 LDD_LIST
*pCurr
, *pPrev
= NULL
;
690 LPLOGDISKDESC pCurrLDD
;
694 TRACE("(%p)\n", pldd
);
697 SETUPX_CreateStandardLDDs();
699 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
700 return ERR_VCP_LDDINVALID
;
702 heap
= GetProcessHeap();
704 /* search until we find the appropriate LDD or hit the end */
705 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
710 if (pCurr
== NULL
) /* hit end of list */
713 pCurr
= HeapAlloc(heap
, 0, sizeof(LDD_LIST
));
714 pCurr
->pldd
= HeapAlloc(heap
, 0, sizeof(LOGDISKDESC_S
));
716 pCurrLDD
= pCurr
->pldd
;
720 pCurrLDD
= pCurr
->pldd
;
721 if (pCurrLDD
->pszPath
) HeapFree(heap
, 0, pCurrLDD
->pszPath
);
722 if (pCurrLDD
->pszVolLabel
) HeapFree(heap
, 0, pCurrLDD
->pszVolLabel
);
723 if (pCurrLDD
->pszDiskName
) HeapFree(heap
, 0, pCurrLDD
->pszDiskName
);
726 memcpy(pCurrLDD
, pldd
, sizeof(LOGDISKDESC_S
));
730 pCurrLDD
->pszPath
= HeapAlloc( heap
, 0, strlen(pldd
->pszPath
)+1 );
731 strcpy( pCurrLDD
->pszPath
, pldd
->pszPath
);
733 if (pldd
->pszVolLabel
)
735 pCurrLDD
->pszVolLabel
= HeapAlloc( heap
, 0, strlen(pldd
->pszVolLabel
)+1 );
736 strcpy( pCurrLDD
->pszVolLabel
, pldd
->pszVolLabel
);
738 if (pldd
->pszDiskName
)
740 pCurrLDD
->pszDiskName
= HeapAlloc( heap
, 0, strlen(pldd
->pszDiskName
)+1 );
741 strcpy( pCurrLDD
->pszDiskName
, pldd
->pszDiskName
);
744 if (is_new
) /* link into list */
748 pCurr
->next
= pPrev
->next
;
759 /***********************************************************************
760 * CtlAddLdd (SETUPX.36)
762 * doesn't check pldd ptr validity: crash (W98SE)
765 static LOGDISKID16 ldid_to_add
= LDID_ASSIGN_START
;
766 RETERR16 WINAPI
CtlAddLdd16(LPLOGDISKDESC pldd
)
768 pldd
->ldid
= ldid_to_add
++;
769 return CtlSetLdd16(pldd
);
772 /***********************************************************************
773 * CtlGetLdd (SETUPX.34)
775 * doesn't check pldd ptr validity: crash (W98SE)
776 * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
779 * ERR_VCP_LDDINVALID if pldd->cbSize != structsize
782 static RETERR16
SETUPX_GetLdd(LPLOGDISKDESC pldd
)
784 LDD_LIST
*pCurr
, *pPrev
= NULL
;
787 SETUPX_CreateStandardLDDs();
789 if (pldd
->cbSize
!= sizeof(LOGDISKDESC_S
))
790 return ERR_VCP_LDDINVALID
;
793 /* search until we find the appropriate LDD or hit the end */
794 while ((pCurr
!= NULL
) && (pldd
->ldid
> pCurr
->pldd
->ldid
))
799 if (pCurr
== NULL
) /* hit end of list */
800 return ERR_VCP_LDDFIND
; /* correct ? */
802 memcpy(pldd
, pCurr
->pldd
, pldd
->cbSize
);
803 /* hmm, we probably ought to strcpy() the string ptrs here */
808 /**********************************************************************/
810 RETERR16 WINAPI
CtlGetLdd16(LPLOGDISKDESC pldd
)
812 FIXME("(%p); - please report to a.mohr@mailto.de !!!\n", pldd
);
813 return SETUPX_GetLdd(pldd
);
816 /***********************************************************************
817 * CtlGetLddPath (SETUPX.38)
819 * Gets the path of an LDD.
820 * No crash if szPath == NULL.
821 * szPath has to be at least MAX_PATH_LEN bytes long.
823 * ERR_VCP_LDDUNINIT if LDD for LDID not found.
825 RETERR16 WINAPI
CtlGetLddPath16(LOGDISKID16 ldid
, LPSTR szPath
)
827 TRACE("(%d, %p);\n", ldid
, szPath
);
833 if (CtlFindLdd16(&ldd
) == ERR_VCP_LDDFIND
)
834 return ERR_VCP_LDDUNINIT
;
836 strcpy(szPath
, ldd
.pszPath
);
837 TRACE("ret '%s' for LDID %d\n", szPath
, ldid
);
842 /***********************************************************************
843 * CtlSetLddPath (SETUPX.508)
845 * Sets the path of an LDD.
846 * Creates LDD for LDID if not existing yet.
848 RETERR16 WINAPI
CtlSetLddPath16(LOGDISKID16 ldid
, LPSTR szPath
)
851 TRACE("(%d, '%s');\n", ldid
, szPath
);
854 ldd
.pszPath
= szPath
;
855 return CtlSetLdd16(&ldd
);
859 * Find the value of a custom LDID in a .inf file
861 * 49300,49301=ProgramFilesDir,5
862 * -- profile section lookup -->
864 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"%24%"
865 * -- GenFormStrWithoutPlaceHolders16 -->
866 * HKLM,"Software\Microsoft\Windows\CurrentVersion","ProgramFilesDir",,"C:\"
867 * -- registry lookup -->
868 * C:\Program Files (or C:\ if not found in registry)
871 * - maybe we ought to add a caching array for speed ? - I don't care :)
872 * - not sure whether the processing is correct - sometimes there are equal
873 * LDIDs for both install and removal sections.
874 * - probably the whole function can be removed as installers add that on their
877 static BOOL
SETUPX_AddCustomLDID(int ldid
, INT16 hInf
)
880 LPSTR sectionbuf
= NULL
, entrybuf
= NULL
, regsectionbuf
= NULL
;
882 LPSTR pSec
, pEnt
, pEqual
, p
, *pSub
= NULL
;
884 char buffer
[MAX_PATH
];
887 sprintf(ldidstr
, "%d", ldid
);
888 filename
= IP_GetFileName(hInf
);
889 if (!(sectionbuf
= SETUPX_GetSections(filename
)))
891 ERR("couldn't get sections !\n");
894 for (pSec
=sectionbuf
; *pSec
; pSec
+= strlen(pSec
)+1)
896 if (!(entrybuf
= SETUPX_GetSectionEntries(filename
, pSec
)))
898 ERR("couldn't get section entries !\n");
901 for (pEnt
=entrybuf
; *pEnt
; pEnt
+= strlen(pEnt
)+1)
903 if (strstr(pEnt
, ldidstr
))
905 pEqual
= strchr(pEnt
, '=');
906 if (!pEqual
) /* crippled entry ?? */
909 /* make sure we found the LDID on left side of the equation */
910 if (pEnt
+strlen(ldidstr
) <= pEqual
)
913 /* but we don't want entries in the strings section */
914 if (!strcasecmp(pSec
, "Strings")) continue;
923 TRACE("found entry '%s'\n", p
);
924 pSub
= SETUPX_GetSubStrings(p
, ',');
925 if (*(DWORD
*)pSub
> 2)
927 ERR("malformed entry '%s' ?\n", p
);
930 TRACE("found section '%s'\n", *(pSub
+1));
931 /* FIXME: what are the optional flags at the end of an entry used for ?? */
933 /* get the location of the registry key from that section */
934 if (!(regsectionbuf
= SETUPX_GetSectionEntries(filename
, *(pSub
+1))))
936 ERR("couldn't get registry section entries !\n");
939 /* sectionbuf is > 1024 bytes anyway, so use it */
940 GenFormStrWithoutPlaceHolders16(sectionbuf
, regsectionbuf
, hInf
);
941 ret
= SETUPX_LookupRegistryString(sectionbuf
, buffer
, MAX_PATH
);
942 TRACE("return '%s'\n", buffer
);
944 ldd
.pszPath
= buffer
;
947 SETUPX_FreeSubStrings(pSub
);
948 if (sectionbuf
) HeapFree(GetProcessHeap(), 0, sectionbuf
);
949 if (entrybuf
) HeapFree(GetProcessHeap(), 0, entrybuf
);
950 if (regsectionbuf
) HeapFree(GetProcessHeap(), 0, regsectionbuf
);
955 * Translate a logical disk identifier (LDID) into its string representation
956 * I'm afraid this can be totally replaced by CtlGetLddPath().
958 static BOOL
SETUPX_IP_TranslateLDID(int ldid
, LPSTR
*p
, HINF16 hInf
)
960 BOOL handled
= FALSE
;
963 ldd
.cbSize
= sizeof(LOGDISKDESC_S
);
965 if (CtlFindLdd16(&ldd
) == ERR_VCP_LDDFIND
)
967 /* hmm, it seems the installers already do the work for us
968 * (by calling CtlSetLddPath) that SETUPX_AddCustomLDID
969 * is supposed to do. Grmbl ;-)
970 * Well, I'll leave it here anyway, but print error... */
971 ERR("hmm, LDID %d not registered yet !?\n", ldid
);
972 handled
= SETUPX_AddCustomLDID(ldid
, hInf
);
981 FIXME("What is LDID %d ??\n", ldid
);
990 /***********************************************************************
991 * GenFormStrWithoutPlaceHolders (SETUPX.103)
993 * ought to be pretty much implemented, I guess...
995 void WINAPI
GenFormStrWithoutPlaceHolders16( LPSTR szDst
, LPCSTR szSrc
, HINF16 hInf
)
997 LPCSTR pSrc
= szSrc
, pSrcEnd
= szSrc
+ strlen(szSrc
);
998 LPSTR pDst
= szDst
, p
, pPHBegin
;
1001 TRACE("(%p, '%s', %04x);\n", szDst
, szSrc
, hInf
);
1002 while (pSrc
< pSrcEnd
)
1004 p
= strchr(pSrc
, '%');
1007 count
= (int)p
- (int)pSrc
;
1008 strncpy(pDst
, pSrc
, count
);
1012 p
= strchr(pPHBegin
, '%');
1015 char placeholder
[80]; /* that really ought to be enough ;) */
1018 count
= (int)p
- (int)pPHBegin
;
1019 strncpy(placeholder
, pPHBegin
, count
);
1020 placeholder
[count
] = '\0';
1021 ldid
= atoi(placeholder
);
1025 done
= SETUPX_IP_TranslateLDID(ldid
, &p
, hInf
);
1028 pDst
+= strlen(pDst
);
1031 { /* hmm, string placeholder. Need to look up
1032 in the [strings] section of the hInf */
1034 char buf
[256]; /* long enough ? */
1036 ret
= GetPrivateProfileStringA("strings", placeholder
, "",
1037 buf
, 256, IP_GetFileName(hInf
));
1041 pDst
+= strlen(buf
);
1045 ERR("placeholder string '%s' not found !\n", placeholder
);
1050 { /* copy raw placeholder string over */
1051 count
= (int)p
- (int)pPHBegin
+ 2;
1052 strncpy(pDst
, pPHBegin
-1, count
);
1061 /* copy the remaining source string over */
1062 strncpy(pDst
, pSrc
, (int)pSrcEnd
- (int)pSrc
+ 1);
1065 TRACE("ret '%s'\n", szDst
);
1069 * Copy all items in a CopyFiles entry over to the destination
1071 * - VNLP_xxx is what is given as flags for a .INF CopyFiles section
1073 static BOOL
SETUPX_CopyFiles(LPSTR
*pSub
, HINF16 hInf
)
1075 BOOL bSingle
= FALSE
;
1077 LPCSTR filename
= IP_GetFileName(hInf
);
1079 char pDstStr
[MAX_PATH
];
1080 LPSTR pSrcDir
, pDstDir
;
1081 LPSTR pFileEntries
, p
;
1085 LPSTR pSrcFile
, pDstFile
;
1088 for (n
=0; n
< *(DWORD
*)pSub
; n
++)
1090 pCopyEntry
= *(pSub
+1+n
);
1091 if (*pCopyEntry
== '@')
1099 /* get source directory for that entry */
1100 INIT_LDD(ldd
, LDID_SRCPATH
);
1101 SETUPX_GetLdd(&ldd
);
1102 pSrcDir
= ldd
.pszPath
;
1104 /* get destination directory for that entry */
1105 if (!(GetPrivateProfileStringA("DestinationDirs", pCopyEntry
, "",
1106 pDstStr
, sizeof(pDstStr
), filename
)))
1108 /* hmm, not found; try the default entry */
1109 if (!(GetPrivateProfileStringA("DestinationDirs", "DefaultDestDir", "", pDstStr
, sizeof(pDstStr
), filename
)))
1111 WARN("DefaultDestDir not found.\n");
1116 /* translate destination dir if given as LDID */
1117 ldid
= atoi(pDstStr
);
1120 if (!(SETUPX_IP_TranslateLDID(ldid
, &pDstDir
, hInf
)))
1126 /* now that we have the destination dir, register file copying */
1130 VcpQueueCopy16(pCopyEntry
, pCopyEntry
, pSrcDir
, pDstDir
, LDID_SRCPATH
, ldid
? ldid
: 0xffff, 0, VFNL_COPY
, 0);
1134 /* entry wasn't a single file, so let's iterate over section */
1135 pFileEntries
= SETUPX_GetSectionEntries(filename
, pCopyEntry
);
1136 if (pFileEntries
== NULL
) continue;
1137 for (p
=pFileEntries
; *p
; p
+=strlen(p
)+1)
1139 pSubFile
= SETUPX_GetSubStrings(p
, ',');
1140 pSrcFile
= *(pSubFile
+1);
1141 pDstFile
= (*(DWORD
*)pSubFile
> 1) ? *(pSubFile
+2) : pSrcFile
;
1142 TRACE("copying file '%s\\%s' to '%s\\%s'\n", pSrcDir
, pSrcFile
, pDstDir
, pDstFile
);
1144 if (*(DWORD
*)pSubFile
> 2)
1146 if ((flag
= atoi(*(pSubFile
+3)))) /* ah, flag */
1149 FIXME("VNLP_xxx flag %d not handled yet.\n", flag
);
1153 FIXME("temp file name '%s' given. Need to register in wininit.ini !\n", *(pSubFile
+3));
1154 /* we probably need to set VIRTNODE.vhstrDstFinalName to
1155 * the final destination name, and the temp name is merely
1156 * the copy destination */
1159 VcpQueueCopy16(pSrcFile
, pDstFile
, pSrcDir
, pDstDir
, LDID_SRCPATH
, ldid
? ldid
: 0xffff, 0, VFNL_COPY
|flag
, 0);
1160 SETUPX_FreeSubStrings(pSubFile
);
1167 /***********************************************************************
1168 * GenInstall (SETUPX.101)
1170 * generic installer function for .INF file sections
1172 * This is not perfect - patch whenever you can !
1174 * wFlags == GENINSTALL_DO_xxx
1176 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
1177 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
1179 RETERR16 WINAPI
GenInstall16(HINF16 hInfFile
, LPCSTR szInstallSection
, WORD wFlags
)
1181 LPCSTR filename
= IP_GetFileName(hInfFile
);
1182 LPSTR pEntries
, p
, pEnd
;
1186 FIXME("(%04x, '%s', %04x), semi-stub. Please implement additional operations here !\n", hInfFile
, szInstallSection
, wFlags
);
1187 pEntries
= SETUPX_GetSectionEntries(filename
, szInstallSection
);
1190 ERR("couldn't find entries for section '%s' !\n", szInstallSection
);
1191 return ERR_IP_SECT_NOT_FOUND
;
1193 for (p
=pEntries
; *p
; p
+=strlen(p
)+1)
1195 pEnd
= strchr(p
, '=');
1196 if (!pEnd
) continue;
1197 pSub
= SETUPX_GetSubStrings(pEnd
+1, ','); /* split entries after the '=' */
1198 SETUPX_IsolateSubString(&p
, &pEnd
);
1199 len
= (int)pEnd
- (int)p
;
1201 if (wFlags
& GENINSTALL_DO_FILES
)
1203 if (!strncasecmp(p
, "CopyFiles", len
))
1205 SETUPX_CopyFiles(pSub
, hInfFile
);
1210 if (!strncasecmp(p
, "DelFiles", len
))
1212 SETUPX_DelFiles(filename
, szInstallSection
, pSub
);
1217 if (wFlags
& GENINSTALL_DO_INI
)
1220 if (!strncasecmp(p
, "UpdateInis", len
))
1222 SETUPX_UpdateInis(filename
, szInstallSection
, pSub
);
1227 if (wFlags
& GENINSTALL_DO_REG
)
1230 /* probably use SUReg*() functions here */
1231 if (!strncasecmp(p
, "AddReg", len
))
1233 SETUPX_AddReg(filename
, szInstallSection
, pSub
);
1237 if (!strncasecmp(p
, "DelReg", len
))
1239 SETUPX_DelReg(filename
, szInstallSection
, pSub
);
1245 SETUPX_FreeSubStrings(pSub
);
1247 HeapFree(GetProcessHeap(), 0, pEntries
);