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.

535 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File Name: fxState.cpp
  4. //
  5. // Abstract: This provides the state routines used in the FaxOCM
  6. // code base.
  7. //
  8. // Environment: Windows XP / User Mode
  9. //
  10. // Copyright (c) 2000 Microsoft Corporation
  11. //
  12. // Revision History:
  13. //
  14. // Date: Developer: Comments:
  15. // ----- ---------- ---------
  16. // 21-Mar-2000 Oren Rosenbloom (orenr) Created file, cleanup routines
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "faxocm.h"
  19. #pragma hdrstop
  20. ///////////////////////////////////////////////////////////////////////////////////////
  21. // Function:
  22. // prv_IsXPOrDotNetUpgrade
  23. //
  24. // Purpose:
  25. // This function searches for FXSAPI.DLL in %system32% and if
  26. // it exists the function returns TRUE, indicating that this is an
  27. // upgrade from XP or .NET Server.
  28. // Params:
  29. // None
  30. //
  31. // Return Value:
  32. // TRUE - This is a XP or .NET upgrade
  33. // FALSE - This is W2K, or a failure occured.
  34. //
  35. // Author:
  36. // Mooly Beery (MoolyB) 26-Dec-2001
  37. ///////////////////////////////////////////////////////////////////////////////////////
  38. BOOL prv_IsXPOrDotNetUpgrade()
  39. {
  40. BOOL bRet = FALSE;
  41. HANDLE hFind = NULL;
  42. WIN32_FIND_DATA FindFileData = {0};
  43. TCHAR szSystemDirectory[MAX_PATH] = {0};
  44. DBG_ENTER(TEXT("prv_IsXPOrDotNetUpgrade"),bRet);
  45. // get the system directory
  46. if (GetSystemDirectory(szSystemDirectory,MAX_PATH-_tcslen(FAX_API_MODULE_NAME)-1)==0)
  47. {
  48. VERBOSE( SETUP_ERR,TEXT("GetSystemDirectory failed (ec: %ld)"),GetLastError());
  49. goto exit;
  50. }
  51. // append
  52. _tcscat(szSystemDirectory,_T("\\"));
  53. _tcscat(szSystemDirectory,FAX_API_MODULE_NAME);
  54. // search for FXSAPI.DLL in the system folder
  55. hFind = FindFirstFile(szSystemDirectory, &FindFileData);
  56. if (hFind==INVALID_HANDLE_VALUE)
  57. {
  58. VERBOSE( DBG_WARNING,
  59. TEXT("FindFirstFile %s failed (ec: %ld)"),
  60. szSystemDirectory,
  61. GetLastError());
  62. goto exit;
  63. }
  64. // found it.
  65. bRet = TRUE;
  66. FindClose(hFind);
  67. exit:
  68. return bRet;
  69. }
  70. ///////////////////////////////////////////////////////////////////////////////////////
  71. // Function:
  72. // prv_IsRepair
  73. //
  74. // Purpose:
  75. // This function determines whether this is a 'same build' upgrade
  76. // which means the user wants to perform a 'repair' operation.
  77. // This is done by comparing the values for SKU and Version we
  78. // write each setup with current values.
  79. // A 'repair' is an upgrade from same build to itself without
  80. // the SKU changing.
  81. //
  82. // Params:
  83. // None
  84. //
  85. // Return Value:
  86. // TRUE - Upgrading from same build to itself and SKU didn't change.
  87. // FALSE - Otherwise.
  88. //
  89. // Author:
  90. // Mooly Beery (MoolyB) 06-Jan-2002
  91. ///////////////////////////////////////////////////////////////////////////////////////
  92. BOOL prv_IsRepair()
  93. {
  94. BOOL bRet = FALSE;
  95. PRODUCT_SKU_TYPE InstalledProductSKU = PRODUCT_SKU_UNKNOWN;
  96. DWORD InstalledProductBuild = 0;
  97. DBG_ENTER(TEXT("prv_IsXPOrDotNetUpgrade"),bRet);
  98. faxocm_GetProductInfo(&InstalledProductSKU,&InstalledProductBuild);
  99. if (InstalledProductSKU!=GetProductSKU())
  100. {
  101. VERBOSE(DBG_MSG,_T("Different SKU upgrade, this is not repair"));
  102. return FALSE;
  103. }
  104. if (InstalledProductBuild!=GetProductBuild())
  105. {
  106. VERBOSE(DBG_MSG,_T("Different build upgrade, this is not repair"));
  107. return FALSE;
  108. }
  109. return TRUE;
  110. }
  111. ///////////////////////////////
  112. // fxState_Init
  113. //
  114. // Initialize the state handling
  115. // module for Faxocm.
  116. //
  117. // Params:
  118. // - void
  119. // Returns:
  120. // - NO_ERROR on success.
  121. // - error code otherwise.
  122. //
  123. DWORD fxState_Init(void)
  124. {
  125. DWORD dwRes = NO_ERROR;
  126. DBG_ENTER(_T("Init State module"),dwRes);
  127. return dwRes;
  128. }
  129. ///////////////////////////////
  130. // fxState_Term
  131. //
  132. // Terminate the state handling module
  133. //
  134. // Params:
  135. // - void.
  136. // Returns:
  137. // - NO_ERROR on success.
  138. // - error code otherwise.
  139. //
  140. DWORD fxState_Term(void)
  141. {
  142. DWORD dwRes = NO_ERROR;
  143. DBG_ENTER(_T("Term State module"),dwRes);
  144. return dwRes;
  145. }
  146. ///////////////////////////////
  147. // fxState_IsUnattended
  148. //
  149. // Determines if this is an unattended install
  150. // It interprets flags given to us
  151. // by OC Manager.
  152. //
  153. // Params:
  154. // - void.
  155. // Returns:
  156. // - TRUE if unattended install.
  157. // - FALSE if not.
  158. //
  159. BOOL fxState_IsUnattended(void)
  160. {
  161. DWORDLONG dwlFlags = 0;
  162. // get the setup flags.
  163. dwlFlags = faxocm_GetComponentFlags();
  164. // if SETOP_BATCH flag is set, then we are in unattended mode.
  165. return (dwlFlags & SETUPOP_BATCH) ? TRUE : FALSE;
  166. }
  167. ///////////////////////////////
  168. // fxState_IsCleanInstall
  169. //
  170. // Determines if this a clean install.
  171. // A clean install is when we are
  172. // NOT upgrading, and we are not
  173. // running in stand alone mode (see below for def'n).
  174. //
  175. // Params:
  176. // - void.
  177. // Returns:
  178. // - TRUE if clean install.
  179. // - FALSE if not.
  180. //
  181. BOOL fxState_IsCleanInstall(void)
  182. {
  183. BOOL bClean = FALSE;
  184. // a clean install is if we are NOT upgrading AND we are not in
  185. // stand alone mode.
  186. if (!fxState_IsUpgrade() && !fxState_IsStandAlone())
  187. {
  188. bClean = TRUE;
  189. }
  190. return bClean;
  191. }
  192. ///////////////////////////////
  193. // fxState_IsStandAlone
  194. //
  195. // Determines if we are running in
  196. // standalone mode or not. We are
  197. // in this mode if the user started
  198. // us up via "sysocmgr.exe" found
  199. // in %systemroot%\system32, as opposed
  200. // to via the install setup, or the
  201. // Add/Remove Windows Components.
  202. //
  203. // Params:
  204. // - void.
  205. // Returns:
  206. // - TRUE if we are in stand alone mode.
  207. // - FALSE if we are not.
  208. //
  209. BOOL fxState_IsStandAlone(void)
  210. {
  211. DWORDLONG dwlFlags = 0;
  212. dwlFlags = faxocm_GetComponentFlags();
  213. return ((dwlFlags & SETUPOP_STANDALONE) ? TRUE : FALSE);
  214. }
  215. ///////////////////////////////
  216. // fxState_IsUpgrade
  217. //
  218. // Determines if we are upgrading
  219. // the OS, as opposed to a clean
  220. // installation.
  221. //
  222. // Params:
  223. // - void.
  224. // Returns:
  225. // - fxState_UpgradeType_e enumerated
  226. // type indicating the type of upgrade.
  227. // (i.e. are we upgrading from Win9X,
  228. // W2K, etc).
  229. //
  230. fxState_UpgradeType_e fxState_IsUpgrade(void)
  231. {
  232. fxState_UpgradeType_e eUpgradeType = FXSTATE_UPGRADE_TYPE_NONE;
  233. DWORDLONG dwlFlags = 0;
  234. static BOOL bXpDotNetUpgrade = prv_IsXPOrDotNetUpgrade();
  235. static BOOL bIsRepair = prv_IsRepair();
  236. dwlFlags = faxocm_GetComponentFlags();
  237. if ((dwlFlags & SETUPOP_WIN31UPGRADE) == SETUPOP_WIN31UPGRADE)
  238. {
  239. eUpgradeType = FXSTATE_UPGRADE_TYPE_WIN31;
  240. }
  241. else if ((dwlFlags & SETUPOP_WIN95UPGRADE) == SETUPOP_WIN95UPGRADE)
  242. {
  243. eUpgradeType = FXSTATE_UPGRADE_TYPE_WIN9X;
  244. }
  245. else if ((dwlFlags & SETUPOP_NTUPGRADE) == SETUPOP_NTUPGRADE)
  246. {
  247. if (bXpDotNetUpgrade)
  248. {
  249. if (bIsRepair)
  250. {
  251. eUpgradeType = FXSTATE_UPGRADE_TYPE_REPAIR;
  252. }
  253. else
  254. {
  255. eUpgradeType = FXSTATE_UPGRADE_TYPE_XP_DOT_NET;
  256. }
  257. }
  258. else
  259. {
  260. eUpgradeType = FXSTATE_UPGRADE_TYPE_W2K;
  261. }
  262. }
  263. return eUpgradeType;
  264. }
  265. ///////////////////////////////
  266. // fxState_IsOsServerBeingInstalled
  267. //
  268. // Are we installing the Server
  269. // version of the OS, or a workstation
  270. // or personal version.
  271. //
  272. // Params:
  273. // - void.
  274. // Returns:
  275. // - TRUE if we are installing a server version.
  276. // - FALSE if we are not.
  277. BOOL fxState_IsOsServerBeingInstalled(void)
  278. {
  279. BOOL bIsServerInstall = FALSE;
  280. DWORD dwProductType = 0;
  281. dwProductType = faxocm_GetProductType();
  282. if (dwProductType == PRODUCT_WORKSTATION)
  283. {
  284. bIsServerInstall = FALSE;
  285. }
  286. else
  287. {
  288. bIsServerInstall = TRUE;
  289. }
  290. return bIsServerInstall;
  291. }
  292. ///////////////////////////////
  293. // fxState_GetInstallType
  294. //
  295. // This function returns one
  296. // of the INF_KEYWORD_INSTALLTYPE_*
  297. // constants found in
  298. // fxconst.h/fxconst.cpp
  299. //
  300. // Params:
  301. // - pszCurrentSection - section we are installing from
  302. // Returns:
  303. // - ptr to one of INF_KEYWORD_INSTALLTYPE_* constants.
  304. //
  305. const TCHAR* fxState_GetInstallType(const TCHAR* pszCurrentSection)
  306. {
  307. DWORD dwErr = NO_ERROR;
  308. BOOL bInstall = TRUE;
  309. BOOL bSelectionHasChanged = FALSE;
  310. DBG_ENTER(_T("fxState_GetInstallType"),_T("%s"),pszCurrentSection);
  311. if (pszCurrentSection == NULL)
  312. {
  313. ::SetLastError(ERROR_INVALID_PARAMETER);
  314. return NULL;
  315. }
  316. // determine if we are installing or uninstalling
  317. dwErr = faxocm_HasSelectionStateChanged(pszCurrentSection,
  318. &bSelectionHasChanged,
  319. &bInstall,
  320. NULL);
  321. if (dwErr != NO_ERROR)
  322. {
  323. VERBOSE(SETUP_ERR,
  324. _T("faxocm_HasSelectionStateChanged failed, rc = 0x%lx"),
  325. dwErr);
  326. return NULL;
  327. }
  328. // we expect the INF to look something like this:
  329. // [Fax]
  330. //
  331. // FaxCleanInstall = Fax.CleanInstall
  332. // FaxUpgradeFromWin9x = Fax.UpgradeFromWin9x
  333. // FaxUninstall = Fax.Uninstall
  334. //
  335. // [Fax.CleanInstall]
  336. // CopyFiles = ...
  337. // etc.
  338. //
  339. // Thus the goal of this function is to determine if we are
  340. // clean installing, upgrading, etc., and then get the section
  341. // name pointed to by one of 'FaxCleanInstall', 'FaxUpgradeFromWin9x'
  342. // , or 'FaxUninstall'.
  343. //
  344. // So for example, if we determined we are clean installing, then
  345. // this function will find the "FaxCleanInstall" keyword, and then
  346. // return "Fax.CleanInstall" in the 'pszSectionToProcess' buffer.
  347. if (bInstall)
  348. {
  349. fxState_UpgradeType_e eUpgrade = FXSTATE_UPGRADE_TYPE_NONE;
  350. if (fxState_IsCleanInstall())
  351. {
  352. // we are a clean install of the OS, user is not upgrading from
  353. // another OS, they are installing a clean version of the OS.
  354. return INF_KEYWORD_INSTALLTYPE_CLEAN;
  355. }
  356. else if (fxState_IsUpgrade())
  357. {
  358. // We are installing as an Upgrade to another OS.
  359. // Determine which OS we are upgrading, then determine
  360. // the type of install to perform.
  361. eUpgrade = fxState_IsUpgrade();
  362. switch (eUpgrade)
  363. {
  364. case FXSTATE_UPGRADE_TYPE_NONE:
  365. return INF_KEYWORD_INSTALLTYPE_CLEAN;
  366. break;
  367. case FXSTATE_UPGRADE_TYPE_WIN9X:
  368. return INF_KEYWORD_INSTALLTYPE_UPGFROMWIN9X;
  369. break;
  370. case FXSTATE_UPGRADE_TYPE_W2K:
  371. return INF_KEYWORD_INSTALLTYPE_UPGFROMWIN2K;
  372. break;
  373. case FXSTATE_UPGRADE_TYPE_XP_DOT_NET:
  374. return INF_KEYWORD_INSTALLTYPE_UPGFROMXPDOTNET;
  375. case FXSTATE_UPGRADE_TYPE_REPAIR:
  376. return INF_KEYWORD_INSTALLTYPE_CLEAN;
  377. default:
  378. VERBOSE(SETUP_ERR,
  379. _T("Failed to get section to process "),
  380. _T("for install. Upgrade Type = %lu"),
  381. eUpgrade);
  382. break;
  383. }
  384. }
  385. else if (fxState_IsStandAlone())
  386. {
  387. // we are being run from SysOcMgr.exe.
  388. // SysOcMgr.exe is either invoked from the command line
  389. // (usually as a way to test new OCM components - not really in
  390. // the retail world), or it is invoked by the Add/Remove
  391. // Windows Components in control panel. In either case,
  392. // treat it as a clean install.
  393. return INF_KEYWORD_INSTALLTYPE_CLEAN;
  394. }
  395. }
  396. else
  397. {
  398. return INF_KEYWORD_INSTALLTYPE_UNINSTALL;
  399. }
  400. return NULL;
  401. }
  402. ///////////////////////////////
  403. // fxState_DumpSetupState
  404. //
  405. // Dumps to debug the state we
  406. // are running in.
  407. //
  408. // Params:
  409. // void
  410. // Returns:
  411. // void
  412. //
  413. //
  414. void fxState_DumpSetupState(void)
  415. {
  416. DWORD dwExpectedOCManagerVersion = 0;
  417. DWORD dwCurrentOCManagerVersion = 0;
  418. TCHAR szComponentID[255 + 1] = {0};
  419. TCHAR szSourcePath[_MAX_PATH + 1] = {0};
  420. TCHAR szUnattendFile[_MAX_PATH + 1] = {0};
  421. PRODUCT_SKU_TYPE InstalledProductSKU = PRODUCT_SKU_UNKNOWN;
  422. DWORD InstalledProductBuild = 0;
  423. DBG_ENTER(_T("fxState_DumpSetupState"));
  424. faxocm_GetComponentID(szComponentID,
  425. sizeof(szComponentID) / sizeof(TCHAR));
  426. faxocm_GetComponentSourcePath(szSourcePath,
  427. sizeof(szSourcePath) / sizeof(TCHAR));
  428. faxocm_GetComponentUnattendFile(szUnattendFile,
  429. sizeof(szUnattendFile) / sizeof(TCHAR));
  430. faxocm_GetVersionInfo(&dwExpectedOCManagerVersion,
  431. &dwCurrentOCManagerVersion);
  432. faxocm_GetProductInfo(&InstalledProductSKU,&InstalledProductBuild);
  433. VERBOSE(DBG_MSG,
  434. _T("IsCleanInstall: '%lu'"),
  435. fxState_IsCleanInstall());
  436. VERBOSE(DBG_MSG,
  437. _T("IsStandAlone: '%lu'"),
  438. fxState_IsStandAlone());
  439. VERBOSE(DBG_MSG,
  440. _T("IsUpgrade (0 = No, 1 = Win31, 2 = Win9X, 3 = Win2K, 4 = XP/.NET, 5=Repair: '%lu'"),
  441. fxState_IsUpgrade());
  442. if ((fxState_IsUpgrade()==FXSTATE_UPGRADE_TYPE_XP_DOT_NET) ||
  443. (fxState_IsUpgrade()==FXSTATE_UPGRADE_TYPE_REPAIR))
  444. {
  445. VERBOSE(DBG_MSG,
  446. _T("Upgrading from Fax build %d"),
  447. InstalledProductBuild);
  448. VERBOSE(DBG_MSG,
  449. _T("Upgrading from OS SKU %s"),
  450. StringFromSKU(InstalledProductSKU));
  451. }
  452. VERBOSE(DBG_MSG,
  453. _T("IsUnattended: '%lu'"),
  454. fxState_IsUnattended());
  455. VERBOSE(DBG_MSG, _T("ComponentID: '%s'"), szComponentID);
  456. VERBOSE(DBG_MSG, _T("Source Path: '%s'"), szSourcePath);
  457. VERBOSE(DBG_MSG, _T("Unattend File: '%s'"), szUnattendFile);
  458. VERBOSE(DBG_MSG,
  459. _T("Expected OC Manager Version: 0x%lx"),
  460. dwExpectedOCManagerVersion);
  461. VERBOSE(DBG_MSG,
  462. _T("Current OC Manager Version: 0x%lx"),
  463. dwCurrentOCManagerVersion);
  464. return;
  465. }