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.

731 lines
22 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. WzUnmang.cpp
  5. Abstract:
  6. Wizard for Unmanaging media - Copy Set Wizard.
  7. Author:
  8. Rohde Wakefield [rohde] 26-09-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "ManVol.h"
  13. #include "WzUnmang.h"
  14. #include "valwait.h"
  15. #include "objidl.h"
  16. // Thread function for running Validate job
  17. static DWORD RunValidateJob(void* pVoid);
  18. typedef struct {
  19. DWORD dwResourceCookie;
  20. DWORD dwHsmServerCookie;
  21. } RUN_VALIDATE_PARAM;
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CUnmanageWizard
  24. CUnmanageWizard::CUnmanageWizard( )
  25. {
  26. WsbTraceIn( L"CUnmanageWizard::CUnmanageWizard", L"" );
  27. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  28. HRESULT hr = S_OK;
  29. //
  30. // Get interfaces to needed objects
  31. //
  32. try {
  33. m_TitleId = IDS_WIZ_UNMANAGE_TITLE;
  34. m_HeaderId = IDB_UNMANAGE_HEADER;
  35. m_WatermarkId = IDB_UNMANAGE_WATERMARK;
  36. } WsbCatch( hr );
  37. WsbTraceOut( L"CUnmanageWizard::CUnmanageWizard", L"" );
  38. }
  39. STDMETHODIMP
  40. CUnmanageWizard::AddWizardPages(
  41. IN RS_PCREATE_HANDLE Handle,
  42. IN IUnknown* pCallback,
  43. IN ISakSnapAsk* pSakSnapAsk
  44. )
  45. {
  46. WsbTraceIn( L"CUnmanageWizard::AddWizardPages", L"" );
  47. HRESULT hr = S_OK;
  48. try {
  49. //
  50. // Initialize the Sheet
  51. //
  52. WsbAffirmHr( InitSheet( Handle, pCallback, 0, pSakSnapAsk, 0, 0 ) );
  53. //
  54. // Load pages
  55. //
  56. WsbAffirmHr( AddPage( &m_IntroPage ) );
  57. WsbAffirmHr( AddPage( &m_SelectPage ) );
  58. WsbAffirmHr( AddPage( &m_FinishPage ) );
  59. } WsbCatch( hr );
  60. WsbTraceOut( L"CUnmanageWizard::AddWizardPages", L"" );
  61. return( hr );
  62. }
  63. CUnmanageWizard::~CUnmanageWizard()
  64. {
  65. WsbTraceIn( L"CUnmanageWizard::~CUnmanageWizard", L"" );
  66. WsbTraceOut( L"CUnmanageWizard::~CUnmanageWizard", L"" );
  67. }
  68. void
  69. CUnmanageWizard::DoThreadSetup(
  70. )
  71. {
  72. WsbTraceIn( L"CUnmanageWizard::DoThreadSetup", L"" );
  73. HRESULT hr = S_OK;
  74. try {
  75. //
  76. // Get the HSM and FSA objects for resource
  77. //
  78. CComPtr<IUnknown> pUnkHsmResource;
  79. WsbAffirmHr( GetHsmObj( &pUnkHsmResource ) );
  80. WsbAffirmHr( pUnkHsmResource.QueryInterface( &m_pHsmResource) );
  81. CComPtr<IUnknown> pUnkFsaResource;
  82. WsbAffirmHr( m_pHsmResource->GetFsaResource( &pUnkFsaResource ) );
  83. WsbAffirmHr( pUnkFsaResource.QueryInterface( &m_pFsaResource ) );
  84. //
  85. // Grab the name of resource
  86. //
  87. WsbAffirmHr( RsGetVolumeDisplayName( m_pFsaResource, m_DisplayName ) );
  88. } WsbCatch( hr );
  89. WsbTraceOut( L"CUnmanageWizard::DoThreadSetup", L"hr = <%ls>", WsbHrAsString( hr ) );
  90. }
  91. HRESULT CUnmanageWizard::OnFinish( )
  92. {
  93. WsbTraceIn( L"CUnmanageWizard::OnFinish", L"" );
  94. //
  95. // The sheet really owns the process as a whole,
  96. // so it will do the final assembly
  97. //
  98. HRESULT hr = S_OK;
  99. try {
  100. CComPtr<IHsmServer> pHsmServer;
  101. WsbAffirmHrOk( GetHsmServer( &pHsmServer ) );
  102. int selected = m_SelectPage.GetCheckedRadioButton( IDC_NOMANAGE, IDC_FULL );
  103. switch( selected ) {
  104. case IDC_NOMANAGE:
  105. //
  106. // Get the Engine's managed resource collection
  107. //
  108. {
  109. CComPtr<IWsbIndexedCollection> pCollection;
  110. WsbAffirmHr( pHsmServer->GetManagedResources( &pCollection ) );
  111. WsbAffirmHr( pCollection->RemoveAndRelease( m_pHsmResource ) );
  112. WsbAffirmHr( pHsmServer->SavePersistData( ) );
  113. CComPtr<IFsaServer> pFsaServer;
  114. WsbAffirmHr( GetFsaServer( &pFsaServer ) );
  115. WsbAffirmHr( RsServerSaveAll( pFsaServer ) );
  116. }
  117. break;
  118. case IDC_FULL:
  119. WsbAffirmHr( RsCreateAndRunFsaJob( HSM_JOB_DEF_TYPE_FULL_UNMANAGE, pHsmServer, m_pFsaResource, FALSE ) );
  120. break;
  121. }
  122. } WsbCatch( hr );
  123. m_HrFinish = hr;
  124. WsbTraceOut( L"CUnmanageWizard::OnFinish", L"hr = <%ls>", WsbHrAsString( hr ) );
  125. return( hr );
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CUnmanageWizardIntro property page
  129. CUnmanageWizardIntro::CUnmanageWizardIntro()
  130. : CSakWizardPage_InitBaseExt( WIZ_UNMANAGE_INTRO )
  131. {
  132. WsbTraceIn( L"CUnmanageWizardIntro::CUnmanageWizardIntro", L"" );
  133. //{{AFX_DATA_INIT(CUnmanageWizardIntro)
  134. // NOTE: the ClassWizard will add member initialization here
  135. //}}AFX_DATA_INIT
  136. WsbTraceOut( L"CUnmanageWizardIntro::CUnmanageWizardIntro", L"" );
  137. }
  138. CUnmanageWizardIntro::~CUnmanageWizardIntro()
  139. {
  140. WsbTraceIn( L"CUnmanageWizardIntro::~CUnmanageWizardIntro", L"" );
  141. WsbTraceOut( L"CUnmanageWizardIntro::~CUnmanageWizardIntro", L"" );
  142. }
  143. void CUnmanageWizardIntro::DoDataExchange(CDataExchange* pDX)
  144. {
  145. WsbTraceIn( L"CUnmanageWizardIntro::DoDataExchange", L"" );
  146. CSakWizardPage::DoDataExchange(pDX );
  147. //{{AFX_DATA_MAP(CUnmanageWizardIntro)
  148. // NOTE: the ClassWizard will add DDX and DDV calls here
  149. //}}AFX_DATA_MAP
  150. WsbTraceOut( L"CUnmanageWizardIntro::DoDataExchange", L"" );
  151. }
  152. BEGIN_MESSAGE_MAP(CUnmanageWizardIntro, CSakWizardPage)
  153. //{{AFX_MSG_MAP(CUnmanageWizardIntro)
  154. //}}AFX_MSG_MAP
  155. END_MESSAGE_MAP()
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CUnmanageWizardIntro message handlers
  158. BOOL CUnmanageWizardIntro::OnInitDialog( )
  159. {
  160. WsbTraceIn( L"CUnmanageWizardIntro::OnInitDialog", L"" );
  161. CSakWizardPage::OnInitDialog( );
  162. //
  163. // Really, first chance that we know we're in the new thread
  164. // Get sheet to initialize as needed
  165. //
  166. CUnmanageWizard* pSheet = (CUnmanageWizard*) m_pSheet;
  167. pSheet->DoThreadSetup( );
  168. WsbTraceOut( L"CUnmanageWizardIntro::OnInitDialog", L"" );
  169. return( TRUE );
  170. }
  171. BOOL CUnmanageWizardIntro::OnSetActive( )
  172. {
  173. WsbTraceIn( L"CUnmanageWizardIntro::OnSetActive", L"" );
  174. m_pSheet->SetWizardButtons( PSWIZB_NEXT );
  175. BOOL retval = CSakWizardPage::OnSetActive( );
  176. WsbTraceOut( L"CUnmanageWizardIntro::OnSetActive", L"" );
  177. return( retval );
  178. }
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CUnmanageWizardSelect property page
  181. CUnmanageWizardSelect::CUnmanageWizardSelect()
  182. : CSakWizardPage_InitBaseInt( WIZ_UNMANAGE_SELECT )
  183. {
  184. WsbTraceIn( L"CUnmanageWizardSelect::CUnmanageWizardSelect", L"" );
  185. //{{AFX_DATA_INIT(CUnmanageWizardSelect)
  186. // NOTE: the ClassWizard will add member initialization here
  187. //}}AFX_DATA_INIT
  188. WsbTraceOut( L"CUnmanageWizardSelect::CUnmanageWizardSelect", L"" );
  189. }
  190. CUnmanageWizardSelect::~CUnmanageWizardSelect()
  191. {
  192. WsbTraceIn( L"CUnmanageWizardSelect::~CUnmanageWizardSelect", L"" );
  193. WsbTraceOut( L"CUnmanageWizardSelect::~CUnmanageWizardSelect", L"" );
  194. }
  195. void CUnmanageWizardSelect::DoDataExchange(CDataExchange* pDX)
  196. {
  197. WsbTraceIn( L"CUnmanageWizardSelect::DoDataExchange", L"" );
  198. CSakWizardPage::DoDataExchange(pDX );
  199. //{{AFX_DATA_MAP(CUnmanageWizardSelect)
  200. //}}AFX_DATA_MAP
  201. WsbTraceOut( L"CUnmanageWizardSelect::DoDataExchange", L"" );
  202. }
  203. BEGIN_MESSAGE_MAP(CUnmanageWizardSelect, CSakWizardPage)
  204. //{{AFX_MSG_MAP(CUnmanageWizardSelect)
  205. ON_BN_CLICKED(IDC_BUTTON_REFRESH, OnButtonRefresh)
  206. //}}AFX_MSG_MAP
  207. END_MESSAGE_MAP()
  208. /////////////////////////////////////////////////////////////////////////////
  209. // CUnmanageWizardSelect message handlers
  210. BOOL CUnmanageWizardSelect::OnInitDialog( )
  211. {
  212. WsbTraceIn( L"CUnmanageWizardSelect::OnInitDialog", L"" );
  213. CSakWizardPage::OnInitDialog( );
  214. HRESULT hr = S_OK;
  215. try {
  216. m_hrAvailable = ((CUnmanageWizard*)m_pSheet)->m_pFsaResource->IsAvailable( );
  217. CheckRadioButton( IDC_NOMANAGE, IDC_FULL, IDC_FULL );
  218. } WsbCatch( hr );
  219. WsbTraceOut( L"CUnmanageWizardSelect::OnInitDialog", L"" );
  220. return TRUE;
  221. }
  222. BOOL CUnmanageWizardSelect::OnSetActive( )
  223. {
  224. WsbTraceIn( L"CUnmanageWizardSelect::OnSetActive", L"" );
  225. BOOL retval = CSakWizardPage::OnSetActive( );
  226. SetButtons( );
  227. WsbTraceOut( L"CUnmanageWizardSelect::OnSetActive", L"" );
  228. return( retval );
  229. }
  230. void CUnmanageWizardSelect::SetButtons()
  231. {
  232. WsbTraceIn( L"CUnmanageWizardSelect::SetButtons", L"" );
  233. HRESULT hr = S_OK;
  234. try {
  235. CUnmanageWizard * pSheet = (CUnmanageWizard*)m_pSheet;
  236. //
  237. // Check if volume is still around (could be formatted now).
  238. // If it is not available, then we don't want to let a job
  239. // be started against it, so set up radio buttons appropriately.
  240. //
  241. if( S_OK == m_hrAvailable ) {
  242. CString string;
  243. LONGLONG total, free, premigrated, truncated;
  244. WsbAffirmHr( pSheet->m_pFsaResource->GetSizes( &total, &free, &premigrated, &truncated ) );
  245. WsbAffirmHr( RsGuiFormatLongLong4Char( free, string ) );
  246. SetDlgItemText( IDC_UNMANAGE_FREE_SPACE, string );
  247. WsbAffirmHr( RsGuiFormatLongLong4Char( truncated, string ) );
  248. SetDlgItemText( IDC_UNMANAGE_TRUNCATE, string );
  249. //
  250. // See if there is enough room to bring everything back
  251. //
  252. BOOL disableRecall = free < truncated;
  253. if( disableRecall ) {
  254. switch( GetCheckedRadioButton( IDC_NOMANAGE, IDC_FULL ) ) {
  255. case IDC_FULL:
  256. CheckRadioButton( IDC_NOMANAGE, IDC_FULL, IDC_NOMANAGE );
  257. break;
  258. }
  259. // Show the Refresh button and related items on every selection
  260. GetDlgItem( IDC_BUTTON_REFRESH )->ShowWindow( SW_SHOW );
  261. GetDlgItem( IDC_REFRESH_DESCRIPTION )->ShowWindow( SW_SHOW );
  262. } else {
  263. // Hide the Refresh button and related items
  264. GetDlgItem( IDC_BUTTON_REFRESH )->ShowWindow( SW_HIDE );
  265. GetDlgItem( IDC_REFRESH_DESCRIPTION )->ShowWindow( SW_HIDE );
  266. }
  267. GetDlgItem( IDC_FULL )->EnableWindow( !disableRecall );
  268. GetDlgItem( IDC_UNMANAGE_FULL_DESCRIPTION )->EnableWindow( !disableRecall );
  269. } else {
  270. CheckRadioButton( IDC_NOMANAGE, IDC_FULL, IDC_NOMANAGE );
  271. GetDlgItem( IDC_FULL )->EnableWindow( FALSE );
  272. GetDlgItem( IDC_UNMANAGE_FULL_DESCRIPTION )->EnableWindow( FALSE );
  273. GetDlgItem( IDC_UNMANAGE_FREE_SPACE_LABEL )->ShowWindow( SW_HIDE );
  274. GetDlgItem( IDC_UNMANAGE_TRUNCATE_LABEL )->ShowWindow( SW_HIDE );
  275. // Hide the Refresh button and related items
  276. GetDlgItem( IDC_BUTTON_REFRESH )->ShowWindow( SW_HIDE );
  277. GetDlgItem( IDC_REFRESH_DESCRIPTION )->ShowWindow( SW_HIDE );
  278. }
  279. //
  280. // Enable the next / back buttons
  281. //
  282. m_pSheet->SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
  283. } WsbCatchAndDo( hr,
  284. m_pSheet->SetWizardButtons( PSWIZB_BACK );
  285. );
  286. WsbTraceOut( L"CUnmanageWizardSelect::SetButtons", L"" );
  287. }
  288. LRESULT CUnmanageWizardSelect::OnWizardNext()
  289. {
  290. WsbTraceIn( L"CUnmanageWizardSelect::SetDescription", L"" );
  291. LRESULT retval = -1;
  292. CUnmanageWizard * pSheet = (CUnmanageWizard*)m_pSheet;
  293. if( S_OK == m_hrAvailable ) {
  294. int boxReturn = IDNO;
  295. const UINT type = MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2;
  296. CString warning;
  297. switch( GetCheckedRadioButton( IDC_NOMANAGE, IDC_FULL ) ) {
  298. case IDC_NOMANAGE:
  299. AfxFormatString1( warning, IDS_WIZ_UNMANAGE_CONFIRM_NOMANAGE, pSheet->m_DisplayName );
  300. break;
  301. case IDC_FULL:
  302. AfxFormatString1( warning, IDS_WIZ_UNMANAGE_CONFIRM_FULL, pSheet->m_DisplayName );
  303. break;
  304. }
  305. boxReturn = AfxMessageBox( warning, type );
  306. if( boxReturn == IDYES ) {
  307. retval = CSakWizardPage::OnWizardNext();
  308. }
  309. } else {
  310. //
  311. // Assume the only action was to delete and the volume
  312. // doesn't exist, so this is OK.
  313. //
  314. retval = 0;
  315. }
  316. WsbTraceOut( L"CUnmanageWizardSelect::SetDescription", L"retval = <%ld>", retval );
  317. return( retval );
  318. }
  319. /////////////////////////////////////////////////////////////////////////////
  320. // CUnmanageWizardFinish property page
  321. CUnmanageWizardFinish::CUnmanageWizardFinish()
  322. : CSakWizardPage_InitBaseExt( WIZ_UNMANAGE_FINISH )
  323. {
  324. WsbTraceIn( L"CUnmanageWizardFinish::CUnmanageWizardFinish", L"" );
  325. //{{AFX_DATA_INIT(CUnmanageWizardFinish)
  326. // NOTE: the ClassWizard will add member initialization here
  327. //}}AFX_DATA_INIT
  328. WsbTraceOut( L"CUnmanageWizardFinish::CUnmanageWizardFinish", L"" );
  329. }
  330. CUnmanageWizardFinish::~CUnmanageWizardFinish()
  331. {
  332. WsbTraceIn( L"CUnmanageWizardFinish::~CUnmanageWizardFinish", L"" );
  333. WsbTraceOut( L"CUnmanageWizardFinish::~CUnmanageWizardFinish", L"" );
  334. }
  335. void CUnmanageWizardFinish::DoDataExchange(CDataExchange* pDX)
  336. {
  337. WsbTraceIn( L"CUnmanageWizardFinish::DoDataExchange", L"" );
  338. CSakWizardPage::DoDataExchange(pDX );
  339. //{{AFX_DATA_MAP(CUnmanageWizardFinish)
  340. // NOTE: the ClassWizard will add DDX and DDV calls here
  341. //}}AFX_DATA_MAP
  342. WsbTraceOut( L"CUnmanageWizardFinish::DoDataExchange", L"" );
  343. }
  344. BEGIN_MESSAGE_MAP(CUnmanageWizardFinish, CSakWizardPage)
  345. //{{AFX_MSG_MAP(CUnmanageWizardFinish)
  346. //}}AFX_MSG_MAP
  347. END_MESSAGE_MAP()
  348. /////////////////////////////////////////////////////////////////////////////
  349. // CUnmanageWizardFinish message handlers
  350. BOOL CUnmanageWizardFinish::OnInitDialog( )
  351. {
  352. WsbTraceIn( L"CUnmanageWizardFinish::OnInitDialog", L"" );
  353. CSakWizardPage::OnInitDialog( );
  354. HRESULT hr = S_OK;
  355. WsbTraceOut( L"CUnmanageWizardFinish::OnInitDialog", L"" );
  356. return TRUE;
  357. }
  358. BOOL CUnmanageWizardFinish::OnSetActive( )
  359. {
  360. WsbTraceIn( L"CUnmanageWizardFinish::OnSetActive", L"" );
  361. HRESULT hr = S_OK;
  362. BOOL fRet = CSakWizardPage::OnSetActive( );
  363. try {
  364. CUnmanageWizard * pSheet = (CUnmanageWizard*)m_pSheet;
  365. int selected = pSheet->m_SelectPage.GetCheckedRadioButton( IDC_NOMANAGE, IDC_FULL );
  366. CString actionString, jobName, taskString;
  367. BOOL entersTask = TRUE;
  368. switch( selected ) {
  369. case IDC_NOMANAGE:
  370. AfxFormatString1( actionString, IDS_WIZ_UNMANAGE_SEL_NOMANAGE, pSheet->m_DisplayName );
  371. entersTask = FALSE;
  372. taskString.LoadString( IDS_WIZ_UNMANAGE_NOMANAGE_TASK_TEXT );
  373. break;
  374. case IDC_FULL:
  375. AfxFormatString1( actionString, IDS_WIZ_UNMANAGE_SEL_FULL, pSheet->m_DisplayName );
  376. RsCreateJobName( HSM_JOB_DEF_TYPE_FULL_UNMANAGE, pSheet->m_pFsaResource, jobName );
  377. break;
  378. }
  379. CString selectString;
  380. AfxFormatString1( selectString, IDS_WIZ_UNMANAGE_SELECT, actionString );
  381. SetDlgItemText( IDC_SELECT_TEXT, selectString );
  382. if( entersTask ) {
  383. CWsbStringPtr computerName;
  384. CComPtr<IHsmServer> pHsmServer;
  385. WsbAffirmHrOk( pSheet->GetHsmServer( &pHsmServer ) );
  386. WsbAffirmHr( pHsmServer->GetName( &computerName ) );
  387. AfxFormatString2( taskString, IDS_WIZ_FINISH_RUN_JOB, jobName, computerName );
  388. }
  389. SetDlgItemText( IDC_TASK_TEXT, taskString );
  390. } WsbCatch( hr );
  391. m_pSheet->SetWizardButtons( PSWIZB_BACK | PSWIZB_FINISH );
  392. WsbTraceOut( L"CUnmanageWizardFinish::OnSetActive", L"" );
  393. return fRet;
  394. }
  395. void CUnmanageWizardSelect::OnButtonRefresh()
  396. {
  397. WsbTraceIn( L"CUnmanageWizardFinish::OnButtonRefresh", L"" );
  398. HRESULT hr = S_OK;
  399. CValWaitDlg* pWaitDlg = 0;
  400. HANDLE hJobThread[1] = { NULL };
  401. BOOL bRunning = TRUE;
  402. CComPtr<IGlobalInterfaceTable> pGIT;
  403. RUN_VALIDATE_PARAM* pThreadParam = NULL;
  404. BOOL bResCookieCreated = FALSE;
  405. BOOL bHsmCookieCreated = FALSE;
  406. CComPtr<IHsmServer> pHsmServer;
  407. try {
  408. CUnmanageWizard* pSheet = (CUnmanageWizard*)m_pSheet;
  409. WsbAffirmHrOk(pSheet->GetHsmServer(&pHsmServer));
  410. // Register interfaces so they can be used in other threads
  411. pThreadParam = new RUN_VALIDATE_PARAM;
  412. WsbAffirm(pThreadParam, E_OUTOFMEMORY);
  413. WsbAffirmHr(CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
  414. CLSCTX_INPROC_SERVER, IID_IGlobalInterfaceTable, (void **)&pGIT));
  415. WsbAffirmHr(pGIT->RegisterInterfaceInGlobal((IUnknown *)(IFsaResource *)(pSheet->m_pFsaResource),
  416. IID_IFsaResource, &(pThreadParam->dwResourceCookie)));
  417. bResCookieCreated = TRUE;
  418. WsbAffirmHr(pGIT->RegisterInterfaceInGlobal((IUnknown *)(IHsmServer *)pHsmServer,
  419. IID_IHsmServer, &(pThreadParam->dwHsmServerCookie)));
  420. bHsmCookieCreated = TRUE;
  421. // Create a thread that runs a Validate job
  422. hJobThread[0] = CreateThread(0, 0, RunValidateJob, (void *)pThreadParam, 0, 0);
  423. if (!hJobThread[0]) {
  424. WsbThrow(HRESULT_FROM_WIN32(GetLastError()));
  425. }
  426. // Open Validate Wait dialog
  427. pWaitDlg = new CValWaitDlg(pSheet, this);
  428. WsbAffirm(pWaitDlg, E_OUTOFMEMORY);
  429. if (! pWaitDlg->Create(CValWaitDlg::IDD, this)) {
  430. // Dialog creation failed
  431. WsbThrow(E_FAIL);
  432. }
  433. while (bRunning) {
  434. DWORD dwStatus;
  435. // Wait for that thread to finish, dispatch messages while it's working
  436. dwStatus = MsgWaitForMultipleObjects(1, hJobThread, FALSE, INFINITE, QS_ALLEVENTS);
  437. switch (dwStatus) {
  438. case WAIT_OBJECT_0: {
  439. // The thread ended get it's exit code
  440. DWORD dwExitCode;
  441. if (GetExitCodeThread(hJobThread[0], &dwExitCode)) {
  442. if (STILL_ACTIVE == dwExitCode) {
  443. // This shouldn't happen
  444. hr = E_FAIL;
  445. } else {
  446. // Thread return code
  447. hr = static_cast<HRESULT>(dwExitCode);
  448. }
  449. } else {
  450. hr = HRESULT_FROM_WIN32(GetLastError());
  451. }
  452. bRunning = FALSE;
  453. break;
  454. }
  455. case (WAIT_OBJECT_0 + 1): {
  456. // Message in the queue
  457. MSG msg;
  458. while (PeekMessage(&msg, pWaitDlg->m_hWnd, 0, 0, PM_REMOVE)) {
  459. DispatchMessage(&msg);
  460. }
  461. while (PeekMessage(&msg, NULL, 0, 0, (PM_REMOVE | PM_QS_PAINT))) {
  462. DispatchMessage(&msg);
  463. }
  464. break;
  465. }
  466. case 0xFFFFFFFF:
  467. default:
  468. // Error
  469. hr = HRESULT_FROM_WIN32(GetLastError());
  470. bRunning = FALSE;
  471. break;
  472. }
  473. }
  474. // Close Wait dialog
  475. pWaitDlg->DestroyWindow( );
  476. // Reset buttons
  477. SetButtons();
  478. } WsbCatch(hr);
  479. // Check err code
  480. if (SUCCEEDED(hr)) {
  481. WsbTrace(L"CUnmanageWizardFinish::OnButtonRefresh: hr = <%ls>\n", WsbHrAsString(hr));
  482. } else {
  483. // Failure should happen only under sever resource conditions so
  484. // display a messagebox on Refresh failure
  485. WsbTraceAlways(L"CUnmanageWizardFinish::OnButtonRefresh: hr = <%ls>\n", WsbHrAsString(hr));
  486. CString errString;
  487. AfxFormatString1(errString, IDS_ERR_REFRESH_FAILED, WsbHrAsString(hr));
  488. AfxMessageBox(errString, RS_MB_ERROR);
  489. }
  490. if (hJobThread[0]) {
  491. CloseHandle(hJobThread[0]);
  492. }
  493. // Clean object registration staff
  494. if (bResCookieCreated) {
  495. pGIT->RevokeInterfaceFromGlobal(pThreadParam->dwResourceCookie);
  496. }
  497. if (bHsmCookieCreated) {
  498. pGIT->RevokeInterfaceFromGlobal(pThreadParam->dwHsmServerCookie);
  499. }
  500. if (pThreadParam) {
  501. delete pThreadParam;
  502. }
  503. WsbTraceOut( L"CUnmanageWizardFinish::OnButtonRefresh", L"" );
  504. }
  505. static DWORD RunValidateJob(void* pVoid)
  506. {
  507. WsbTraceIn( L"RunValidateJob", L"" );
  508. HRESULT hr = S_OK;
  509. HRESULT hrCom = S_OK;
  510. try {
  511. RUN_VALIDATE_PARAM* pThreadParam = NULL;
  512. CComPtr<IHsmServer> pHsmServer;
  513. CComPtr<IFsaResource> pFsaResource;
  514. CComPtr<IGlobalInterfaceTable> pGIT;
  515. hrCom = CoInitialize( 0 );
  516. WsbAffirmHr( hrCom );
  517. pThreadParam = (RUN_VALIDATE_PARAM*)pVoid;
  518. WsbAffirmPointer(pThreadParam);
  519. // Get Fsa Resource & HSM Server interface pointers for this thread
  520. WsbAffirmHr(CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL,
  521. CLSCTX_INPROC_SERVER, IID_IGlobalInterfaceTable, (void **)&pGIT));
  522. WsbAffirmHr(pGIT->GetInterfaceFromGlobal(pThreadParam->dwResourceCookie,
  523. IID_IFsaResource, (void **)&pFsaResource));
  524. WsbAffirmHr(pGIT->GetInterfaceFromGlobal(pThreadParam->dwHsmServerCookie,
  525. IID_IHsmServer, (void **)&pHsmServer));
  526. // Run job
  527. WsbTrace(L"RunValidateJob: Got interface pointers, running Validate job\n");
  528. WsbAffirmHr(RsCreateAndRunDirectFsaJob(HSM_JOB_DEF_TYPE_VALIDATE, pHsmServer,
  529. pFsaResource, TRUE));
  530. } WsbCatch(hr);
  531. if (SUCCEEDED(hrCom)) {
  532. CoUninitialize();
  533. }
  534. WsbTraceOut( L"RunValidateJob", L"hr = <%ls>", WsbHrAsString( hr ) );
  535. return(static_cast<DWORD>(hr));
  536. }