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.

433 lines
11 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. /*
  184. * Save source path for restoration
  185. *
  186. * If we get a non-zero length string for the old
  187. * source path then we will restore it when finished
  188. */
  189. err = CtlGetLddPath(LDID_SRCPATH,szPrevSourcePath);
  190. if ((err == OK) && (lstrlen(szPrevSourcePath))) {
  191. DEBUGMSG("Saved Sourcpath [%s]", szPrevSourcePath );
  192. fNeedToRestorePrevSourcePath = TRUE;
  193. }
  194. /*
  195. * Set Source Path for GenInstall
  196. */
  197. DEBUGMSG("Setting Source path to [%s]", lpszDirectory );
  198. CtlSetLddPath(LDID_SRCPATH, lpszDirectory );
  199. /*
  200. * Set Up GenInstall UI
  201. */
  202. _fmemset(&VcpUiInfo,0,sizeof(VcpUiInfo));
  203. if ( ! dwQuietMode ) {
  204. VcpUiInfo.flags = VCPUI_CREATEPROGRESS;
  205. } else {
  206. VcpUiInfo.flags = 0;
  207. }
  208. VcpUiInfo.hwndParent = 0; // Our parent
  209. // VcpUiInfo.hwndParent = (HWND)hWnd; // Our parent
  210. VcpUiInfo.hwndProgress = NULL; // No progress DLG
  211. VcpUiInfo.idPGauge = 0;
  212. VcpUiInfo.lpfnStatCallback = NULL; // No stat callback
  213. VcpUiInfo.lUserData = 0L; // No client data.
  214. /*
  215. * Open VCP to batch copy requests
  216. */
  217. DEBUGMSG("Setting up VCP");
  218. err = VcpOpen((VIFPROC) vcpUICallbackProc, (LPARAM)(LPVCPUIINFO)&VcpUiInfo);
  219. if (err != OK)
  220. {
  221. DEBUGMSG("VcpOpen returned %u",err);
  222. return err;
  223. }
  224. DEBUGMSG("VCP Setup Complete");
  225. /*
  226. * Call GenInstall to Install Files
  227. */
  228. DEBUGMSG("Installing Files using InstallFilesFromINF()");
  229. err = InstallFilesFromINF(0, lpszInf, lpszSection, GENINSTALL_DO_FILES);
  230. // err = InstallFilesFromINF((HWND)hWnd, lpszInf, lpszSection, GENINSTALL_DO_FILES);
  231. DEBUGMSG("InstallFilesFromINF() Returned %d", err);
  232. if (err == OK)
  233. {
  234. err = VcpClose(VCPFL_COPY | VCPFL_DELETE | VCPFL_RENAME, NULL);
  235. if (err != OK)
  236. {
  237. DEBUGMSG("VcpClose returned %u", err);
  238. return(err);
  239. }
  240. }
  241. else
  242. {
  243. err = VcpClose(VCPFL_ABANDON, NULL);
  244. if (err != OK)
  245. {
  246. DEBUGMSG("VcpClose returned %u", err);
  247. return(err);
  248. }
  249. }
  250. /*
  251. * Now have GenInstall do rest of install
  252. */
  253. DEBUGMSG("Installing everything else using InstallFilesFromINF()");
  254. err = InstallFilesFromINF(0, lpszInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES);
  255. // err = InstallFilesFromINF((HWND)hWnd, lpszInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES);
  256. if (err != OK)
  257. {
  258. DEBUGMSG("InstallFilesFromINF() Non Files returned %d", err );
  259. return(err);
  260. }
  261. /*
  262. * Restore Source LDID
  263. */
  264. if (fNeedToRestorePrevSourcePath) {
  265. DEBUGMSG("Restoring source path to: %s",(LPSTR) szPrevSourcePath);
  266. err=CtlSetLddPath(LDID_SRCPATH,szPrevSourcePath);
  267. ASSERT(err == OK);
  268. }
  269. return(err);
  270. }
  271. VOID WINAPI GetSETUPXErrorText16(DWORD dwError,LPSTR pszErrorDesc, DWORD cbErrorDesc)
  272. {
  273. WORD wID; // ID of string resource in SETUPX with error description
  274. // get string ID with this error from setupx
  275. wID = suErrorToIds((WORD) dwError,E2I_SETUPX);
  276. if (wID) {
  277. CHAR szSetupxFilename[13]; // big enough for 8.3
  278. HMODULE hInstSetupx;
  279. // get setupx filename out of resource
  280. LoadString(hInstance,IDS_SETUPX_FILENAME,szSetupxFilename,
  281. sizeof(szSetupxFilename));
  282. // get the module handle for setupx
  283. hInstSetupx = GetModuleHandle(szSetupxFilename);
  284. ASSERT(hInstSetupx); // pretty weird if this fails
  285. if (hInstSetupx) {
  286. // load the string from setupx
  287. if (LoadString(hInstSetupx,wID,pszErrorDesc,(int) cbErrorDesc)) {
  288. return; // got it
  289. }
  290. }
  291. }
  292. // we get here if couldn't map error to string ID, couldn't get
  293. // SETUPX module handle, or couldn't find string ID in setupx. 1st
  294. // case is relatively likely, other cases are pretty unlikely.
  295. {
  296. CHAR szFmt[SMALL_BUF_LEN+1];
  297. // load generic text and insert error number
  298. LoadString(hInstance,IDS_GENERIC_SETUPX_ERR,szFmt,sizeof(szFmt));
  299. wsprintf(pszErrorDesc,szFmt,wID);
  300. }
  301. }
  302. WORD WINAPI CtlSetLddPath16(UINT uiLDID, LPSTR lpszPath)
  303. {
  304. return(CtlSetLddPath(uiLDID, lpszPath));
  305. }
  306. BOOL WINAPI GenFormStrWithoutPlaceHolders16( LPSTR lpszDst, LPSTR lpszSrc, LPSTR lpszInfFilename )
  307. {
  308. RETERR err = OK;
  309. HINF hInf;
  310. err = OpenValidateInf(lpszInfFilename, &hInf);
  311. if (err != OK) {
  312. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszInfFilename, err);
  313. return FALSE;
  314. }
  315. GenFormStrWithoutPlaceHolders( lpszDst, (LPCSTR) lpszSrc, hInf );
  316. IpClose( hInf );
  317. return TRUE;
  318. }