Source code of Windows XP (NT5)
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.

1087 lines
24 KiB

  1. /*
  2. * Copyright (c) 1998 Microsoft Corporation
  3. *
  4. * Module Name:
  5. *
  6. * licenoc.cpp
  7. *
  8. * Abstract:
  9. *
  10. * This file contains the main OC code.
  11. *
  12. * Author:
  13. *
  14. * Breen Hagan (BreenH) Oct-02-98
  15. *
  16. * Environment:
  17. *
  18. * User Mode
  19. */
  20. #include "stdafx.h"
  21. #include "pages.h"
  22. #include "..\common\svcrole.h"
  23. #include "upgdef.h"
  24. #include "logfile.h"
  25. /*
  26. * Constants.
  27. */
  28. const TCHAR gszLogFile[] = _T("%SystemRoot%\\LicenOc.log");
  29. const TCHAR *gInstallSectionNames[] = {
  30. _T("LicenseServer.Install"),
  31. _T("LicenseServer.Uninstall"),
  32. _T("LicenseServer.DoNothing")
  33. };
  34. /*
  35. * Global variables.
  36. */
  37. BOOL gNt4Upgrade = FALSE;
  38. BOOL gNtUpgrade;
  39. BOOL gStandAlone;
  40. BOOL gUnAttended;
  41. EnablePage *gEnableDlg = NULL;
  42. EServerType gServerRole = eEnterpriseServer;
  43. HINSTANCE ghInstance = NULL;
  44. PSETUP_INIT_COMPONENT gpInitComponentData = NULL;
  45. /*
  46. * Function prototypes.
  47. */
  48. HINF GetComponentInfHandle(VOID);
  49. DWORD GetComponentVersion(VOID);
  50. HINSTANCE GetInstance(VOID);
  51. EInstall GetInstallSection(VOID);
  52. LPCTSTR GetInstallSectionName(VOID);
  53. BOOL GetSelectionState(UINT);
  54. EServerType GetServerRole(VOID);
  55. DWORD OnPreinitialize(UINT_PTR);
  56. DWORD OnInitComponent(PSETUP_INIT_COMPONENT);
  57. DWORD OnSetLanguage(UINT_PTR);
  58. DWORD OnQueryImage(UINT_PTR, PDWORD);
  59. DWORD OnRequestPages(WizardPagesType, PSETUP_REQUEST_PAGES);
  60. DWORD OnWizardCreated(VOID);
  61. DWORD OnQueryState(UINT_PTR);
  62. DWORD OnQueryChangeSelState(UINT_PTR, UINT);
  63. DWORD OnCalcDiskSpace(LPCTSTR, UINT_PTR, HDSKSPC);
  64. DWORD OnQueueFileOps(LPCTSTR, HSPFILEQ);
  65. DWORD OnQueryStepCount(VOID);
  66. DWORD OnAboutToCommitQueue(VOID);
  67. DWORD OnCompleteInstallation(LPCTSTR);
  68. DWORD OnCleanup(VOID);
  69. VOID SetDatabaseDirectory(LPCTSTR);
  70. DWORD SetServerRole(UINT);
  71. #define GetCurrentSelectionState() GetSelectionState(OCSELSTATETYPE_CURRENT)
  72. #define GetOriginalSelectionState() GetSelectionState(OCSELSTATETYPE_ORIGINAL)
  73. /*
  74. * Helper Functions.
  75. */
  76. HINF
  77. GetComponentInfHandle(
  78. VOID
  79. )
  80. {
  81. return(gpInitComponentData->ComponentInfHandle);
  82. }
  83. DWORD
  84. GetComponentVersion(
  85. VOID
  86. )
  87. {
  88. return(OCMANAGER_VERSION);
  89. }
  90. HINSTANCE
  91. GetInstance(
  92. VOID
  93. )
  94. {
  95. return(ghInstance);
  96. }
  97. EInstall
  98. GetInstallSection(
  99. VOID
  100. )
  101. {
  102. BOOL fCurrentState = GetCurrentSelectionState();
  103. BOOL fOriginalState = GetOriginalSelectionState();
  104. //
  105. // StandAlone Setup Matrix
  106. //
  107. // Originally Selected, Currently Selected -> DoNothing
  108. // Originally Selected, Currently Unselected -> Uninstall
  109. // Originally Unselected, Currently Selected -> Install
  110. // Originally Unselected, Currently Unselected -> DoNothing
  111. //
  112. // Gui Mode / Upgrade Matrix
  113. //
  114. // Nt 4.0 any setup, Nt 5.0 w LS -> Install
  115. // Nt 4.0 any setup, Nt 5.0 w/o LS -> Uninstall
  116. // Nt 5.0 w/ LS, Nt 5.0 w/ LS -> Install
  117. // Nt 5.0 w/ LS, Nt 5.0 w/o LS -> Uninstall
  118. // Nt 5.0 w/o LS, Nt 5.0 w/ LS -> Install
  119. // Nt 5.0 w/o LS, Nt 5.0 w/o LS -> Uninstall
  120. // Win9x, Nt5.0 w/ LS -> Install
  121. // Win9x, Nt5.0 w/o LS -> Uninstall
  122. //
  123. //
  124. // If this is a TS 4 installation, fOriginalState will be false,
  125. // even though LS is installed. Handle this case first.
  126. //
  127. if (gNt4Upgrade) {
  128. if (fCurrentState) {
  129. return(kInstall);
  130. } else {
  131. return(kUninstall);
  132. }
  133. }
  134. if (gStandAlone && (fCurrentState == fOriginalState)) {
  135. return(kDoNothing);
  136. }
  137. if (fCurrentState) {
  138. return(kInstall);
  139. } else {
  140. return(kUninstall);
  141. }
  142. }
  143. LPCTSTR
  144. GetInstallSectionName(
  145. VOID
  146. )
  147. {
  148. LOGMESSAGE(
  149. _T("GetInstallSectionName: Returned %s"),
  150. gInstallSectionNames[(INT)GetInstallSection()]
  151. );
  152. return(gInstallSectionNames[(INT)GetInstallSection()]);
  153. }
  154. BOOL
  155. GetSelectionState(
  156. UINT StateType
  157. )
  158. {
  159. return(gpInitComponentData->HelperRoutines.QuerySelectionState(
  160. gpInitComponentData->HelperRoutines.OcManagerContext,
  161. COMPONENT_NAME,
  162. StateType
  163. ));
  164. }
  165. EServerType
  166. GetServerRole(
  167. VOID
  168. )
  169. {
  170. return(gServerRole);
  171. }
  172. BOOL
  173. InWin2000Domain(
  174. VOID
  175. )
  176. {
  177. NET_API_STATUS dwErr;
  178. DSROLE_PRIMARY_DOMAIN_INFO_BASIC *pDomainInfo = NULL;
  179. PDOMAIN_CONTROLLER_INFO pdcInfo = NULL;
  180. BOOL fRet = FALSE;
  181. //
  182. // Check if we're in a workgroup
  183. //
  184. dwErr = DsRoleGetPrimaryDomainInformation(NULL,
  185. DsRolePrimaryDomainInfoBasic,
  186. (PBYTE *) &pDomainInfo);
  187. if ((dwErr != NO_ERROR) || (pDomainInfo == NULL))
  188. {
  189. return FALSE;
  190. }
  191. switch (pDomainInfo->MachineRole)
  192. {
  193. case DsRole_RoleStandaloneWorkstation:
  194. case DsRole_RoleStandaloneServer:
  195. DsRoleFreeMemory(pDomainInfo);
  196. return FALSE;
  197. break; // just in case
  198. }
  199. DsRoleFreeMemory(pDomainInfo);
  200. dwErr = DsGetDcName(NULL, // Computer Name
  201. NULL, // Domain Name
  202. NULL, // Domain GUID
  203. NULL, // Site Name
  204. DS_DIRECTORY_SERVICE_PREFERRED,
  205. &pdcInfo);
  206. if ((dwErr != NO_ERROR) || (pdcInfo == NULL))
  207. {
  208. return FALSE;
  209. }
  210. if (pdcInfo->Flags & DS_DS_FLAG)
  211. {
  212. fRet = TRUE;
  213. }
  214. NetApiBufferFree(pdcInfo);
  215. return fRet;
  216. }
  217. DWORD
  218. SetServerRole(
  219. IN UINT newType
  220. )
  221. {
  222. switch(newType) {
  223. case ePlainServer:
  224. case eEnterpriseServer:
  225. gServerRole = (EServerType)newType;
  226. break;
  227. default:
  228. return(ERROR_INVALID_PARAMETER);
  229. }
  230. return(NO_ERROR);
  231. }
  232. /*
  233. * DllMain
  234. *
  235. * Initial entry point into the License Server OC dll.
  236. */
  237. DWORD WINAPI
  238. DllMain(
  239. IN HINSTANCE hInstance,
  240. IN DWORD dwReason,
  241. IN LPVOID lpReserved
  242. )
  243. {
  244. TCHAR pszLogFile[MAX_PATH + 1];
  245. switch(dwReason) {
  246. case DLL_PROCESS_ATTACH:
  247. if (hInstance != NULL) {
  248. ghInstance = hInstance;
  249. } else {
  250. return(FALSE);
  251. }
  252. ExpandEnvironmentStrings(gszLogFile, pszLogFile, MAX_PATH);
  253. LOGINIT(pszLogFile, COMPONENT_NAME);
  254. break;
  255. case DLL_THREAD_ATTACH:
  256. break;
  257. case DLL_PROCESS_DETACH:
  258. break;
  259. case DLL_THREAD_DETACH:
  260. break;
  261. }
  262. UNREFERENCED_PARAMETER(lpReserved);
  263. return(TRUE);
  264. }
  265. /*
  266. * EntryProc()
  267. *
  268. * Entry point into OCBase class for OCManager.
  269. */
  270. DWORD
  271. EntryProc(
  272. IN LPCVOID ComponentId,
  273. IN LPCVOID SubcomponentId,
  274. IN UINT Function,
  275. IN UINT_PTR Param1,
  276. IN OUT PVOID Param2
  277. )
  278. {
  279. DWORD dwRet;
  280. switch(Function) {
  281. case OC_PREINITIALIZE:
  282. LOGMESSAGE(_T("\r\nOnPreinitialize: Entered"));
  283. dwRet = OnPreinitialize(
  284. Param1
  285. );
  286. LOGMESSAGE(_T("OnPreinitialize: Returned"));
  287. break;
  288. case OC_INIT_COMPONENT:
  289. LOGMESSAGE(_T("\r\nOnInitComponent: Entered"));
  290. dwRet = OnInitComponent(
  291. (PSETUP_INIT_COMPONENT)Param2
  292. );
  293. LOGMESSAGE(_T("OnInitComponent: Returned"));
  294. break;
  295. case OC_SET_LANGUAGE:
  296. LOGMESSAGE(_T("\r\nOnSetLanguage: Entered"));
  297. dwRet = OnSetLanguage(
  298. Param1
  299. );
  300. LOGMESSAGE(_T("OnSetLanguage: Returned"));
  301. break;
  302. case OC_QUERY_IMAGE:
  303. LOGMESSAGE(_T("\r\nOnQueryImage: Entered"));
  304. dwRet = OnQueryImage(
  305. Param1,
  306. (PDWORD)Param2
  307. );
  308. LOGMESSAGE(_T("OnQueryImage: Returned"));
  309. break;
  310. case OC_REQUEST_PAGES:
  311. LOGMESSAGE(_T("\r\nOnRequestPages: Entered"));
  312. dwRet = OnRequestPages(
  313. (WizardPagesType)Param1,
  314. (PSETUP_REQUEST_PAGES)Param2
  315. );
  316. LOGMESSAGE(_T("OnRequestPages: Returned"));
  317. break;
  318. case OC_WIZARD_CREATED:
  319. LOGMESSAGE(_T("\r\nOnWizardCreated: Entered"));
  320. dwRet = OnWizardCreated();
  321. LOGMESSAGE(_T("OnWizardCreated: Returned"));
  322. break;
  323. case OC_QUERY_STATE:
  324. LOGMESSAGE(_T("\r\nOnQueryState: Entered"));
  325. dwRet = OnQueryState(
  326. Param1
  327. );
  328. LOGMESSAGE(_T("OnQueryState: Returned"));
  329. break;
  330. case OC_QUERY_CHANGE_SEL_STATE:
  331. LOGMESSAGE(_T("\r\nOnQueryChangeSelState: Entered"));
  332. dwRet = OnQueryChangeSelState(
  333. Param1,
  334. (UINT)((UINT_PTR)Param2)
  335. );
  336. LOGMESSAGE(_T("OnQueryChangeSelState: Returned"));
  337. break;
  338. case OC_CALC_DISK_SPACE:
  339. LOGMESSAGE(_T("\r\nOnCalcDiskSpace: Entered"));
  340. dwRet = OnCalcDiskSpace(
  341. (LPCTSTR)SubcomponentId,
  342. Param1,
  343. (HDSKSPC)Param2
  344. );
  345. LOGMESSAGE(_T("OnCalcDiskSpace: Returned"));
  346. break;
  347. case OC_QUEUE_FILE_OPS:
  348. LOGMESSAGE(_T("\r\nOnQueueFileOps: Entered"));
  349. dwRet = OnQueueFileOps(
  350. (LPCTSTR)SubcomponentId,
  351. (HSPFILEQ)Param2
  352. );
  353. LOGMESSAGE(_T("OnQueueFileOps: Returned"));
  354. break;
  355. case OC_QUERY_STEP_COUNT:
  356. LOGMESSAGE(_T("\r\nOnQueryStepCount: Entered"));
  357. dwRet = OnQueryStepCount();
  358. LOGMESSAGE(_T("OnQueryStepCount: Returned"));
  359. break;
  360. case OC_ABOUT_TO_COMMIT_QUEUE:
  361. LOGMESSAGE(_T("\r\nOnAboutToCommitQueue: Entered"));
  362. dwRet = OnAboutToCommitQueue();
  363. LOGMESSAGE(_T("OnAboutToCommitQueue: Returned"));
  364. break;
  365. case OC_COMPLETE_INSTALLATION:
  366. LOGMESSAGE(_T("\r\nOnCompleteInstallation: Entered"));
  367. dwRet = OnCompleteInstallation(
  368. (LPCTSTR)SubcomponentId
  369. );
  370. LOGMESSAGE(_T("OnCompleteInstallation: Returned"));
  371. break;
  372. case OC_CLEANUP:
  373. LOGMESSAGE(_T("\r\nOnCleanup: Entered"));
  374. dwRet = OnCleanup();
  375. break;
  376. default:
  377. LOGMESSAGE(_T("\r\nOC Manager calling for unknown function %ld\r\n"),
  378. Function);
  379. dwRet = 0;
  380. }
  381. UNREFERENCED_PARAMETER(ComponentId);
  382. return(dwRet);
  383. }
  384. /*
  385. * OnPreinitialize()
  386. *
  387. *
  388. */
  389. DWORD
  390. OnPreinitialize(
  391. IN UINT_PTR Flags
  392. )
  393. {
  394. UNREFERENCED_PARAMETER(Flags);
  395. #ifdef UNICODE
  396. return(OCFLAG_UNICODE);
  397. #else
  398. return(OCFLAG_ANSI);
  399. #endif
  400. }
  401. /*
  402. * OnInitComponent()
  403. *
  404. *
  405. */
  406. DWORD
  407. OnInitComponent(
  408. IN PSETUP_INIT_COMPONENT pSetupInitComponent
  409. )
  410. {
  411. BOOL fErr;
  412. DWORDLONG OperationFlags;
  413. if (pSetupInitComponent == NULL) {
  414. LOGMESSAGE(_T("OnInitComponent: Passed NULL PSETUP_INIT_COMPONENT"));
  415. return(ERROR_CANCELLED);
  416. }
  417. //
  418. // Verify that the OC Manager and OC versions are compatible.
  419. //
  420. pSetupInitComponent->ComponentVersion = GetComponentVersion();
  421. if (pSetupInitComponent->ComponentVersion >
  422. pSetupInitComponent->OCManagerVersion) {
  423. LOGMESSAGE(_T("OnInitComponent: Version mismatch."));
  424. return(ERROR_CALL_NOT_IMPLEMENTED);
  425. }
  426. //
  427. // Copy setup data.
  428. //
  429. gpInitComponentData = (PSETUP_INIT_COMPONENT)LocalAlloc(
  430. LPTR,
  431. sizeof(SETUP_INIT_COMPONENT)
  432. );
  433. if (gpInitComponentData == NULL) {
  434. LOGMESSAGE(_T("OnInitComponent: Can't allocate gpInitComponentData."));
  435. return(ERROR_CANCELLED);
  436. }
  437. CopyMemory(
  438. gpInitComponentData,
  439. pSetupInitComponent,
  440. sizeof(SETUP_INIT_COMPONENT)
  441. );
  442. //
  443. // Open Inf file.
  444. //
  445. if (GetComponentInfHandle() == NULL) {
  446. return(ERROR_CANCELLED);
  447. }
  448. fErr = SetupOpenAppendInfFile(
  449. NULL,
  450. GetComponentInfHandle(),
  451. NULL
  452. );
  453. if (!fErr) {
  454. LOGMESSAGE(_T("OnInitComponent: SetupOpenAppendInfFile failed: %ld"),
  455. GetLastError());
  456. return(GetLastError());
  457. }
  458. //
  459. // Set state variables.
  460. //
  461. OperationFlags = gpInitComponentData->SetupData.OperationFlags;
  462. gStandAlone = OperationFlags & SETUPOP_STANDALONE ? TRUE : FALSE;
  463. gUnAttended = OperationFlags & SETUPOP_BATCH ? TRUE : FALSE;
  464. gNtUpgrade = OperationFlags & SETUPOP_NTUPGRADE ? TRUE : FALSE;
  465. LOGMESSAGE(_T("OnInitComponent: gStandAlone = %s"),
  466. gStandAlone ? _T("TRUE") : _T("FALSE"));
  467. LOGMESSAGE(_T("OnInitComponent: gUnAttended = %s"),
  468. gUnAttended ? _T("TRUE") : _T("FALSE"));
  469. LOGMESSAGE(_T("OnInitComponent: gNtUpgrade = %s"),
  470. gNtUpgrade ? _T("TRUE") : _T("FALSE"));
  471. //
  472. // Gather previous version's information from registry. If the role
  473. // does not exist in the registry, SetServerRole will stay with the
  474. // default, PlainServer.
  475. //
  476. SetServerRole(GetServerRoleFromRegistry());
  477. //
  478. // Check for Nt4 Upgrade.
  479. //
  480. if (GetNT4DbConfig(NULL, NULL, NULL, NULL) == NO_ERROR) {
  481. LOGMESSAGE(_T("OnInitComponent: Nt4Upgrade"));
  482. gNt4Upgrade = TRUE;
  483. DeleteNT4ODBCDataSource();
  484. }
  485. //
  486. // License Server will only use the directory in the registry during
  487. // an Nt5 to Nt5 upgrade or stand alone setup from Add/Remove Programs.
  488. //
  489. if (gStandAlone || (gNtUpgrade && !gNt4Upgrade)) {
  490. LPCTSTR pszDbDirFromReg = GetDatabaseDirectoryFromRegistry();
  491. if (pszDbDirFromReg != NULL) {
  492. SetDatabaseDirectory(pszDbDirFromReg);
  493. }
  494. }
  495. return(NO_ERROR);
  496. }
  497. /*
  498. * OnSetLanguage()
  499. *
  500. *
  501. */
  502. DWORD
  503. OnSetLanguage(
  504. IN UINT_PTR LanguageId
  505. )
  506. {
  507. UNREFERENCED_PARAMETER(LanguageId);
  508. return((DWORD)FALSE);
  509. }
  510. /*
  511. * OnQueryImage()
  512. *
  513. *
  514. */
  515. DWORD
  516. OnQueryImage(
  517. IN UINT_PTR SubCompEnum,
  518. IN OUT PDWORD Size
  519. )
  520. {
  521. UNREFERENCED_PARAMETER(SubCompEnum);
  522. UNREFERENCED_PARAMETER(Size);
  523. return((DWORD)NULL);
  524. }
  525. /*
  526. * OnRequestPages()
  527. *
  528. *
  529. */
  530. DWORD
  531. OnRequestPages(
  532. IN WizardPagesType PageTypeEnum,
  533. IN OUT PSETUP_REQUEST_PAGES pRequestPages
  534. )
  535. {
  536. const DWORD cUiPages = 1;
  537. BOOL fErr;
  538. LOGMESSAGE(_T("OnRequestPages: Page Type %d"), PageTypeEnum);
  539. if (pRequestPages == NULL) {
  540. LOGMESSAGE(_T("OnRequestPages: pRequestPages == NULL"));
  541. return(0);
  542. }
  543. if ((!gStandAlone) || (PageTypeEnum != WizPagesEarly)) {
  544. return(0);
  545. }
  546. if (pRequestPages->MaxPages >= cUiPages) {
  547. gEnableDlg = new EnablePage;
  548. if (gEnableDlg == NULL) {
  549. goto CleanUp1;
  550. }
  551. fErr = gEnableDlg->Initialize();
  552. if (!fErr) {
  553. goto CleanUp1;
  554. }
  555. pRequestPages->Pages[0] = CreatePropertySheetPage(
  556. (LPPROPSHEETPAGE)gEnableDlg
  557. );
  558. if (pRequestPages->Pages[0] == NULL) {
  559. LOGMESSAGE(_T("OnRequestPages: Failed CreatePropertySheetPage!"));
  560. goto CleanUp0;
  561. }
  562. }
  563. return(cUiPages);
  564. CleanUp0:
  565. delete gEnableDlg;
  566. CleanUp1:
  567. SetLastError(ERROR_OUTOFMEMORY);
  568. LOGMESSAGE(_T("OnRequestPages: Out of Memory!"));
  569. return((DWORD)-1);
  570. }
  571. /*
  572. * OnWizardCreated()
  573. *
  574. *
  575. */
  576. DWORD
  577. OnWizardCreated(
  578. VOID
  579. )
  580. {
  581. return(NO_ERROR);
  582. }
  583. /*
  584. * OnQueryState()
  585. *
  586. *
  587. */
  588. DWORD
  589. OnQueryState(
  590. IN UINT_PTR uState
  591. )
  592. {
  593. UNREFERENCED_PARAMETER(uState);
  594. return(SubcompUseOcManagerDefault);
  595. }
  596. /*
  597. * OnQueryChangeSelState()
  598. *
  599. *
  600. */
  601. DWORD
  602. OnQueryChangeSelState(
  603. IN UINT_PTR SelectionState,
  604. IN UINT Flags
  605. )
  606. {
  607. BOOL fDirectSelection;
  608. BOOL fRet;
  609. BOOL fSelect;
  610. UNREFERENCED_PARAMETER(Flags);
  611. if (Flags & OCQ_ACTUAL_SELECTION)
  612. {
  613. fDirectSelection = TRUE;
  614. }
  615. else
  616. {
  617. fDirectSelection = FALSE;
  618. }
  619. fRet = TRUE;
  620. fSelect = (SelectionState != 0);
  621. if (!fSelect && fDirectSelection && GetOriginalSelectionState())
  622. {
  623. DWORD dwStatus;
  624. HWND hWnd;
  625. int iRet;
  626. hWnd = gpInitComponentData->HelperRoutines.QueryWizardDialogHandle(gpInitComponentData->HelperRoutines.OcManagerContext);
  627. dwStatus = DisplayMessageBox(
  628. hWnd,
  629. IDS_STRING_LICENSES_GO_BYE_BYE,
  630. IDS_MAIN_TITLE,
  631. MB_YESNO,
  632. &iRet
  633. );
  634. if (dwStatus == ERROR_SUCCESS)
  635. {
  636. fRet = (iRet == IDYES);
  637. }
  638. }
  639. return((DWORD)fRet);
  640. }
  641. /*
  642. * OnCalcDiskSpace()
  643. *
  644. *
  645. */
  646. DWORD
  647. OnCalcDiskSpace(
  648. IN LPCTSTR SubcomponentId,
  649. IN UINT_PTR AddComponent,
  650. IN OUT HDSKSPC DiskSpaceHdr
  651. )
  652. {
  653. BOOL fErr;
  654. LPCTSTR pSection;
  655. if ((SubcomponentId == NULL) ||
  656. (SubcomponentId[0] == NULL)) {
  657. return(0);
  658. }
  659. LOGMESSAGE(_T("OnCalcDiskSpace: %s"),
  660. AddComponent ? _T("Installing") : _T("Removing"));
  661. //
  662. // There is no clear documentation on how this should work. If the
  663. // size of the installation should be visible no matter what, then
  664. // the section to install should be hardcoded, not determined by
  665. // the current state.
  666. //
  667. pSection = gInstallSectionNames[kInstall];
  668. LOGMESSAGE(_T("OnCalcDiskSpace: Calculating for %s"), pSection);
  669. if (AddComponent != 0) {
  670. fErr = SetupAddInstallSectionToDiskSpaceList(
  671. DiskSpaceHdr,
  672. GetComponentInfHandle(),
  673. NULL,
  674. pSection,
  675. NULL,
  676. 0
  677. );
  678. } else {
  679. fErr = SetupRemoveInstallSectionFromDiskSpaceList(
  680. DiskSpaceHdr,
  681. GetComponentInfHandle(),
  682. NULL,
  683. pSection,
  684. NULL,
  685. 0
  686. );
  687. }
  688. if (fErr) {
  689. return(NO_ERROR);
  690. } else {
  691. LOGMESSAGE(_T("OnCalcDiskSpace: Error %ld"), GetLastError());
  692. return(GetLastError());
  693. }
  694. }
  695. /*
  696. * OnQueueFileOps()
  697. *
  698. *
  699. */
  700. DWORD
  701. OnQueueFileOps(
  702. IN LPCTSTR SubcomponentId,
  703. IN OUT HSPFILEQ FileQueueHdr
  704. )
  705. {
  706. BOOL fErr;
  707. DWORD dwErr;
  708. EInstall eInstallSection;
  709. LPCTSTR pSection;
  710. if ((SubcomponentId == NULL) ||
  711. (SubcomponentId[0] == NULL)) {
  712. return(0);
  713. }
  714. pSection = GetInstallSectionName();
  715. LOGMESSAGE(_T("OnQueueFileOps: Queueing %s"), pSection);
  716. //
  717. // Stop and remove the license server service, if needed. This must
  718. // be done before queueing files for deletion.
  719. //
  720. eInstallSection = GetInstallSection();
  721. if (eInstallSection == kUninstall) {
  722. if (gServerRole == eEnterpriseServer) {
  723. if (UnpublishEnterpriseServer() != S_OK) {
  724. LOGMESSAGE(
  725. _T("OnQueueFileOps: UnpublishEnterpriseServer() failed")
  726. );
  727. }
  728. }
  729. dwErr = ServiceDeleteFromInfSection(
  730. GetComponentInfHandle(),
  731. pSection
  732. );
  733. if (dwErr != ERROR_SUCCESS) {
  734. LOGMESSAGE(
  735. _T("OnQueueFileOps: Error deleting service: %ld"),
  736. dwErr
  737. );
  738. }
  739. }
  740. fErr = SetupInstallFilesFromInfSection(
  741. GetComponentInfHandle(),
  742. NULL,
  743. FileQueueHdr,
  744. pSection,
  745. NULL,
  746. eInstallSection == kUninstall ? 0 : SP_COPY_NEWER
  747. );
  748. if (fErr) {
  749. return(NO_ERROR);
  750. } else {
  751. LOGMESSAGE(_T("OnQueueFileOps: Error %ld"), GetLastError());
  752. return(GetLastError());
  753. }
  754. }
  755. /*
  756. * OnQueryStepCount()
  757. *
  758. * TODO: how many steps, when should we tick?
  759. */
  760. DWORD
  761. OnQueryStepCount(
  762. VOID
  763. )
  764. {
  765. return(0);
  766. }
  767. /*
  768. * OnAboutToCommitQueue()
  769. *
  770. *
  771. */
  772. DWORD
  773. OnAboutToCommitQueue(
  774. VOID
  775. )
  776. {
  777. return(NO_ERROR);
  778. }
  779. /*
  780. * OnCompleteInstallation()
  781. *
  782. *
  783. */
  784. DWORD
  785. OnCompleteInstallation(
  786. IN LPCTSTR SubcomponentId
  787. )
  788. {
  789. BOOL fErr;
  790. DWORD dwErr;
  791. EInstall eInstallSection = GetInstallSection();
  792. LPCTSTR pSection;
  793. TCHAR tchBuf[MESSAGE_SIZE] ={0};
  794. TCHAR tchTitle[TITLE_SIZE] = {0};
  795. if ((SubcomponentId == NULL) ||
  796. (SubcomponentId[0] == NULL)) {
  797. return(NO_ERROR);
  798. }
  799. if (eInstallSection == kDoNothing) {
  800. LOGMESSAGE(_T("OnCompleteInstallation: Nothing to do"));
  801. return(NO_ERROR);
  802. }
  803. pSection = GetInstallSectionName();
  804. //
  805. // In GUI mode setup and in unattended StandAlone setup, the wizard
  806. // page does not display, and therefore the directory is not created.
  807. // Create the default directory here.
  808. //
  809. if (eInstallSection == kInstall) {
  810. if ((!gStandAlone) || (gUnAttended)) {
  811. CreateDatabaseDirectory();
  812. }
  813. }
  814. //
  815. // SetupAPI correctly handles installing and removing files, and
  816. // creating start menu links.
  817. //
  818. fErr = SetupInstallFromInfSection(
  819. NULL,
  820. GetComponentInfHandle(),
  821. pSection,
  822. SPINST_INIFILES | SPINST_REGISTRY | SPINST_PROFILEITEMS,
  823. NULL,
  824. NULL,
  825. 0,
  826. NULL,
  827. NULL,
  828. NULL,
  829. NULL
  830. );
  831. if (!fErr) {
  832. LOGMESSAGE(_T("OnCompleteInstallation: InstallFromInf failed %ld"),
  833. GetLastError());
  834. return(GetLastError());
  835. }
  836. //
  837. // Perform installation and upgrade-specific tasks.
  838. //
  839. if (eInstallSection == kInstall) {
  840. LOGMESSAGE(_T("OnCompleteInstallation: Installing"));
  841. //
  842. // Set service settings first and install the service.
  843. //
  844. dwErr = CreateRegistrySettings(GetDatabaseDirectory(), gServerRole);
  845. if (dwErr != NO_ERROR) {
  846. LOGMESSAGE(
  847. _T("OnCompleteInstallation: CreateRegistrySettings: Error %ld"),
  848. dwErr
  849. );
  850. return(dwErr);
  851. }
  852. fErr = SetupInstallServicesFromInfSection(
  853. GetComponentInfHandle(),
  854. pSection,
  855. 0
  856. );
  857. if (!fErr) {
  858. LOGMESSAGE(
  859. _T("OnCompleteInstallation: InstallServices: Error %ld"),
  860. GetLastError()
  861. );
  862. return(GetLastError());
  863. }
  864. if (gServerRole == eEnterpriseServer) {
  865. if (PublishEnterpriseServer() != S_OK) {
  866. LOGMESSAGE(_T("OnCompleteInstallation: PublishEnterpriseServer() failed. Setup will still complete."));
  867. LOGMESSAGE(_T("PublishEnterpriseServer: Uninstall, try logging on as a member of the Enterprise Admins or Domain Admins group and then run setup again."));
  868. if (!gUnAttended)
  869. {
  870. LoadString( GetInstance(), IDS_INSUFFICIENT_PERMISSION, tchBuf, sizeof(tchBuf)/sizeof(TCHAR));
  871. LoadString( GetInstance(), IDS_MAIN_TITLE, tchTitle, sizeof(tchTitle)/sizeof(TCHAR));
  872. MessageBox( NULL, tchBuf, tchTitle, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
  873. }
  874. }
  875. }
  876. if (gStandAlone) {
  877. dwErr = ServiceStartFromInfSection(
  878. GetComponentInfHandle(),
  879. pSection
  880. );
  881. if (dwErr != ERROR_SUCCESS) {
  882. LOGMESSAGE(
  883. _T("OnCompleteInstallation: Error starting service: %ld"),
  884. dwErr
  885. );
  886. return(dwErr);
  887. }
  888. }
  889. } else if (eInstallSection == kUninstall) {
  890. CleanLicenseServerSecret();
  891. RemoveDatabaseDirectory();
  892. RemoveRegistrySettings();
  893. }
  894. return(NO_ERROR);
  895. }
  896. /*
  897. * OnCleanup()
  898. *
  899. *
  900. */
  901. DWORD
  902. OnCleanup(
  903. VOID
  904. )
  905. {
  906. if (gpInitComponentData != NULL) {
  907. LocalFree(gpInitComponentData);
  908. }
  909. if (gEnableDlg != NULL) {
  910. delete gEnableDlg;
  911. }
  912. LOGMESSAGE(_T("OnCleanup: Returned"));
  913. LOGCLOSE();
  914. return(NO_ERROR);
  915. }