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.

445 lines
10 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. WORD WINAPI CtlSetLddPath16(UINT uiLDID, LPSTR lpszPath);
  35. WORD WINAPI GenInstall16(LPSTR lpszInf, LPSTR lpszSection, LPSTR lpszDirectory);
  36. BOOL WINAPI GenFormStrWithoutPlaceHolders16( LPSTR lpszDst, LPSTR lpszSrc, LPSTR lpszInfFilename );
  37. /*
  38. * Library Initialization
  39. *
  40. * Call by LibInit
  41. */
  42. BOOL FAR PASCAL LibMain(HINSTANCE hInst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
  43. {
  44. // Keep Copy of Instance
  45. hInstance = hInst;
  46. DEBUGMSG("W95INF16.DLL - LibMain()");
  47. return( TRUE );
  48. }
  49. /*
  50. * Thunk Entry Point
  51. */
  52. BOOL FAR PASCAL DllEntryPoint(DWORD dwReason, WORD hInst, WORD wDS, WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
  53. {
  54. DEBUGMSG("W95INF16.DLL - DllEntryPoint()");
  55. if (! (w95thk_ThunkConnect16(szDll16, szDll32, hInst, dwReason))) {
  56. DEBUGMSG("W95INF16.DLL - w95thk_ThunkConnect16() Failed");
  57. return( FALSE );
  58. }
  59. return( TRUE );
  60. }
  61. /*
  62. * O P E N _ V A L I D A T E _ I N F
  63. *
  64. * Routine: OpenValidateInf
  65. *
  66. * Purpose: Open INF and validate internals
  67. *
  68. * Notes: Stolen from setupx
  69. *
  70. *
  71. */
  72. RETERR OpenValidateInf(LPCSTR lpszInfFile, HINF FAR * phInf )
  73. {
  74. RETERR err;
  75. HINF hInfFile;
  76. char szTmpBuf[SHORTSTRING];
  77. ASSERT(lpszInfFile);
  78. ASSERT(phInf);
  79. DEBUGMSG("OpenValidateInf([%s])", lpszInfFile );
  80. /*
  81. * Open the INF
  82. */
  83. err = IpOpen( lpszInfFile, &hInfFile );
  84. if (err != OK) {
  85. DEBUGMSG("IpOpen(%s) returned %u",(LPSTR) lpszInfFile,err);
  86. return err;
  87. }
  88. /*
  89. * Get INF signature
  90. */
  91. err = IpGetProfileString( hInfFile, szSectVersion, szKeySignature, szTmpBuf, sizeof(szTmpBuf));
  92. if (err != OK) {
  93. DEBUGMSG("IpGetProfileString returned %u",err);
  94. return err;
  95. }
  96. /*
  97. * Check INF signature
  98. */
  99. if ( lstrcmpi(szTmpBuf,szValSignature) != 0 ) {
  100. DEBUGMSG("signature error in %s",(LPSTR) lpszInfFile);
  101. IpClose(hInfFile);
  102. return ERR_IP_INVALID_INFFILE;
  103. }
  104. /*
  105. * Set Out Parameter phInf
  106. */
  107. *phInf = hInfFile;
  108. DEBUGMSG("OpenValidateInf([%s]) Complete", lpszInfFile );
  109. return OK;
  110. }
  111. /*
  112. * I N S T A L L F I L E S F R O M I N F
  113. *
  114. * Routine: InstallFilesFromINF()
  115. *
  116. * Purpose: Call GenInstall to GenInstall a section of an INF
  117. * using specified flags
  118. *
  119. */
  120. RETERR InstallFilesFromINF(HWND hwndParent, LPCSTR lpszINF, LPCSTR lpszSection, WORD wFlags)
  121. {
  122. RETERR err = OK;
  123. HINF hInf;
  124. ASSERT(lpszINF);
  125. ASSERT(lpszSection);
  126. DEBUGMSG("InstallFilesFromINF([%s], [%s], [%x])", lpszINF, lpszSection, wFlags );
  127. /*
  128. * Open INF
  129. */
  130. err = OpenValidateInf(lpszINF, &hInf);
  131. if (err != OK) {
  132. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszINF, err);
  133. return err;
  134. }
  135. ASSERT(hInf);
  136. /*
  137. * GenInstall Go Do your thing
  138. */
  139. err = GenInstall(hInf,lpszSection, wFlags );
  140. /*
  141. * Close INF
  142. */
  143. IpClose(hInf);
  144. return err;
  145. }
  146. /*
  147. * I N S T A L L S T O P
  148. *
  149. * Routine: InstallStop()
  150. *
  151. * Purpose: Perform install cleanup such as group converter
  152. * (program group stuff) and renaming
  153. *
  154. * CODE STOLEN FROM SETUPX.DLL
  155. *
  156. *
  157. */
  158. RETERR InstallStop( BYTE FAR *fNeedBoot )
  159. {
  160. char szSubkey[MAX_PATH];
  161. char szGrpConv[MAX_PATH] = {"grpconv -o"};
  162. HKEY hkey;
  163. RETERR reRet = OK;
  164. if ( *fNeedBoot ) {
  165. /*
  166. * Make the RunOnce do GrpConvert
  167. */
  168. lstrcpy(szSubkey, REGSTR_PATH_RUNONCE);
  169. if (RegOpenKey(HKEY_LOCAL_MACHINE, szSubkey, &hkey) == ERROR_SUCCESS) {
  170. RegSetValueEx(hkey, "GrpConv", 0, REG_SZ, (LPBYTE)szGrpConv, lstrlen(szGrpConv) );
  171. RegCloseKey(hkey);
  172. }
  173. }
  174. else
  175. {
  176. WinExec( szGrpConv, SW_SHOWNORMAL );
  177. }
  178. return( reRet);
  179. }
  180. WORD WINAPI GenInstall16(LPSTR lpszInf, LPSTR lpszSection, LPSTR lpszDirectory)
  181. {
  182. VCPUIINFO VcpUiInfo;
  183. RETERR err;
  184. HWND hwndParent = 0;
  185. BYTE fNeedBoot = 1;
  186. char szPrevSourcePath[MAX_PATH+1] = "";
  187. BOOL fNeedToRestorePrevSourcePath = FALSE;
  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. VcpUiInfo.flags = VCPUI_CREATEPROGRESS;
  209. VcpUiInfo.hwndParent = hwndParent; // 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(hwndParent, lpszInf, lpszSection, GENINSTALL_DO_FILES);
  230. DEBUGMSG("InstallFilesFromINF() Returned %d", err);
  231. if (err == OK)
  232. {
  233. err = VcpClose(VCPFL_COPY | VCPFL_DELETE | VCPFL_RENAME, NULL);
  234. if (err != OK)
  235. {
  236. DEBUGMSG("VcpClose returned %u", err);
  237. return(err);
  238. }
  239. }
  240. else
  241. {
  242. err = VcpClose(VCPFL_ABANDON, NULL);
  243. if (err != OK)
  244. {
  245. DEBUGMSG("VcpClose returned %u", err);
  246. return(err);
  247. }
  248. }
  249. /*
  250. * Now have GenInstall do rest of install
  251. */
  252. DEBUGMSG("Installing everything else using InstallFilesFromINF()");
  253. err = InstallFilesFromINF(hwndParent, lpszInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES);
  254. if (err != OK)
  255. {
  256. DEBUGMSG("InstallFilesFromINF() Non Files returned %d", err );
  257. return(err);
  258. }
  259. /*
  260. * Kick off run-once stuff to run grpconverter and rename
  261. * directories
  262. */
  263. err = InstallStop(&fNeedBoot);
  264. if (err != OK)
  265. {
  266. DEBUGMSG("InstallStop() (runonce, group converter) failed: %d", err );
  267. return(err);
  268. }
  269. /*
  270. * Restore Source LDID
  271. */
  272. if (fNeedToRestorePrevSourcePath) {
  273. DEBUGMSG("Restoring source path to: %s",(LPSTR) szPrevSourcePath);
  274. err=CtlSetLddPath(LDID_SRCPATH,szPrevSourcePath);
  275. ASSERT(err == OK);
  276. }
  277. return(err);
  278. }
  279. VOID WINAPI GetSETUPXErrorText16(DWORD dwError,LPSTR pszErrorDesc, DWORD cbErrorDesc)
  280. {
  281. WORD wID; // ID of string resource in SETUPX with error description
  282. // get string ID with this error from setupx
  283. wID = suErrorToIds((WORD) dwError,E2I_SETUPX);
  284. if (wID) {
  285. CHAR szSetupxFilename[13]; // big enough for 8.3
  286. HMODULE hInstSetupx;
  287. // get setupx filename out of resource
  288. LoadString(hInstance,IDS_SETUPX_FILENAME,szSetupxFilename,
  289. sizeof(szSetupxFilename));
  290. // get the module handle for setupx
  291. hInstSetupx = GetModuleHandle(szSetupxFilename);
  292. ASSERT(hInstSetupx); // pretty weird if this fails
  293. if (hInstSetupx) {
  294. // load the string from setupx
  295. if (LoadString(hInstSetupx,wID,pszErrorDesc,(int) cbErrorDesc)) {
  296. return; // got it
  297. }
  298. }
  299. }
  300. // we get here if couldn't map error to string ID, couldn't get
  301. // SETUPX module handle, or couldn't find string ID in setupx. 1st
  302. // case is relatively likely, other cases are pretty unlikely.
  303. {
  304. CHAR szFmt[SMALL_BUF_LEN+1];
  305. // load generic text and insert error number
  306. LoadString(hInstance,IDS_GENERIC_SETUPX_ERR,szFmt,sizeof(szFmt));
  307. wsprintf(pszErrorDesc,szFmt,wID);
  308. }
  309. }
  310. WORD WINAPI CtlSetLddPath16(UINT uiLDID, LPSTR lpszPath)
  311. {
  312. return(CtlSetLddPath(uiLDID, lpszPath));
  313. }
  314. BOOL WINAPI GenFormStrWithoutPlaceHolders16( LPSTR lpszDst, LPSTR lpszSrc, LPSTR lpszInfFilename )
  315. {
  316. RETERR err = OK;
  317. HINF hInf;
  318. err = OpenValidateInf(lpszInfFilename, &hInf);
  319. if (err != OK) {
  320. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszInfFilename, err);
  321. return FALSE;
  322. }
  323. GenFormStrWithoutPlaceHolders( lpszDst, (LPCSTR) lpszSrc, hInf );
  324. IpClose( hInf );
  325. return TRUE;
  326. }