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.

367 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. #pragma message("If you change W95INF16.DLL, you need to manually increase")
  17. #pragma message("the version number in w95inf16.rcv. This is not done automatically.")
  18. #define SHORTSTRING 256
  19. /*
  20. * GLOBALS
  21. */
  22. HINSTANCE hInstance;
  23. CHAR szDll16[] = "W95INF16.DLL";
  24. CHAR szDll32[] = "W95INF32.DLL";
  25. static char g_szRunOnceExe[] = {"runonce"};
  26. /*
  27. * S T R I N G S
  28. */
  29. char *szSectVersion = "version";
  30. char *szKeySignature = "signature";
  31. char *szValSignature = "$CHICAGO$";
  32. /*
  33. * Declarations
  34. */
  35. BOOL FAR PASCAL w95thk_ThunkConnect16(LPSTR pszDLL16, LPSTR pszDll32, WORD hInst, DWORD dwReason);
  36. VOID WINAPI GetSETUPXErrorText16(DWORD,LPSTR, DWORD);
  37. WORD WINAPI CtlSetLddPath16(UINT, LPSTR);
  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. *phInf = NULL;
  84. /*
  85. * Open the INF
  86. */
  87. err = IpOpen( lpszInfFile, &hInfFile );
  88. if (err != OK) {
  89. DEBUGMSG("IpOpen(%s) returned %u",(LPSTR) lpszInfFile,err);
  90. return err;
  91. }
  92. /*
  93. * Get INF signature
  94. */
  95. err = IpGetProfileString( hInfFile, szSectVersion, szKeySignature, szTmpBuf, sizeof(szTmpBuf));
  96. if (err != OK) {
  97. DEBUGMSG("IpGetProfileString returned %u",err);
  98. return err;
  99. }
  100. /*
  101. * Check INF signature
  102. */
  103. if ( lstrcmpi(szTmpBuf,szValSignature) != 0 ) {
  104. DEBUGMSG("signature error in %s",(LPSTR) lpszInfFile);
  105. IpClose(hInfFile);
  106. return ERR_IP_INVALID_INFFILE;
  107. }
  108. /*
  109. * Set Out Parameter phInf
  110. */
  111. *phInf = hInfFile;
  112. DEBUGMSG("OpenValidateInf([%s]) Complete", lpszInfFile );
  113. return OK;
  114. }
  115. //***************************************************************************
  116. //* *
  117. //* NAME: AddPath *
  118. //* *
  119. //* SYNOPSIS: *
  120. //* *
  121. //* REQUIRES: *
  122. //* *
  123. //* RETURNS: *
  124. //* *
  125. //***************************************************************************
  126. VOID AddPath(LPSTR szPath, LPCSTR szName )
  127. {
  128. LPSTR szTmp;
  129. // Find end of the string
  130. szTmp = szPath + lstrlen(szPath);
  131. // If no trailing backslash then add one
  132. if ( szTmp > szPath && *(AnsiPrev( szPath, szTmp )) != '\\' )
  133. *(szTmp++) = '\\';
  134. // Add new name to existing path string
  135. while ( *szName == ' ' ) szName++;
  136. lstrcpy( szTmp, szName );
  137. }
  138. //BUGBUG: Ideally, we would like to use the HWND in here, but in 32-bit land,
  139. // HWND is 32-bits and in 16-bit land, HWND is 16-bits, so we have a
  140. // problem.
  141. //WORD WINAPI GenInstall16(LPSTR lpszInf, LPSTR lpszSection, LPSTR lpszDirectory, DWORD dwQuietMode, DWORD hWnd )
  142. WORD WINAPI GenInstall16(LPSTR lpszInf, LPSTR lpszSection, LPSTR lpszDirectory, DWORD dwQuietMode )
  143. {
  144. VCPUIINFO VcpUiInfo;
  145. RETERR err;
  146. BYTE fNeedBoot = 1;
  147. char szPrevSourcePath[MAX_PATH+1] = "";
  148. BOOL fNeedToRestorePrevSourcePath = FALSE;
  149. HINF hInf = NULL;
  150. ASSERT(lpszInf);
  151. ASSERT(lpszSection);
  152. /*
  153. * Open INF
  154. */
  155. err = OpenValidateInf(lpszInf, &hInf);
  156. if (err != OK) {
  157. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszInf, err);
  158. goto done;
  159. }
  160. ASSERT(hInf);
  161. /*
  162. * Save source path for restoration
  163. *
  164. * If we get a non-zero length string for the old
  165. * source path then we will restore it when finished
  166. */
  167. err = CtlGetLddPath(LDID_SRCPATH,szPrevSourcePath);
  168. if ((err == OK) && (lstrlen(szPrevSourcePath))) {
  169. DEBUGMSG("Saved Sourcpath [%s]", szPrevSourcePath );
  170. fNeedToRestorePrevSourcePath = TRUE;
  171. }
  172. /*
  173. * Set Source Path for GenInstall
  174. */
  175. DEBUGMSG("Setting Source path to [%s]", lpszDirectory );
  176. CtlSetLddPath(LDID_SRCPATH, lpszDirectory );
  177. /*
  178. * Set Up GenInstall UI
  179. */
  180. _fmemset(&VcpUiInfo,0,sizeof(VcpUiInfo));
  181. if ( ! dwQuietMode ) {
  182. VcpUiInfo.flags = VCPUI_CREATEPROGRESS;
  183. } else {
  184. VcpUiInfo.flags = 0;
  185. }
  186. VcpUiInfo.hwndParent = 0; // 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. goto done;
  200. }
  201. DEBUGMSG("VCP Setup Complete");
  202. /*
  203. * Call GenInstall to Install Files
  204. */
  205. /*
  206. * GenInstall Go Do your thing
  207. */
  208. err = GenInstall(hInf,lpszSection, GENINSTALL_DO_FILES );
  209. // err = InstallFilesFromINF(0, lpszInf, lpszSection, GENINSTALL_DO_FILES);
  210. DEBUGMSG("GeInstall() DO_FILE Returned %d", err);
  211. if (err == OK)
  212. {
  213. err = VcpClose(VCPFL_COPY | VCPFL_DELETE | VCPFL_RENAME, NULL);
  214. if (err != OK)
  215. {
  216. DEBUGMSG("VcpClose returned %u", err);
  217. goto done;
  218. }
  219. }
  220. else
  221. {
  222. err = VcpClose(VCPFL_ABANDON, NULL);
  223. if (err != OK)
  224. {
  225. DEBUGMSG("VcpClose returned %u", err);
  226. goto done;
  227. }
  228. }
  229. /*
  230. * Now have GenInstall do rest of install
  231. */
  232. err = GenInstall(hInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES );
  233. //DEBUGMSG("Installing everything else using InstallFilesFromINF()");
  234. //err = InstallFilesFromINF(0, lpszInf, lpszSection, GENINSTALL_DO_ALL ^ GENINSTALL_DO_FILES);
  235. if (err != OK)
  236. {
  237. DEBUGMSG("GenInstall() Non Files returned %d", err );
  238. goto done;
  239. }
  240. done:
  241. /*
  242. * Restore Source LDID
  243. */
  244. if (fNeedToRestorePrevSourcePath) {
  245. DEBUGMSG("Restoring source path to: %s",(LPSTR) szPrevSourcePath);
  246. err=CtlSetLddPath(LDID_SRCPATH,szPrevSourcePath);
  247. ASSERT(err == OK);
  248. }
  249. if ( hInf )
  250. IpClose( hInf );
  251. return(err);
  252. }
  253. VOID WINAPI GetSETUPXErrorText16(DWORD dwError,LPSTR pszErrorDesc, DWORD cbErrorDesc)
  254. {
  255. WORD wID; // ID of string resource in SETUPX with error description
  256. // get string ID with this error from setupx
  257. wID = suErrorToIds((WORD) dwError,E2I_SETUPX);
  258. if (wID) {
  259. CHAR szSetupxFilename[13]; // big enough for 8.3
  260. HMODULE hInstSetupx;
  261. // get setupx filename out of resource
  262. LoadString(hInstance,IDS_SETUPX_FILENAME,szSetupxFilename,
  263. sizeof(szSetupxFilename));
  264. // get the module handle for setupx
  265. hInstSetupx = GetModuleHandle(szSetupxFilename);
  266. ASSERT(hInstSetupx); // pretty weird if this fails
  267. if (hInstSetupx) {
  268. // load the string from setupx
  269. if (LoadString(hInstSetupx,wID,pszErrorDesc,(int) cbErrorDesc)) {
  270. return; // got it
  271. }
  272. }
  273. }
  274. // we get here if couldn't map error to string ID, couldn't get
  275. // SETUPX module handle, or couldn't find string ID in setupx. 1st
  276. // case is relatively likely, other cases are pretty unlikely.
  277. {
  278. CHAR szFmt[SMALL_BUF_LEN+1];
  279. // load generic text and insert error number
  280. LoadString(hInstance,IDS_GENERIC_SETUPX_ERR,szFmt,sizeof(szFmt));
  281. wsprintf(pszErrorDesc,szFmt,wID);
  282. }
  283. }
  284. WORD WINAPI CtlSetLddPath16(UINT uiLDID, LPSTR lpszPath)
  285. {
  286. return(CtlSetLddPath(uiLDID, lpszPath));
  287. }
  288. BOOL WINAPI GenFormStrWithoutPlaceHolders16( LPSTR lpszDst, LPSTR lpszSrc, LPSTR lpszInfFilename )
  289. {
  290. RETERR err = OK;
  291. HINF hInf;
  292. err = OpenValidateInf(lpszInfFilename, &hInf);
  293. if (err != OK) {
  294. DEBUGMSG("OpenValidateInf(%s) returned %u",lpszInfFilename, err);
  295. return FALSE;
  296. }
  297. GenFormStrWithoutPlaceHolders( lpszDst, (LPCSTR) lpszSrc, hInf );
  298. IpClose( hInf );
  299. return TRUE;
  300. }