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.

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