Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

459 lines
12 KiB

  1. /*
  2. * w95inf16.c
  3. *
  4. * Copyright (c) 1995 Microsoft Corporation
  5. *
  6. * 16bit portion of the INFINST program. This DLL contains all the
  7. * stuff to drive GenInstall (a 16 bit DLL)
  8. *
  9. */
  10. #include "w95inf16.h"
  11. #include <regstr.h>
  12. #include <cpldebug.h>
  13. #include <memory.h>
  14. #include <string.h>
  15. //#include "..\core\infinst.h"
  16. #define SHORTSTRING 256
  17. /*
  18. * GLOBALS
  19. */
  20. HINSTANCE hInstance;
  21. CHAR szDll16[] = "W95INF16.DLL";
  22. CHAR szDll32[] = "W95INF32.DLL";
  23. static char g_szRunOnceExe[] = {"runonce"};
  24. /*
  25. * S T R I N G S
  26. */
  27. char *szSectVersion = "version";
  28. char *szKeySignature = "signature";
  29. char *szValSignature = "$CHICAGO$";
  30. /*
  31. * Declarations
  32. */
  33. BOOL FAR PASCAL w95thk_ThunkConnect16(LPSTR pszDLL16, LPSTR pszDll32, WORD hInst, DWORD dwReason);
  34. VOID WINAPI GetSETUPXErrorText16(DWORD,LPSTR, DWORD);
  35. WORD WINAPI CtlSetLddPath16(UINT, LPSTR);
  36. //BUGBUG: 32-bit HWND
  37. //WORD WINAPI GenInstall16(LPSTR, LPSTR, LPSTR, DWORD, DWORD);
  38. WORD WINAPI GenInstall16(LPSTR, LPSTR, LPSTR, DWORD);
  39. BOOL WINAPI GenFormStrWithoutPlaceHolders16(LPSTR, LPSTR, LPSTR);
  40. /*
  41. * Library Initialization
  42. *
  43. * Call by LibInit
  44. */
  45. BOOL FAR PASCAL LibMain(HINSTANCE hInst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
  46. {
  47. // Keep Copy of Instance
  48. hInstance = hInst;
  49. DEBUGMSG("W95INF16.DLL - LibMain()");
  50. return( TRUE );
  51. }
  52. /*
  53. * Thunk Entry Point
  54. */
  55. BOOL FAR PASCAL DllEntryPoint(DWORD dwReason, WORD hInst, WORD wDS, WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
  56. {
  57. DEBUGMSG("W95INF16.DLL - DllEntryPoint()");
  58. if (! (w95thk_ThunkConnect16(szDll16, szDll32, hInst, dwReason))) {
  59. DEBUGMSG("W95INF16.DLL - w95thk_ThunkConnect16() Failed");
  60. return( FALSE );
  61. }
  62. return( TRUE );
  63. }
  64. /*
  65. * O P E N _ V A L I D A T E _ I N F
  66. *
  67. * Routine: OpenValidateInf
  68. *
  69. * Purpose: Open INF and validate internals
  70. *
  71. * Notes: Stolen from setupx
  72. *
  73. *
  74. */
  75. RETERR OpenValidateInf(LPCSTR lpszInfFile, HINF FAR * phInf )
  76. {
  77. RETERR err;
  78. HINF hInfFile;
  79. char szTmpBuf[SHORTSTRING];
  80. ASSERT(lpszInfFile);
  81. ASSERT(phInf);
  82. DEBUGMSG("OpenValidateInf([%s])", lpszInfFile );
  83. /*
  84. * Open the INF
  85. */
  86. err = IpOpen( lpszInfFile, &hInfFile );
  87. if (err != OK) {
  88. DEBUGMSG("IpOpen(%s) returned %u",(LPSTR) lpszInfFile,err);
  89. return err;
  90. }
  91. /*
  92. * Get INF signature
  93. */
  94. err = IpGetProfileString( hInfFile, szSectVersion, szKeySignature, szTmpBuf, sizeof(szTmpBuf));
  95. if (err != OK) {
  96. DEBUGMSG("IpGetProfileString returned %u",err);
  97. return err;
  98. }
  99. /*
  100. * Check INF signature
  101. */
  102. if ( lstrcmpi(szTmpBuf,szValSignature) != 0 ) {
  103. DEBUGMSG("signature error in %s",(LPSTR) lpszInfFile);
  104. IpClose(hInfFile);
  105. return ERR_IP_INVALID_INFFILE;
  106. }
  107. /*
  108. * Set Out Parameter phInf
  109. */
  110. *phInf = hInfFile;
  111. DEBUGMSG("OpenValidateInf([%s]) Complete", lpszInfFile );
  112. return OK;
  113. }
  114. /*
  115. * I N S T A L L F I L E S F R O M I N F
  116. *
  117. * Routine: InstallFilesFromINF()
  118. *
  119. * Purpose: Call GenInstall to GenInstall a section of an INF
  120. * using specified flags
  121. *
  122. */
  123. RETERR InstallFilesFromINF(HWND hwndParent, LPCSTR lpszINF, LPCSTR lpszSection, WORD wFlags)
  124. {
  125. RETERR err = OK;
  126. HINF hInf;
  127. ASSERT(lpszINF);
  128. ASSERT(lpszSection);
  129. DEBUGMSG("InstallFilesFromINF([%s], [%s], [%x])", lpszINF, lpszSection, wFlags );
  130. /*
  131. * Open INF
  132. */
  133. err = OpenValidateInf(lpszINF, &hInf);
  134. if (err != OK) {
  135. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszINF, err);
  136. return err;
  137. }
  138. ASSERT(hInf);
  139. /*
  140. * GenInstall Go Do your thing
  141. */
  142. err = GenInstall(hInf,lpszSection, wFlags );
  143. /*
  144. * Close INF
  145. */
  146. IpClose(hInf);
  147. return err;
  148. }
  149. //***************************************************************************
  150. //* *
  151. //* NAME: AddPath *
  152. //* *
  153. //* SYNOPSIS: *
  154. //* *
  155. //* REQUIRES: *
  156. //* *
  157. //* RETURNS: *
  158. //* *
  159. //***************************************************************************
  160. VOID AddPath(LPSTR szPath, LPCSTR szName )
  161. {
  162. LPSTR szTmp;
  163. // Find end of the string
  164. szTmp = szPath + lstrlen(szPath);
  165. // If no trailing backslash then add one
  166. if ( szTmp > szPath && *(AnsiPrev( szPath, szTmp )) != '\\' )
  167. *(szTmp++) = '\\';
  168. // Add new name to existing path string
  169. while ( *szName == ' ' ) szName++;
  170. lstrcpy( szTmp, szName );
  171. }
  172. //BUGBUG: Ideally, we would like to use the HWND in here, but in 32-bit land,
  173. // HWND is 32-bits and in 16-bit land, HWND is 16-bits, so we have a
  174. // problem.
  175. //WORD WINAPI GenInstall16(LPSTR lpszInf, LPSTR lpszSection, LPSTR lpszDirectory, DWORD dwQuietMode, DWORD hWnd )
  176. WORD WINAPI GenInstall16(LPSTR lpszInf, LPSTR lpszSection, LPSTR lpszDirectory, DWORD dwQuietMode )
  177. {
  178. VCPUIINFO VcpUiInfo;
  179. RETERR err;
  180. BYTE fNeedBoot = 1;
  181. char szPrevSourcePath[MAX_PATH+1] = "";
  182. BOOL fNeedToRestorePrevSourcePath = FALSE;
  183. char szTempPath[MAX_PATH];
  184. int i = 0;
  185. static const char c_aszDlls[3][20] = { "advpack.dll",
  186. "w95inf16.dll",
  187. "w95inf32.dll", };
  188. /*
  189. * Save source path for restoration
  190. *
  191. * If we get a non-zero length string for the old
  192. * source path then we will restore it when finished
  193. */
  194. err = CtlGetLddPath(LDID_SRCPATH,szPrevSourcePath);
  195. if ((err == OK) && (lstrlen(szPrevSourcePath))) {
  196. DEBUGMSG("Saved Sourcpath [%s]", szPrevSourcePath );
  197. fNeedToRestorePrevSourcePath = TRUE;
  198. }
  199. /*
  200. * Set Source Path for GenInstall
  201. */
  202. DEBUGMSG("Setting Source path to [%s]", lpszDirectory );
  203. CtlSetLddPath(LDID_SRCPATH, lpszDirectory );
  204. /*
  205. * Set Up GenInstall UI
  206. */
  207. _fmemset(&VcpUiInfo,0,sizeof(VcpUiInfo));
  208. if ( ! dwQuietMode ) {
  209. VcpUiInfo.flags = VCPUI_CREATEPROGRESS;
  210. } else {
  211. VcpUiInfo.flags = 0;
  212. }
  213. VcpUiInfo.hwndParent = 0; // Our parent
  214. // VcpUiInfo.hwndParent = (HWND)hWnd; // Our parent
  215. VcpUiInfo.hwndProgress = NULL; // No progress DLG
  216. VcpUiInfo.idPGauge = 0;
  217. VcpUiInfo.lpfnStatCallback = NULL; // No stat callback
  218. VcpUiInfo.lUserData = 0L; // No client data.
  219. /*
  220. * Open VCP to batch copy requests
  221. */
  222. DEBUGMSG("Setting up VCP");
  223. err = VcpOpen((VIFPROC) vcpUICallbackProc, (LPARAM)(LPVCPUIINFO)&VcpUiInfo);
  224. if (err != OK)
  225. {
  226. DEBUGMSG("VcpOpen returned %u",err);
  227. return err;
  228. }
  229. DEBUGMSG("VCP Setup Complete");
  230. // Install advpack.dll and w95inf16.dll and w95inf32.dll
  231. for ( i = 0; i < 3; i += 1 ) {
  232. lstrcpy( szTempPath, lpszDirectory );
  233. AddPath( szTempPath, c_aszDlls[i] );
  234. if ( GetFileAttributes( szTempPath ) == 0xFFFFFFFF ) {
  235. continue;
  236. }
  237. err = VcpQueueCopy( c_aszDlls[i], c_aszDlls[i],
  238. NULL, NULL, LDID_SRCPATH, LDID_SYS,
  239. NULL, VNFL_MULTIPLEOK, VNLP_KEEPNEWER );
  240. if ( err != OK ) {
  241. VcpClose(VCPFL_ABANDON, NULL);
  242. return err;
  243. }
  244. }
  245. /*
  246. * Call GenInstall to Install Files
  247. */
  248. DEBUGMSG("Installing Files using InstallFilesFromINF()");
  249. err = InstallFilesFromINF(0, lpszInf, lpszSection, GENINSTALL_DO_FILES);
  250. // err = InstallFilesFromINF((HWND)hWnd, lpszInf, lpszSection, GENINSTALL_DO_FILES);
  251. DEBUGMSG("InstallFilesFromINF() Returned %d", err);
  252. if (err == OK)
  253. {
  254. err = VcpClose(VCPFL_COPY | VCPFL_DELETE | VCPFL_RENAME, NULL);
  255. if (err != OK)
  256. {
  257. DEBUGMSG("VcpClose returned %u", err);
  258. return(err);
  259. }
  260. }
  261. else
  262. {
  263. err = VcpClose(VCPFL_ABANDON, NULL);
  264. if (err != OK)
  265. {
  266. DEBUGMSG("VcpClose returned %u", err);
  267. return(err);
  268. }
  269. }
  270. /*
  271. * Now have GenInstall do rest of install
  272. */
  273. DEBUGMSG("Installing everything else using InstallFilesFromINF()");
  274. err = InstallFilesFromINF(0, lpszInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES);
  275. // err = InstallFilesFromINF((HWND)hWnd, lpszInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES);
  276. if (err != OK)
  277. {
  278. DEBUGMSG("InstallFilesFromINF() Non Files returned %d", err );
  279. return(err);
  280. }
  281. /*
  282. * Restore Source LDID
  283. */
  284. if (fNeedToRestorePrevSourcePath) {
  285. DEBUGMSG("Restoring source path to: %s",(LPSTR) szPrevSourcePath);
  286. err=CtlSetLddPath(LDID_SRCPATH,szPrevSourcePath);
  287. ASSERT(err == OK);
  288. }
  289. return(err);
  290. }
  291. VOID WINAPI GetSETUPXErrorText16(DWORD dwError,LPSTR pszErrorDesc, DWORD cbErrorDesc)
  292. {
  293. WORD wID; // ID of string resource in SETUPX with error description
  294. // get string ID with this error from setupx
  295. wID = suErrorToIds((WORD) dwError,E2I_SETUPX);
  296. if (wID) {
  297. CHAR szSetupxFilename[13]; // big enough for 8.3
  298. HMODULE hInstSetupx;
  299. // get setupx filename out of resource
  300. LoadString(hInstance,IDS_SETUPX_FILENAME,szSetupxFilename,
  301. sizeof(szSetupxFilename));
  302. // get the module handle for setupx
  303. hInstSetupx = GetModuleHandle(szSetupxFilename);
  304. ASSERT(hInstSetupx); // pretty weird if this fails
  305. if (hInstSetupx) {
  306. // load the string from setupx
  307. if (LoadString(hInstSetupx,wID,pszErrorDesc,(int) cbErrorDesc)) {
  308. return; // got it
  309. }
  310. }
  311. }
  312. // we get here if couldn't map error to string ID, couldn't get
  313. // SETUPX module handle, or couldn't find string ID in setupx. 1st
  314. // case is relatively likely, other cases are pretty unlikely.
  315. {
  316. CHAR szFmt[SMALL_BUF_LEN+1];
  317. // load generic text and insert error number
  318. LoadString(hInstance,IDS_GENERIC_SETUPX_ERR,szFmt,sizeof(szFmt));
  319. wsprintf(pszErrorDesc,szFmt,wID);
  320. }
  321. }
  322. WORD WINAPI CtlSetLddPath16(UINT uiLDID, LPSTR lpszPath)
  323. {
  324. return(CtlSetLddPath(uiLDID, lpszPath));
  325. }
  326. BOOL WINAPI GenFormStrWithoutPlaceHolders16( LPSTR lpszDst, LPSTR lpszSrc, LPSTR lpszInfFilename )
  327. {
  328. RETERR err = OK;
  329. HINF hInf;
  330. err = OpenValidateInf(lpszInfFilename, &hInf);
  331. if (err != OK) {
  332. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszInfFilename, err);
  333. return FALSE;
  334. }
  335. GenFormStrWithoutPlaceHolders( lpszDst, (LPCSTR) lpszSrc, hInf );
  336. IpClose( hInf );
  337. return TRUE;
  338. }