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.

1293 lines
33 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. htmlui.cpp
  5. Abstract:
  6. This file contains the implementation of the CRestoreShell class, which
  7. provide several methods to be used by HTML scripts. This class wrappes the
  8. new CRestoreManager class.
  9. Revision History:
  10. Seong Kook Khang (SKKhang) 10/08/99
  11. created
  12. Seong Kook Khang (SKKhang) 05/10/00
  13. Renamed from rstrshl.cpp to htmlui.cpp.
  14. New architecture for Whistler, now CRestoreShell is merely a dummy
  15. ActiveX control, wrapping the new CRestoreManager class. Most of the
  16. real functionalities were moved into CRestoreManager.
  17. ******************************************************************************/
  18. #include "stdwin.h"
  19. #include "stdatl.h"
  20. #include "resource.h"
  21. #include "rstrpriv.h"
  22. #include "srui_htm.h"
  23. #include "rstrmgr.h"
  24. #include "rstrshl.h"
  25. #include "rstrmap.h"
  26. #include "winsta.h"
  27. #define MAX_DATETIME_STR 256
  28. #define PROGRESSBAR_INITIALIZING_MAXVAL 30
  29. #define PROGRESSBAR_AFTER_INITIALIZING 30
  30. #define PROGRESSBAR_AFTER_RESTORE_MAP 40
  31. #define PROGRESSBAR_AFTER_RESTORE 100
  32. #define CLIWND_RESTORE_TIMER_ID 1
  33. #define CLIWND_RESTORE_TIMER_TIME 500
  34. const IID IID_IMarsHost = { 0xCC6FFEB0,0xE379,0x427a,{0x98,0x10,0xA1,0x6B,0x7A,0x82,0x6A,0x89 }};
  35. static LPCWSTR s_cszHelpAssistant = L"HelpAssistant";
  36. #define HELPASSISTANT_STRINGID 114
  37. BOOL ConvSysTimeToVariant( PSYSTEMTIME pst, VARIANT *pvar )
  38. {
  39. TraceFunctEnter("ConvSysTimeToVariant");
  40. BOOL fRet = FALSE;
  41. if ( !::SystemTimeToVariantTime( pst, &V_DATE(pvar) ) )
  42. {
  43. LPCWSTR cszErr = ::GetSysErrStr();
  44. ErrorTrace(TRACE_ID, "::SystemTimeToVariantTime failed - %ls", cszErr);
  45. goto Exit;
  46. }
  47. V_VT(pvar) = VT_DATE;
  48. fRet = TRUE;
  49. Exit:
  50. TraceFunctLeave();
  51. return( fRet );
  52. }
  53. BOOL ConvVariantToSysTime( VARIANT var, PSYSTEMTIME pst )
  54. {
  55. TraceFunctEnter("ConvVariantToSysTime");
  56. BOOL fRet = FALSE;
  57. if ( !::VariantTimeToSystemTime( V_DATE(&var), pst ) )
  58. {
  59. LPCWSTR cszErr = ::GetSysErrStr();
  60. ErrorTrace(TRACE_ID, "::VariantTimeToSystemTime failed - %ls", cszErr);
  61. goto Exit;
  62. }
  63. fRet = TRUE;
  64. Exit:
  65. TraceFunctLeave();
  66. return( fRet );
  67. }
  68. inline VARIANT_BOOL ConvBoolToVBool( BOOL fVal )
  69. {
  70. return( fVal ? VARIANT_TRUE : VARIANT_FALSE );
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CRestoreShell construction
  74. CRestoreShell::CRestoreShell()
  75. {
  76. m_fFormInitialized = FALSE;
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CRestoreShell - IRestoreShell restore points enumerator
  80. STDMETHODIMP
  81. CRestoreShell::Item( INT nIndex, IRestorePoint** ppRP )
  82. {
  83. TraceFunctEnter("CRestoreShell::Item");
  84. HRESULT hr = S_OK;
  85. SRestorePointInfo *pRPI;
  86. CRPIObj *pRPIObj;
  87. VALIDATE_INPUT_ARGUMENT(ppRP);
  88. *ppRP = NULL;
  89. if ( nIndex < 0 || nIndex >= g_pRstrMgr->GetRPICount() )
  90. {
  91. ErrorTrace(TRACE_ID, "Invalid Argument, out of range");
  92. hr = E_INVALIDARG;
  93. goto Exit;
  94. }
  95. pRPI = g_pRstrMgr->GetRPI( nIndex );
  96. if ( pRPI == NULL )
  97. {
  98. hr = S_FALSE;
  99. goto Exit;
  100. }
  101. hr = CRPIObj::CreateInstance( &pRPIObj );
  102. if ( hr != S_OK || pRPIObj == NULL )
  103. {
  104. ErrorTrace(TRACE_ID, "Cannot create RestorePointObject Instance, hr=%d", hr);
  105. if ( hr == S_OK )
  106. hr = E_FAIL;
  107. goto Exit;
  108. }
  109. hr = pRPIObj->HrInit( pRPI );
  110. if ( FAILED(hr) )
  111. goto Exit;
  112. pRPIObj->AddRef(); // CreateInstance doesn't do this
  113. hr = pRPIObj->QueryInterface( IID_IRestorePoint, (void**)ppRP );
  114. if ( FAILED(hr) )
  115. {
  116. ErrorTrace(TRACE_ID, "QI failed, hr=%d", hr);
  117. goto Exit;
  118. }
  119. Exit:
  120. TraceFunctLeave();
  121. return hr;
  122. }
  123. /******************************************************************************/
  124. STDMETHODIMP
  125. CRestoreShell::get_Count( INT *pnCount )
  126. {
  127. TraceFunctEnter("CRestoreShell::get_Count");
  128. HRESULT hr = S_OK;
  129. VALIDATE_INPUT_ARGUMENT(pnCount);
  130. *pnCount = g_pRstrMgr->GetRPICount();
  131. Exit:
  132. TraceFunctLeave();
  133. return( hr );
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CRestoreShell - IRestoreShell properties
  137. STDMETHODIMP
  138. CRestoreShell::get_CurrentDate( VARIANT *pvarDate )
  139. {
  140. TraceFunctEnter("CRestoreShell::get_CurrentDate");
  141. HRESULT hr = E_FAIL;
  142. SYSTEMTIME stToday;
  143. VALIDATE_INPUT_ARGUMENT(pvarDate);
  144. g_pRstrMgr->GetToday( &stToday );
  145. if ( !ConvSysTimeToVariant( &stToday, pvarDate ) )
  146. goto Exit;
  147. /*
  148. if ( ::SystemTimeToVariantTime( &stToday, &V_DATE(pvarDate) ) == 0 )
  149. {
  150. LPCWSTR cszErr = ::GetSysErrStr();
  151. ErrorTrace(TRACE_ID, "::SystemTimeToVariantTime failed - %ls", cszErr);
  152. hr = E_FAIL;
  153. goto Exit;
  154. }
  155. V_VT(pvarDate) = VT_DATE;
  156. */
  157. hr = S_OK;
  158. Exit:
  159. TraceFunctLeave();
  160. return hr;
  161. }
  162. /******************************************************************************/
  163. STDMETHODIMP
  164. CRestoreShell::get_FirstDayOfWeek( INT *pnFirstDay )
  165. {
  166. TraceFunctEnter("CRestoreShell::get_LocaleFirstDay");
  167. HRESULT hr = S_OK;
  168. int nFirstDay;
  169. VALIDATE_INPUT_ARGUMENT(pnFirstDay);
  170. *pnFirstDay = 0;
  171. nFirstDay = g_pRstrMgr->GetFirstDayOfWeek();
  172. if ( nFirstDay < 0 || nFirstDay > 6 )
  173. {
  174. hr = E_FAIL;
  175. goto Exit;
  176. }
  177. if ( nFirstDay == 6 )
  178. *pnFirstDay = 0;
  179. else
  180. *pnFirstDay = nFirstDay + 1;
  181. Exit:
  182. TraceFunctLeave();
  183. return( hr );
  184. }
  185. /******************************************************************************/
  186. STDMETHODIMP
  187. CRestoreShell::get_IsSafeMode( VARIANT_BOOL *pfIsSafeMode )
  188. {
  189. TraceFunctEnter("CRestoreShell::get_IsSafeMode");
  190. HRESULT hr = S_OK;
  191. VALIDATE_INPUT_ARGUMENT(pfIsSafeMode);
  192. *pfIsSafeMode = ConvBoolToVBool( g_pRstrMgr->GetIsSafeMode() );
  193. Exit:
  194. TraceFunctLeave();
  195. return( hr );
  196. }
  197. /******************************************************************************/
  198. STDMETHODIMP
  199. CRestoreShell::get_IsUndo( VARIANT_BOOL *pfIsUndo )
  200. {
  201. TraceFunctEnter("CRestoreShell::get_IsUndo");
  202. HRESULT hr = S_OK;
  203. VALIDATE_INPUT_ARGUMENT(pfIsUndo);
  204. *pfIsUndo = ConvBoolToVBool( g_pRstrMgr->GetIsUndo() );
  205. Exit:
  206. TraceFunctLeave();
  207. return( hr );
  208. }
  209. STDMETHODIMP
  210. CRestoreShell::put_IsUndo( VARIANT_BOOL fIsUndo )
  211. {
  212. TraceFunctEnter("CRestoreShell::put_IsUndo");
  213. g_pRstrMgr->SetIsUndo( fIsUndo );
  214. TraceFunctLeave();
  215. return( S_OK );
  216. }
  217. /******************************************************************************/
  218. STDMETHODIMP
  219. CRestoreShell::get_LastRestore( INT *pnLastRestore )
  220. {
  221. TraceFunctEnter("CRestoreShell::get_LastRestore");
  222. HRESULT hr = S_OK;
  223. VALIDATE_INPUT_ARGUMENT(pnLastRestore);
  224. //Initialize();
  225. *pnLastRestore = g_pRstrMgr->GetLastRestore();
  226. Exit:
  227. TraceFunctLeave();
  228. return( hr );
  229. }
  230. /******************************************************************************/
  231. STDMETHODIMP
  232. CRestoreShell::get_MainOption( INT *pnMainOption )
  233. {
  234. TraceFunctEnter("CRestoreShell::get_MainOption");
  235. HRESULT hr = S_OK;
  236. VALIDATE_INPUT_ARGUMENT(pnMainOption);
  237. *pnMainOption = g_pRstrMgr->GetMainOption();
  238. Exit:
  239. TraceFunctLeave();
  240. return( hr );
  241. }
  242. STDMETHODIMP
  243. CRestoreShell::put_MainOption( INT nMainOption )
  244. {
  245. TraceFunctEnter("CRestoreShell::put_MainOption");
  246. HRESULT hr = S_OK;
  247. if ( !g_pRstrMgr->SetMainOption( nMainOption ) )
  248. hr = E_INVALIDARG;
  249. TraceFunctLeave();
  250. return( hr );
  251. }
  252. /******************************************************************************/
  253. STDMETHODIMP
  254. CRestoreShell::get_ManualRPName( BSTR *pbstrManualRP )
  255. {
  256. TraceFunctEnter("CRestoreShell::get_ManualRPName");
  257. HRESULT hr = S_OK;
  258. LPCWSTR cszRPName;
  259. VALIDATE_INPUT_ARGUMENT(pbstrManualRP);
  260. cszRPName = g_pRstrMgr->GetManualRPName();
  261. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrManualRP, cszRPName );
  262. Exit:
  263. TraceFunctLeave();
  264. return( hr );
  265. }
  266. STDMETHODIMP
  267. CRestoreShell::put_ManualRPName( BSTR bstrManualRP )
  268. {
  269. TraceFunctEnter("CRestoreShell::put_ManualRPName");
  270. g_pRstrMgr->SetManualRPName( bstrManualRP );
  271. TraceFunctLeave();
  272. return( S_OK );
  273. }
  274. /******************************************************************************/
  275. STDMETHODIMP
  276. CRestoreShell::get_MaxDate( VARIANT *pvarDate )
  277. {
  278. TraceFunctEnter("CRestoreShell::get_MaxDate");
  279. HRESULT hr = E_FAIL;
  280. SYSTEMTIME stMax;
  281. VALIDATE_INPUT_ARGUMENT(pvarDate);
  282. g_pRstrMgr->GetMaxDate( &stMax );
  283. if ( !ConvSysTimeToVariant( &stMax, pvarDate ) )
  284. goto Exit;
  285. hr = S_OK;
  286. Exit:
  287. TraceFunctLeave();
  288. return( hr );
  289. }
  290. STDMETHODIMP
  291. CRestoreShell::get_MinDate( VARIANT *pvarDate )
  292. {
  293. TraceFunctEnter("CRestoreShell::get_MinDate");
  294. HRESULT hr = E_FAIL;
  295. SYSTEMTIME stMin;
  296. VALIDATE_INPUT_ARGUMENT(pvarDate);
  297. g_pRstrMgr->GetMinDate( &stMin );
  298. if ( !ConvSysTimeToVariant( &stMin, pvarDate ) )
  299. goto Exit;
  300. hr = S_OK;
  301. Exit:
  302. TraceFunctLeave();
  303. return( hr );
  304. }
  305. /******************************************************************************/
  306. STDMETHODIMP
  307. CRestoreShell::get_RealPoint( INT *pnPoint )
  308. {
  309. TraceFunctEnter("CRestoreShell::get_RealPoint");
  310. HRESULT hr = S_OK;
  311. VALIDATE_INPUT_ARGUMENT(pnPoint);
  312. *pnPoint = g_pRstrMgr->GetRealPoint();
  313. Exit:
  314. TraceFunctLeave();
  315. return( hr );
  316. }
  317. /******************************************************************************/
  318. STDMETHODIMP
  319. CRestoreShell::get_RenamedFolders( IRenamedFolders **ppList )
  320. {
  321. TraceFunctEnter("CRestoreShell::get_RenamedFolders");
  322. HRESULT hr = S_OK;
  323. CRFObj *pRF;
  324. VALIDATE_INPUT_ARGUMENT(ppList);
  325. hr = CComObject<CRenamedFolders>::CreateInstance( &pRF );
  326. if ( FAILED(hr) )
  327. {
  328. ErrorTrace(TRACE_ID, "Cannot create CRenamedFolders object, hr=0x%08X", hr);
  329. goto Exit;
  330. }
  331. hr = pRF->QueryInterface( IID_IRenamedFolders, (void**)ppList );
  332. if ( FAILED(hr) )
  333. {
  334. ErrorTrace(TRACE_ID, "Cannot QI IRenamedFolders, hr=0x%08X", hr);
  335. goto Exit;
  336. }
  337. Exit:
  338. TraceFunctLeave();
  339. return hr;
  340. }
  341. /******************************************************************************/
  342. STDMETHODIMP
  343. CRestoreShell::get_RestorePtSelected( VARIANT_BOOL *pfRPSel )
  344. {
  345. TraceFunctEnter("CRestoreShell::get_RestorePtSelected");
  346. HRESULT hr = S_OK;
  347. VALIDATE_INPUT_ARGUMENT(pfRPSel);
  348. *pfRPSel = ConvBoolToVBool( g_pRstrMgr->GetIsRPSelected() );
  349. Exit:
  350. TraceFunctLeave();
  351. return( hr );
  352. }
  353. STDMETHODIMP
  354. CRestoreShell::put_RestorePtSelected( VARIANT_BOOL fRPSel )
  355. {
  356. TraceFunctEnter("CRestoreShell::put_RestorePtSelected");
  357. g_pRstrMgr->SetIsRPSelected( fRPSel );
  358. TraceFunctLeave();
  359. return( S_OK );
  360. }
  361. /******************************************************************************/
  362. STDMETHODIMP
  363. CRestoreShell::get_SelectedDate( VARIANT *pvarDate )
  364. {
  365. TraceFunctEnter("CRestoreShell::get_SelectedDate");
  366. HRESULT hr = E_FAIL;
  367. SYSTEMTIME stSel;
  368. //DATE dateSel;
  369. VALIDATE_INPUT_ARGUMENT(pvarDate);
  370. g_pRstrMgr->GetSelectedDate( &stSel );
  371. if ( !ConvSysTimeToVariant( &stSel, pvarDate ) )
  372. goto Exit;
  373. hr = S_OK;
  374. Exit:
  375. TraceFunctLeave();
  376. return( hr );
  377. }
  378. STDMETHODIMP
  379. CRestoreShell::put_SelectedDate( VARIANT varDate )
  380. {
  381. TraceFunctEnter("CRestoreShell::put_SelectedDate");
  382. HRESULT hr = E_FAIL;
  383. SYSTEMTIME stSel;
  384. if ( !ConvVariantToSysTime( varDate, &stSel ) )
  385. goto Exit;
  386. g_pRstrMgr->SetSelectedDate( &stSel );
  387. hr = S_OK;
  388. Exit:
  389. TraceFunctLeave();
  390. return hr;
  391. }
  392. /******************************************************************************/
  393. STDMETHODIMP
  394. CRestoreShell::get_SelectedName( BSTR *pbstrName )
  395. {
  396. TraceFunctEnter("CRestoreShell::get_SelectedName");
  397. HRESULT hr = S_OK;
  398. LPCWSTR cszName;
  399. VALIDATE_INPUT_ARGUMENT(pbstrName);
  400. cszName = g_pRstrMgr->GetSelectedName();
  401. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrName, cszName );
  402. Exit:
  403. TraceFunctLeave();
  404. return hr;
  405. }
  406. /******************************************************************************/
  407. STDMETHODIMP
  408. CRestoreShell::get_SelectedPoint( INT *pnPoint )
  409. {
  410. TraceFunctEnter("CRestoreShell::get_SelectedPoint");
  411. HRESULT hr = S_OK;
  412. VALIDATE_INPUT_ARGUMENT(pnPoint);
  413. *pnPoint = g_pRstrMgr->GetSelectedPoint();
  414. Exit:
  415. TraceFunctLeave();
  416. return( hr );
  417. }
  418. STDMETHODIMP
  419. CRestoreShell::put_SelectedPoint( INT nPoint )
  420. {
  421. TraceFunctEnter("CRestoreShell::put_SelectedPoint");
  422. HRESULT hr = S_OK;
  423. if ( nPoint < 0 || nPoint >= g_pRstrMgr->GetRPICount() )
  424. {
  425. ErrorTrace(TRACE_ID, "Index is out of range");
  426. hr = E_INVALIDARG;
  427. goto Exit;
  428. }
  429. if ( !g_pRstrMgr->SetSelectedPoint( nPoint ) )
  430. {
  431. hr = E_FAIL;
  432. goto Exit;
  433. }
  434. Exit:
  435. TraceFunctLeave();
  436. return( hr );
  437. }
  438. /******************************************************************************/
  439. STDMETHODIMP
  440. CRestoreShell::get_SmgrUnavailable( VARIANT_BOOL *pfSmgr )
  441. {
  442. TraceFunctEnter("CRestoreShell::get_SmgrUnavailable");
  443. HRESULT hr = S_OK;
  444. VALIDATE_INPUT_ARGUMENT(pfSmgr);
  445. *pfSmgr = ConvBoolToVBool( g_pRstrMgr->GetIsSmgrAvailable() );
  446. Exit:
  447. TraceFunctLeave();
  448. return( hr );
  449. }
  450. /******************************************************************************/
  451. STDMETHODIMP
  452. CRestoreShell::get_StartMode( INT *pnMode )
  453. {
  454. TraceFunctEnter("CRestoreShell::get_StartMode");
  455. HRESULT hr = S_OK;
  456. VALIDATE_INPUT_ARGUMENT(pnMode);
  457. *pnMode = g_pRstrMgr->GetStartMode();
  458. Exit:
  459. TraceFunctLeave();
  460. return hr;
  461. }
  462. /******************************************************************************/
  463. STDMETHODIMP
  464. CRestoreShell::get_UsedDate( VARIANT *pvarDate )
  465. {
  466. TraceFunctEnter("CRestoreShell::get_UsedDate");
  467. HRESULT hr = E_FAIL;
  468. SYSTEMTIME stDate;
  469. //DATE dateDate;
  470. VALIDATE_INPUT_ARGUMENT(pvarDate);
  471. g_pRstrMgr->GetUsedDate( &stDate );
  472. if ( !ConvSysTimeToVariant( &stDate, pvarDate ) )
  473. goto Exit;
  474. hr = S_OK;
  475. Exit:
  476. TraceFunctLeave();
  477. return( hr );
  478. }
  479. /******************************************************************************/
  480. STDMETHODIMP
  481. CRestoreShell::get_UsedName( BSTR *pbstrName )
  482. {
  483. TraceFunctEnter("CRestoreShell::get_UsedDate");
  484. HRESULT hr = S_OK;
  485. LPCWSTR cszName;
  486. VALIDATE_INPUT_ARGUMENT(pbstrName);
  487. cszName = g_pRstrMgr->GetUsedName();
  488. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrName, cszName );
  489. Exit:
  490. TraceFunctLeave();
  491. return hr;
  492. }
  493. /////////////////////////////////////////////////////////////////////////////
  494. // CRestoreShell - IRestoreShell properties - HTML UI Specific
  495. STDMETHODIMP
  496. CRestoreShell::get_CanNavigatePage( VARIANT_BOOL *pfCanNavigatePage )
  497. {
  498. TraceFunctEnter("CRestoreShell::get_CanNavigatePage");
  499. HRESULT hr = S_OK;
  500. VALIDATE_INPUT_ARGUMENT(pfCanNavigatePage);
  501. *pfCanNavigatePage = ConvBoolToVBool( g_pRstrMgr->GetCanNavigatePage() );
  502. Exit:
  503. TraceFunctLeave();
  504. return( S_OK );
  505. }
  506. STDMETHODIMP
  507. CRestoreShell::put_CanNavigatePage( VARIANT_BOOL fCanNavigatePage )
  508. {
  509. TraceFunctEnter("CRestoreShell::put_CanNavigatePage");
  510. g_pRstrMgr->SetCanNavigatePage( fCanNavigatePage );
  511. TraceFunctLeave();
  512. return( S_OK );
  513. }
  514. /////////////////////////////////////////////////////////////////////////////
  515. // CRestoreShell - IRestoreShell methods
  516. STDMETHODIMP
  517. CRestoreShell::BeginRestore( VARIANT_BOOL *pfBeginRestore )
  518. {
  519. TraceFunctEnter("CRestoreShell::BeginRestore");
  520. HRESULT hr = S_OK;
  521. BOOL fRes;
  522. VALIDATE_INPUT_ARGUMENT(pfBeginRestore);
  523. fRes = g_pRstrMgr->BeginRestore();
  524. *pfBeginRestore = ConvBoolToVBool( fRes );
  525. Exit:
  526. TraceFunctLeave();
  527. return( hr );
  528. }
  529. /////////////////////////////////////////////////////////////////////////////
  530. // CRestoreShell - IRestoreShell methods
  531. STDMETHODIMP
  532. CRestoreShell::CheckRestore( VARIANT_BOOL *pfCheckRestore )
  533. {
  534. TraceFunctEnter("CRestoreShell::BeginRestore");
  535. HRESULT hr = S_OK;
  536. BOOL fRes;
  537. VALIDATE_INPUT_ARGUMENT(pfCheckRestore);
  538. fRes = g_pRstrMgr->CheckRestore(FALSE); // show UI if any errors found
  539. *pfCheckRestore = ConvBoolToVBool( fRes );
  540. Exit:
  541. TraceFunctLeave();
  542. return( hr );
  543. }
  544. /******************************************************************************/
  545. //
  546. // This method is called only from the HTML code to decide whether to
  547. // shutdown or not, and the external.window.close() is called to shutdown
  548. // as sending a WM_CLOSE message to Mars causes problems
  549. //
  550. STDMETHODIMP
  551. CRestoreShell::Cancel( VARIANT_BOOL *pfAbort )
  552. {
  553. TraceFunctEnter("CRestoreShell::Cancel");
  554. HRESULT hr = S_OK;
  555. VALIDATE_INPUT_ARGUMENT(pfAbort);
  556. *pfAbort = ConvBoolToVBool( g_pRstrMgr->Cancel() );
  557. Exit:
  558. TraceFunctLeave();
  559. return( hr );
  560. }
  561. /******************************************************************************/
  562. STDMETHODIMP
  563. CRestoreShell::CancelRestorePoint()
  564. {
  565. TraceFunctEnter("CRestoreShell::CancelRestorePoint");
  566. HRESULT hr = E_FAIL;
  567. if ( !g_pRstrMgr->CancelRestorePoint() )
  568. goto Exit;
  569. hr = S_OK;
  570. Exit:
  571. TraceFunctLeave();
  572. return( hr );
  573. }
  574. /*******************************************************************************/
  575. STDMETHODIMP
  576. CRestoreShell::CompareDate( VARIANT varDate1, VARIANT varDate2, INT *pnCmp )
  577. {
  578. TraceFunctEnter("CRestoreShell::CompareDate");
  579. HRESULT hr = S_OK;
  580. VALIDATE_INPUT_ARGUMENT(pnCmp);
  581. VALIDATE_INPUT_VARIANT(varDate1, VT_DATE);
  582. VALIDATE_INPUT_VARIANT(varDate2, VT_DATE);
  583. *pnCmp = (long)V_DATE(&varDate1) - (long)V_DATE(&varDate2);
  584. Exit:
  585. TraceFunctLeave();
  586. return( hr );
  587. }
  588. /******************************************************************************/
  589. STDMETHODIMP
  590. CRestoreShell::CreateRestorePoint( VARIANT_BOOL *pfSucceeded )
  591. {
  592. TraceFunctEnter("CRestoreShell::CreateRestorePoint");
  593. HRESULT hr = S_OK;
  594. BOOL fRes;
  595. VALIDATE_INPUT_ARGUMENT(pfSucceeded);
  596. fRes = g_pRstrMgr->CreateRestorePoint();
  597. *pfSucceeded = ConvBoolToVBool( fRes );
  598. Exit:
  599. TraceFunctLeave();
  600. return( hr );
  601. }
  602. /******************************************************************************/
  603. STDMETHODIMP
  604. CRestoreShell::DisableFIFO( void )
  605. {
  606. TraceFunctEnter("CRestoreShell::DisableFIFO");
  607. HRESULT hr = S_OK;
  608. if ( !g_pRstrMgr->DisableFIFO() )
  609. {
  610. hr = E_FAIL;
  611. goto Exit;
  612. }
  613. Exit:
  614. TraceFunctLeave();
  615. return( hr );
  616. }
  617. /******************************************************************************/
  618. STDMETHODIMP
  619. CRestoreShell::EnableFIFO( void )
  620. {
  621. TraceFunctEnter("CRestoreShell::EnableFIFO");
  622. HRESULT hr = S_OK;
  623. if ( !g_pRstrMgr->EnableFIFO() )
  624. {
  625. hr = E_FAIL;
  626. goto Exit;
  627. }
  628. Exit:
  629. TraceFunctLeave();
  630. return( hr );
  631. }
  632. /******************************************************************************/
  633. STDMETHODIMP
  634. CRestoreShell::FormatDate( VARIANT varDate, VARIANT_BOOL fLongFmt, BSTR *pbstrDate )
  635. {
  636. TraceFunctEnter("CRestoreShell::FormatDate");
  637. HRESULT hr = E_FAIL;
  638. SYSTEMTIME st;
  639. CSRStr str;
  640. VALIDATE_INPUT_ARGUMENT(pbstrDate);
  641. VALIDATE_INPUT_VARIANT(varDate, VT_DATE);
  642. if ( !ConvVariantToSysTime( varDate, &st ) )
  643. goto Exit;
  644. if ( !g_pRstrMgr->FormatDate( &st, str, fLongFmt ) )
  645. goto Exit;
  646. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrDate, str );
  647. hr = S_OK;
  648. Exit:
  649. TraceFunctLeave();
  650. return( hr );
  651. }
  652. /******************************************************************************/
  653. STDMETHODIMP
  654. CRestoreShell::FormatLowDiskMsg( BSTR bstrFmt, BSTR *pbstrMsg )
  655. {
  656. TraceFunctEnter("CRestoreShell::FormatLowDiskMsg");
  657. HRESULT hr = E_FAIL;
  658. CSRStr str;
  659. VALIDATE_INPUT_ARGUMENT(pbstrMsg);
  660. if ( !g_pRstrMgr->FormatLowDiskMsg( (WCHAR *)bstrFmt, str ) )
  661. goto Exit;
  662. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrMsg, str );
  663. hr = S_OK;
  664. Exit:
  665. TraceFunctLeave();
  666. return( hr );
  667. }
  668. /******************************************************************************/
  669. STDMETHODIMP
  670. CRestoreShell::FormatTime( VARIANT varTime, BSTR *pbstrTime )
  671. {
  672. TraceFunctEnter("CRestoreShell::FormatTime");
  673. HRESULT hr = E_FAIL;
  674. SYSTEMTIME st;
  675. CSRStr str;
  676. VALIDATE_INPUT_ARGUMENT(pbstrTime);
  677. VALIDATE_INPUT_VARIANT(varTime, VT_DATE);
  678. if ( !ConvVariantToSysTime( varTime, &st ) )
  679. goto Exit;
  680. if ( !g_pRstrMgr->FormatTime( &st, str ) )
  681. goto Exit;
  682. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrTime, str );
  683. hr = S_OK;
  684. Exit:
  685. TraceFunctLeave();
  686. return( hr );
  687. }
  688. /******************************************************************************/
  689. STDMETHODIMP
  690. CRestoreShell::GetLocaleDateFormat( VARIANT varDate, BSTR bstrFormat, BSTR *pbstrDate )
  691. {
  692. TraceFunctEnter("CRestoreShell::GetLocaleDateFormat");
  693. HRESULT hr = E_FAIL;
  694. SYSTEMTIME st;
  695. CSRStr str;
  696. VALIDATE_INPUT_ARGUMENT(pbstrDate);
  697. VALIDATE_INPUT_VARIANT(varDate, VT_DATE);
  698. if ( !ConvVariantToSysTime( varDate, &st ) )
  699. goto Exit;
  700. if ( !g_pRstrMgr->GetLocaleDateFormat( &st, bstrFormat, str ) )
  701. goto Exit;
  702. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrDate, str );
  703. hr = S_OK;
  704. Exit:
  705. TraceFunctLeave();
  706. return( hr );
  707. }
  708. /******************************************************************************/
  709. STDMETHODIMP
  710. CRestoreShell::GetYearMonthStr( INT nYear, INT nMonth, BSTR *pbstrYearMonth )
  711. {
  712. TraceFunctEnter("CRestoreShell::GetYearMonthStr");
  713. HRESULT hr = E_FAIL;
  714. CSRStr str;
  715. VALIDATE_INPUT_ARGUMENT(pbstrYearMonth);
  716. if ( !g_pRstrMgr->GetYearMonthStr( nYear, nMonth, str ) )
  717. goto Exit;
  718. ALLOCATEBSTR_AND_CHECK_ERROR( pbstrYearMonth, str );
  719. hr = S_OK;
  720. Exit:
  721. TraceFunctLeave();
  722. return( hr );
  723. }
  724. /******************************************************************************/
  725. STDMETHODIMP
  726. CRestoreShell::InitializeAll()
  727. {
  728. TraceFunctEnter("CRestoreShell::InitializeAll");
  729. HRESULT hr = S_OK;
  730. if ( !g_pRstrMgr->InitializeAll() )
  731. {
  732. hr = E_FAIL;
  733. goto Exit;
  734. }
  735. Exit:
  736. TraceFunctLeave();
  737. return( hr );
  738. }
  739. /******************************************************************************/
  740. STDMETHODIMP
  741. CRestoreShell::Restore( OLE_HANDLE hwndProgress )
  742. {
  743. TraceFunctEnter("CRestoreShell::Restore");
  744. HRESULT hr = S_OK;
  745. if ( !g_pRstrMgr->Restore( (HWND)hwndProgress ) )
  746. {
  747. hr = E_FAIL;
  748. goto Exit;
  749. }
  750. Exit:
  751. TraceFunctLeave();
  752. return( hr );
  753. }
  754. /******************************************************************************/
  755. STDMETHODIMP
  756. CRestoreShell::SetFormSize( INT nWidth, INT nHeight )
  757. {
  758. TraceFunctEnter("CRestoreShell::SetFormSize");
  759. HWND hwndFrame;
  760. CWindow cWnd;
  761. RECT rc;
  762. HICON hIconFrame;
  763. //
  764. // Cannot initialize more than once
  765. //
  766. if ( m_fFormInitialized )
  767. goto Exit;
  768. hwndFrame = g_pRstrMgr->GetFrameHwnd();
  769. if ( hwndFrame == NULL )
  770. {
  771. ErrorTrace(TRACE_ID, "hwndFrame is NULL");
  772. goto Exit;
  773. }
  774. cWnd.Attach( hwndFrame );
  775. cWnd.ModifyStyle( WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX, 0 );
  776. hIconFrame = (HICON)::LoadImage( _Module.GetResourceInstance(),
  777. MAKEINTRESOURCE(IDR_RSTRUI),
  778. IMAGE_ICON, 0, 0, LR_DEFAULTSIZE );
  779. if ( hIconFrame != NULL )
  780. cWnd.SetIcon( hIconFrame, TRUE );
  781. hIconFrame = (HICON)::LoadImage( _Module.GetResourceInstance(),
  782. MAKEINTRESOURCE(IDR_RSTRUI),
  783. IMAGE_ICON,
  784. ::GetSystemMetrics(SM_CXSMICON),
  785. ::GetSystemMetrics(SM_CYSMICON),
  786. LR_DEFAULTSIZE );
  787. if ( hIconFrame != NULL )
  788. cWnd.SetIcon( hIconFrame, FALSE );
  789. rc.left = 0;
  790. rc.top = 0;
  791. rc.right = nWidth;
  792. rc.bottom = nHeight;
  793. ::AdjustWindowRectEx( &rc, cWnd.GetStyle(), FALSE, cWnd.GetExStyle() );
  794. cWnd.SetWindowPos(
  795. NULL,
  796. 0,
  797. 0,
  798. rc.right-rc.left,
  799. rc.bottom-rc.top,
  800. SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER);
  801. cWnd.CenterWindow(::GetDesktopWindow()); // ignore error return if any
  802. cWnd.ShowWindow(SW_SHOW);
  803. m_fFormInitialized = TRUE ;
  804. Exit:
  805. TraceFunctLeave();
  806. return( S_OK );
  807. }
  808. /******************************************************************************/
  809. STDMETHODIMP
  810. CRestoreShell::ShowMessage( BSTR bstrMsg )
  811. {
  812. TraceFunctEnter("CRestoreShell::ShowMessage");
  813. WCHAR szTitle[MAX_STR_TITLE];
  814. CSRStr strMsg = bstrMsg;
  815. PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  816. ::MessageBox( g_pRstrMgr->GetFrameHwnd(), strMsg, szTitle, MB_OK | MB_ICONINFORMATION );
  817. TraceFunctLeave();
  818. return( S_OK );
  819. }
  820. /******************************************************************************/
  821. STDMETHODIMP
  822. CRestoreShell::CanRunRestore( VARIANT_BOOL *pfSucceeded )
  823. {
  824. TraceFunctEnter("CRestoreShell::CanRunRestore");
  825. HRESULT hr = S_OK;
  826. BOOL fRes;
  827. VALIDATE_INPUT_ARGUMENT(pfSucceeded);
  828. fRes = g_pRstrMgr->CanRunRestore( FALSE );
  829. *pfSucceeded = ConvBoolToVBool( fRes );
  830. Exit:
  831. TraceFunctLeave();
  832. return( hr );
  833. }
  834. /*
  835. // check if this user is an RA Help Assistant
  836. BOOL
  837. IsRAUser(HANDLE hServer , PLOGONID pId, LPWSTR pszHelpAsst)
  838. {
  839. TENTER("IsRAUser");
  840. WINSTATIONINFORMATION Info;
  841. ULONG Length;
  842. ULONG LogonId;
  843. BOOL fRet = FALSE;
  844. LogonId = pId->LogonId;
  845. if ( !WinStationQueryInformation( hServer,
  846. LogonId,
  847. WinStationInformation,
  848. &Info,
  849. sizeof(Info),
  850. &Length ) )
  851. {
  852. trace(0, "! WinStationQueryInformation : %ld", GetLastError());
  853. goto done;
  854. }
  855. trace(0, "Logged user: %S", Info.UserName);
  856. if (0 == _wcsnicmp(Info.UserName, pszHelpAsst, lstrlen(pszHelpAsst)))
  857. fRet = TRUE;
  858. done:
  859. TLEAVE();
  860. return fRet;
  861. }
  862. */
  863. /******************************************************************************/
  864. // --------------------------------------------------------------------------
  865. // GetLoggedOnUserCount
  866. //
  867. // Arguments: <none>
  868. //
  869. // Returns: int
  870. //
  871. // Purpose: Returns the count of logged on users on this machine. Ripped
  872. // straight out of shtdndlg.c in msgina.
  873. //
  874. // History: 2000-03-29 vtan created
  875. // --------------------------------------------------------------------------
  876. int GetLoggedOnUserCount(void)
  877. {
  878. int iCount;
  879. HANDLE hServer;
  880. PLOGONID pLogonID, pLogonIDs;
  881. ULONG ul, ulEntries;
  882. WCHAR szHelpAsst[50];
  883. DWORD dwErr;
  884. TENTER("GetLoggedOnUserCount");
  885. /*
  886. // get the "HelpAssistant" string from the resource exe
  887. dwErr = SRLoadString(L"sessmgr.exe", HELPASSISTANT_STRINGID, szHelpAsst, sizeof(szHelpAsst));
  888. if (dwErr != ERROR_SUCCESS)
  889. {
  890. trace(0, "! SRLoadString : %ld", dwErr);
  891. lstrcpy(szHelpAsst, s_cszHelpAssistant);
  892. }
  893. trace(0, "Help Asst string: %S", szHelpAsst);
  894. */
  895. iCount = 0;
  896. // Open a connection to terminal services and get the number of sessions.
  897. hServer = WinStationOpenServerW(reinterpret_cast<WCHAR*>(
  898. SERVERNAME_CURRENT));
  899. if (hServer != NULL)
  900. {
  901. if (WinStationEnumerate(hServer, &pLogonIDs, &ulEntries))
  902. {
  903. // Iterate the sessions looking for active and disconnected sessions only.
  904. // Then match the user name and domain (case INsensitive) for a result.
  905. for (ul = 0, pLogonID = pLogonIDs; ul < ulEntries; ++ul, ++pLogonID)
  906. {
  907. if ((pLogonID->State == State_Active) || (pLogonID->State ==
  908. State_Disconnected) || (pLogonID->State == State_Shadow))
  909. {
  910. // don't count RA Help Assistant user if present
  911. if (FALSE == WinStationIsHelpAssistantSession(SERVERNAME_CURRENT, pLogonID->LogonId))
  912. ++iCount;
  913. else
  914. trace(0, "RA session present - not counting");
  915. }
  916. }
  917. // Free any resources used.
  918. (BOOLEAN)WinStationFreeMemory(pLogonIDs);
  919. }
  920. (BOOLEAN)WinStationCloseServer(hServer);
  921. }
  922. TLEAVE();
  923. // Return result.
  924. return(iCount);
  925. }
  926. /******************************************************************************/
  927. STDMETHODIMP
  928. CRestoreShell::DisplayOtherUsersWarning()
  929. {
  930. TraceFunctEnter("CRestoreShell::DisplayOtherUsersWarning");
  931. HRESULT hr = S_OK;
  932. WCHAR szTitle[MAX_STR_TITLE];
  933. WCHAR szMsg[MAX_STR_MSG];
  934. WCHAR szMsg1[MAX_STR_MSG];
  935. WCHAR szMsg2[MAX_STR_MSG];
  936. DWORD dwUsersLoggedIn,dwCount,dwError;
  937. dwUsersLoggedIn = GetLoggedOnUserCount();
  938. if (dwUsersLoggedIn <= 1)
  939. {
  940. // there are no other users
  941. goto cleanup;
  942. }
  943. // there are other users - display warning
  944. dwCount=PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  945. if (dwCount==0)
  946. {
  947. dwError = GetLastError();
  948. ErrorTrace(0, "Loading IDS_RESTOREUI_TITLE failed %d",dwError);
  949. goto cleanup;
  950. }
  951. dwCount=PCHLoadString(IDS_ERR_OTHER_USERS_LOGGED_ON1, szMsg1, MAX_STR_MSG);
  952. if (dwCount==0)
  953. {
  954. dwError = GetLastError();
  955. ErrorTrace(0, "Loading IDS_ERR_OTHER_USERS_LOGGED_ON1 failed %d",
  956. dwError);
  957. goto cleanup;
  958. }
  959. dwCount=PCHLoadString(IDS_ERR_OTHER_USERS_LOGGED_ON2, szMsg2, MAX_STR_MSG);
  960. if (dwCount==0)
  961. {
  962. dwError = GetLastError();
  963. ErrorTrace(0, "Loading IDS_ERR_OTHER_USERS_LOGGED_ON2 failed %d",
  964. dwError);
  965. goto cleanup;
  966. }
  967. ::wsprintf( szMsg, L"%s %d%s", szMsg1,dwUsersLoggedIn -1, szMsg2 );
  968. ::MessageBox( g_pRstrMgr->GetFrameHwnd(),
  969. szMsg,
  970. szTitle,
  971. MB_OK | MB_ICONWARNING | MB_DEFBUTTON2);
  972. cleanup:
  973. TraceFunctLeave();
  974. return( hr );
  975. }
  976. //this returns TRUE if any move fileex entries exist
  977. STDMETHODIMP
  978. CRestoreShell::DisplayMoveFileExWarning(VARIANT_BOOL *pfSucceeded)
  979. {
  980. TraceFunctEnter("CRestoreShell::DisplayOtherUsersWarning");
  981. HRESULT hr = S_OK;
  982. DWORD dwType, cbData, dwRes;
  983. BOOL fRes;
  984. VALIDATE_INPUT_ARGUMENT(pfSucceeded);
  985. fRes = FALSE;
  986. /*
  987. // Check if MoveFileEx entries exist
  988. dwRes = ::SHGetValue( HKEY_LOCAL_MACHINE,
  989. STR_REGPATH_SESSIONMANAGER,
  990. STR_REGVAL_MOVEFILEEX,
  991. &dwType,
  992. NULL,
  993. &cbData );
  994. if ( dwRes == ERROR_SUCCESS )
  995. {
  996. if ( cbData > 2* sizeof(WCHAR))
  997. {
  998. fRes = TRUE;
  999. ErrorTrace(0, "MoveFileEx entries exist...");
  1000. ::ShowSRErrDlg( IDS_ERR_SR_MOVEFILEEX_EXIST );
  1001. }
  1002. }
  1003. */
  1004. *pfSucceeded = ConvBoolToVBool( fRes );
  1005. Exit:
  1006. TraceFunctLeave();
  1007. return( hr );
  1008. }
  1009. //this returns TRUE if any move fileex entries exist
  1010. STDMETHODIMP
  1011. CRestoreShell::WasLastRestoreFromSafeMode(VARIANT_BOOL *pfSucceeded)
  1012. {
  1013. TraceFunctEnter("CRestoreShell::WasLastRestoreFromSafeMode");
  1014. HRESULT hr = S_OK;
  1015. BOOL fRes;
  1016. VALIDATE_INPUT_ARGUMENT(pfSucceeded);
  1017. fRes = TRUE;
  1018. fRes = ::WasLastRestoreInSafeMode();
  1019. *pfSucceeded = ConvBoolToVBool( fRes );
  1020. Exit:
  1021. TraceFunctLeave();
  1022. return( hr );
  1023. }
  1024. /***************************************************************************/
  1025. //
  1026. // END OF NEW CODE
  1027. //
  1028. // end of file