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.

1851 lines
49 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. rstrmgr.cpp
  5. Abstract:
  6. This file contains the implementation of the CRestoreManager class, which
  7. controls overall restoration process and provides methods to control &
  8. help user experience flow.
  9. Revision History:
  10. Seong Kook Khang (SKKhang) 05/10/00
  11. created
  12. ******************************************************************************/
  13. #include "stdwin.h"
  14. #include "resource.h"
  15. #include "rstrpriv.h"
  16. #include "rstrmgr.h"
  17. #include "extwrap.h"
  18. #include "..\rstrcore\resource.h"
  19. #define MAX_STR_DATETIME 256
  20. #define MAX_STR_MESSAGE 1024
  21. /*
  22. #define PROGRESSBAR_INITIALIZING_MAXVAL 30
  23. #define PROGRESSBAR_AFTER_INITIALIZING 30
  24. #define PROGRESSBAR_AFTER_RESTORE_MAP 40
  25. #define PROGRESSBAR_AFTER_RESTORE 100
  26. */
  27. #define GET_FLAG(mask) ( ( m_dwFlags & (mask) ) != 0 )
  28. #define SET_FLAG(mask,val) ( (val) ? ( m_dwFlags |= (mask) ) : ( m_dwFlags &= ~(mask) ) )
  29. /////////////////////////////////////////////////////////////////////////////
  30. //
  31. // CSRTime
  32. //
  33. /////////////////////////////////////////////////////////////////////////////
  34. CSRTime::CSRTime()
  35. {
  36. SetToCurrent();
  37. }
  38. const CSRTime& CSRTime::operator=( const CSRTime &cSrc )
  39. {
  40. TraceFunctEnter("CSRTime::operator=");
  41. m_st = cSrc.m_st;
  42. TraceFunctLeave();
  43. return( *this );
  44. }
  45. PSYSTEMTIME CSRTime::GetTime()
  46. {
  47. TraceFunctEnter("CSRTime::GetTime -> SYSTEMTIME*");
  48. TraceFunctLeave();
  49. return( &m_st );
  50. }
  51. void CSRTime::GetTime( PSYSTEMTIME pst )
  52. {
  53. TraceFunctEnter("CSRTime::GetTime -> SYSTEMTIME*");
  54. *pst = m_st;
  55. TraceFunctLeave();
  56. }
  57. BOOL CSRTime::GetTime( PFILETIME pft )
  58. {
  59. TraceFunctEnter("CSRTime::GetTime -> FILETIME*");
  60. BOOL fRet = FALSE;
  61. if ( !::SystemTimeToFileTime( &m_st, pft ) )
  62. {
  63. LPCWSTR cszErr = ::GetSysErrStr();
  64. ErrorTrace(TRACE_ID, "::SystemTimeToFileTime failed - %ls", cszErr);
  65. goto Exit;
  66. }
  67. fRet = TRUE;
  68. Exit:
  69. TraceFunctLeave();
  70. return( fRet );
  71. }
  72. #define COMPARE_AND_EXIT_ON_DIFF(a,b) \
  73. nDiff = (a) - (b); \
  74. if ( nDiff != 0 ) \
  75. goto Exit; \
  76. int CSRTime::Compare( CSRTime &cTime )
  77. {
  78. TraceFunctEnter("CSRTime::Compare");
  79. int nDiff;
  80. SYSTEMTIME *st = cTime.GetTime();
  81. COMPARE_AND_EXIT_ON_DIFF( m_st.wYear, st->wYear );
  82. COMPARE_AND_EXIT_ON_DIFF( m_st.wMonth, st->wMonth );
  83. COMPARE_AND_EXIT_ON_DIFF( m_st.wDay, st->wDay );
  84. COMPARE_AND_EXIT_ON_DIFF( m_st.wHour, st->wYear );
  85. COMPARE_AND_EXIT_ON_DIFF( m_st.wMinute, st->wMonth );
  86. COMPARE_AND_EXIT_ON_DIFF( m_st.wSecond, st->wDay );
  87. COMPARE_AND_EXIT_ON_DIFF( m_st.wMilliseconds, st->wDay );
  88. Exit:
  89. TraceFunctLeave();
  90. return( nDiff );
  91. }
  92. int CSRTime::CompareDate( CSRTime &cTime )
  93. {
  94. TraceFunctEnter("CSRTime::CompareDate");
  95. int nDiff;
  96. SYSTEMTIME *st = cTime.GetTime();
  97. COMPARE_AND_EXIT_ON_DIFF( m_st.wYear, st->wYear );
  98. COMPARE_AND_EXIT_ON_DIFF( m_st.wMonth, st->wMonth );
  99. COMPARE_AND_EXIT_ON_DIFF( m_st.wDay, st->wDay );
  100. Exit:
  101. TraceFunctLeave();
  102. return( nDiff );
  103. }
  104. BOOL CSRTime::SetTime( PFILETIME pft, BOOL fLocal )
  105. {
  106. TraceFunctEnter("CSRTime::SetFileTime");
  107. BOOL fRet = FALSE;
  108. FILETIME ft;
  109. SYSTEMTIME st;
  110. if ( !fLocal )
  111. {
  112. if ( !::FileTimeToLocalFileTime( pft, &ft ) )
  113. {
  114. LPCWSTR cszErr = ::GetSysErrStr();
  115. ErrorTrace(TRACE_ID, "::FileTimeToLocalFileTime failed - %ls", cszErr);
  116. goto Exit;
  117. }
  118. }
  119. else
  120. ft = *pft;
  121. if ( !::FileTimeToSystemTime( &ft, &st ) )
  122. {
  123. LPCWSTR cszErr = ::GetSysErrStr();
  124. ErrorTrace(TRACE_ID, "::FileTimeToSystemTime failed - %ls", cszErr);
  125. goto Exit;
  126. }
  127. m_st = st;
  128. fRet = TRUE;
  129. Exit:
  130. TraceFunctLeave();
  131. return( fRet );
  132. }
  133. void CSRTime::SetTime( PSYSTEMTIME st )
  134. {
  135. TraceFunctEnter("CSRTime::SetSysTime");
  136. m_st = *st;
  137. TraceFunctLeave();
  138. }
  139. void CSRTime::SetToCurrent()
  140. {
  141. TraceFunctEnter("CSRTime::SetToCurrent");
  142. ::GetLocalTime( &m_st );
  143. TraceFunctLeave();
  144. }
  145. /////////////////////////////////////////////////////////////////////////////
  146. //
  147. // CRestoreManager
  148. //
  149. /////////////////////////////////////////////////////////////////////////////
  150. BOOL CreateRestoreManagerInstance( CRestoreManager **ppMgr )
  151. {
  152. TraceFunctEnter("CreateRestoreManagerInstance");
  153. BOOL fRet = FALSE;
  154. if ( ppMgr == NULL )
  155. {
  156. FatalTrace(TRACE_ID, "Invalid parameter, ppMgr is NULL...");
  157. goto Exit;
  158. }
  159. *ppMgr = new CRestoreManager;
  160. if ( *ppMgr == NULL )
  161. {
  162. FatalTrace(TRACE_ID, "Cannot create CRestoreManager instance...");
  163. goto Exit;
  164. }
  165. fRet = TRUE;
  166. Exit:
  167. TraceFunctLeave();
  168. return( fRet );
  169. }
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CRestoreManager construction
  172. CRestoreManager::CRestoreManager()
  173. {
  174. TraceFunctEnter("CRestoreManager::CRestoreManager");
  175. m_nStartMode = SRRSM_NORMAL;
  176. m_fNeedReboot = FALSE;
  177. m_hwndFrame = NULL;
  178. m_nMainOption = RMO_RESTORE;
  179. //m_nStatus = SRRMS_NONE;
  180. m_fDenyClose = FALSE;
  181. m_dwFlags = 0;
  182. m_dwFlagsEx = 0;
  183. m_nSelectedRP = 0;
  184. m_nRealPoint = 0;
  185. m_ullManualRP = 0;
  186. m_nRPUsed = -1;
  187. m_nRPNew = -1;
  188. //m_nRPI = 0;
  189. //m_aryRPI = NULL;
  190. m_nLastRestore = -1;
  191. m_pCtx =NULL;
  192. //m_nRFI = 0;
  193. //m_aryRFI = NULL;
  194. //DisableArchiving( FALSE );
  195. TraceFunctLeave();
  196. }
  197. CRestoreManager::~CRestoreManager()
  198. {
  199. TraceFunctEnter("CRestoreManager::~CRestoreManager");
  200. Cleanup();
  201. TraceFunctLeave();
  202. }
  203. void CRestoreManager::Release()
  204. {
  205. TraceFunctEnter("CRestoreManager::Release");
  206. delete this;
  207. TraceFunctLeave();
  208. }
  209. void FormatDriveNameProperly(WCHAR * pszDrive)
  210. {
  211. WCHAR * pszIndex;
  212. pszIndex = wcschr( pszDrive, L':' );
  213. if (NULL != pszIndex)
  214. {
  215. *pszIndex = L'\0';
  216. }
  217. }
  218. /////////////////////////////////////////////////////////////////////////////
  219. // CRestoreManager properties - Common
  220. BOOL CRestoreManager::CanRunRestore( BOOL fThawIfFrozen )
  221. {
  222. TraceFunctEnter("CRestoreManager::CanRunRestore");
  223. BOOL fRet = FALSE;
  224. LPCWSTR cszErr;
  225. DWORD fDisable = FALSE;
  226. DWORD dwDSMin;
  227. DWORD dwRes, dwType, cbData;
  228. WCHAR szMsg[MAX_STR_MSG];
  229. WCHAR szTitle[MAX_STR_TITLE];
  230. ULARGE_INTEGER ulTotal, ulAvail, ulFree;
  231. WCHAR szSystemDrive[10], szSystemDriveCopy[10];
  232. // Check if SR is disabled via group policy
  233. if ( ::SRGetRegDword( HKEY_LOCAL_MACHINE, s_cszGroupPolicy, s_cszDisableSR, &fDisable ) && fDisable)
  234. {
  235. ErrorTrace(0, "SR is DISABLED by group policy!!!");
  236. ::ShowSRErrDlg( IDS_ERR_SR_DISABLED_GROUP_POLICY );
  237. goto Exit;
  238. }
  239. fDisable = FALSE;
  240. // Check if SR is disabled
  241. if ( !::SRGetRegDword( HKEY_LOCAL_MACHINE, s_cszSRRegKey, s_cszDisableSR, &fDisable ) )
  242. goto Exit;
  243. if ( fDisable )
  244. {
  245. ErrorTrace(0, "SR is DISABLED!!!");
  246. //
  247. // if safemode, show different error message
  248. //
  249. if (0 != GetSystemMetrics(SM_CLEANBOOT))
  250. {
  251. ShowSRErrDlg(IDS_RESTORE_SAFEMODE);
  252. goto Exit;
  253. }
  254. if ( ::LoadString( g_hInst, IDS_ERR_SR_DISABLED,
  255. szMsg, MAX_STR_MESSAGE ) == 0 )
  256. {
  257. cszErr = ::GetSysErrStr();
  258. ErrorTrace(0, "::LoadString(%u) failed - %ls", IDS_ERR_SR_DISABLED,
  259. cszErr);
  260. goto Exit;
  261. }
  262. if ( ::LoadString( g_hInst, IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE ) == 0 )
  263. {
  264. cszErr = ::GetSysErrStr();
  265. ErrorTrace(0, "::LoadString(%u) failed - %ls", IDS_RESTOREUI_TITLE, cszErr);
  266. // continue anyway...
  267. }
  268. if ( ::MessageBox( NULL, szMsg, szTitle, MB_YESNO ) == IDYES )
  269. {
  270. STARTUPINFO sSI;
  271. PROCESS_INFORMATION sPI;
  272. WCHAR szCmdLine[MAX_PATH] = L"control sysdm.cpl,,4";
  273. ZeroMemory (&sSI, sizeof(sSI));
  274. sSI.cb = sizeof(sSI);
  275. if ( !::CreateProcess( NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &sSI, &sPI ) )
  276. {
  277. cszErr = ::GetSysErrStr();
  278. ErrorTrace(0, "::CreateProcess failed - %ls", cszErr);
  279. goto Exit;
  280. }
  281. ::CloseHandle( sPI.hThread );
  282. ::CloseHandle( sPI.hProcess );
  283. }
  284. goto Exit;
  285. }
  286. // Check if service is running
  287. if ( FALSE == IsSRServiceRunning())
  288. {
  289. ErrorTrace(0, "Service is not running...");
  290. ::ShowSRErrDlg( IDS_ERR_SERVICE_DEAD );
  291. goto Exit;
  292. }
  293. // get free disk space
  294. ulTotal.QuadPart = 0;
  295. ulAvail.QuadPart = 0;
  296. ulFree.QuadPart = 0;
  297. if ( FALSE == GetSystemDrive( szSystemDrive ) )
  298. {
  299. ErrorTrace(0, "SR cannot get system drive!!!");
  300. goto CheckSRAgain;
  301. }
  302. if ( szSystemDrive[2] != L'\\' )
  303. szSystemDrive[2] = L'\\';
  304. // Check if SR is frozen
  305. if ( fThawIfFrozen && ::IsSRFrozen() )
  306. {
  307. ErrorTrace(0, "SR is Frozen!!!");
  308. if ( FALSE == GetDiskFreeSpaceEx( szSystemDrive,
  309. &ulAvail,
  310. &ulTotal,
  311. &ulFree ) )
  312. {
  313. ErrorTrace(0, "SR cannot get free disk space!!!");
  314. goto CheckSRAgain;
  315. }
  316. if ( !::SRGetRegDword( HKEY_LOCAL_MACHINE, s_cszSRRegKey, s_cszDSMin, &dwDSMin ) )
  317. dwDSMin = SR_DEFAULT_DSMIN;
  318. if ( ulFree.QuadPart >= (dwDSMin * MEGABYTE) )
  319. {
  320. STATEMGRSTATUS sMgrStatus;
  321. RESTOREPOINTINFO sRPInfo;
  322. // Thaw SR by creating a restore point
  323. sRPInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
  324. sRPInfo.dwRestorePtType = CHECKPOINT;
  325. sRPInfo.llSequenceNumber = 0;
  326. if (ERROR_SUCCESS != SRLoadString(L"srrstr.dll", IDS_SYSTEM_CHECKPOINT_TEXT, sRPInfo.szDescription, MAX_PATH))
  327. {
  328. lstrcpy(sRPInfo.szDescription, s_cszSystemCheckpointName);
  329. }
  330. if ( !::SRSetRestorePoint( &sRPInfo, &sMgrStatus ) )
  331. {
  332. ErrorTrace(TRACE_ID, "SRSetRestorePoint failed");
  333. goto CheckSRAgain;
  334. }
  335. }
  336. }
  337. CheckSRAgain:
  338. // Check if SR is frozen
  339. if ( ::IsSRFrozen() )
  340. {
  341. if ( !::SRGetRegDword( HKEY_LOCAL_MACHINE, s_cszSRRegKey, s_cszDSMin, &dwDSMin ) )
  342. {
  343. dwDSMin = SR_DEFAULT_DSMIN;
  344. }
  345. lstrcpy(szSystemDriveCopy, szSystemDrive);
  346. FormatDriveNameProperly(szSystemDriveCopy);
  347. ::SRFormatMessage( szMsg, IDS_ERR_SR_FROZEN, dwDSMin,
  348. szSystemDriveCopy );
  349. if ( ::LoadString( g_hInst, IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE ) == 0 )
  350. {
  351. cszErr = ::GetSysErrStr();
  352. ErrorTrace(0, "::LoadString(%u) failed - %ls", IDS_RESTOREUI_TITLE, cszErr);
  353. // continue anyway...
  354. }
  355. if ( ::MessageBox( NULL, szMsg, szTitle, MB_YESNO ) == IDYES )
  356. {
  357. ::InvokeDiskCleanup( szSystemDrive );
  358. }
  359. goto Exit;
  360. }
  361. // check if there is enough free space for restore to operate without freezing
  362. // needed free space = 60mb for restoration + 20 mb for restore restore point
  363. if (FALSE == GetDiskFreeSpaceEx(szSystemDrive,
  364. &ulAvail,
  365. &ulTotal,
  366. &ulFree))
  367. {
  368. ErrorTrace(0, "! GetDiskFreeSpaceEx : %ld", GetLastError());
  369. goto Exit;
  370. }
  371. if (ulFree.QuadPart <= THRESHOLD_UI_DISKSPACE * MEGABYTE)
  372. {
  373. DebugTrace(0, "***Less than 80MB free - cannot run restore***");
  374. ::SRFormatMessage( szMsg, IDS_ERR_SR_LOWDISK, THRESHOLD_UI_DISKSPACE, szSystemDrive );
  375. if ( ::LoadString( g_hInst, IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE ) == 0 )
  376. {
  377. cszErr = ::GetSysErrStr();
  378. ErrorTrace(0, "::LoadString(%u) failed - %ls", IDS_RESTOREUI_TITLE, cszErr);
  379. // continue anyway...
  380. }
  381. if ( ::MessageBox( NULL, szMsg, szTitle, MB_YESNO ) == IDYES )
  382. {
  383. ::InvokeDiskCleanup( szSystemDrive );
  384. }
  385. goto Exit;
  386. }
  387. fRet = TRUE;
  388. Exit:
  389. TraceFunctLeave();
  390. return( fRet );
  391. }
  392. /***************************************************************************/
  393. int CRestoreManager::GetFirstDayOfWeek()
  394. {
  395. TraceFunctEnter("CRestoreManager::GetFirstDayOfWeek");
  396. int nFirstDay = -1;
  397. WCHAR szBuf[100];
  398. int nRet;
  399. int nDay;
  400. nRet = ::GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
  401. szBuf, sizeof(szBuf)/sizeof(WCHAR));
  402. if ( nRet == 0 )
  403. {
  404. LPCWSTR cszErr = ::GetSysErrStr();
  405. ErrorTrace(TRACE_ID, "GetLocaleInfo(IFIRSTDAYOFWEEK) failed - %ls", cszErr);
  406. goto Exit;
  407. }
  408. nDay = ::_wtoi( szBuf );
  409. if ( nDay < 0 || nDay > 6 )
  410. {
  411. ErrorTrace(TRACE_ID, "Out of range, IFIRSTDAYOFWEEK = %d", nDay);
  412. goto Exit;
  413. }
  414. DebugTrace(TRACE_ID, "nFirstDay=%d", nFirstDay);
  415. nFirstDay = nDay;
  416. Exit:
  417. TraceFunctLeave();
  418. return( nFirstDay );
  419. }
  420. /***************************************************************************/
  421. BOOL CRestoreManager::GetIsRPSelected()
  422. {
  423. TraceFunctEnter("CRestoreManager::GetIsRPSelected");
  424. TraceFunctLeave();
  425. return( GET_FLAG( SRRMF_ISRPSELECTED ) );
  426. }
  427. /***************************************************************************/
  428. BOOL CRestoreManager::GetIsSafeMode()
  429. {
  430. TraceFunctEnter("CRestoreManager::GetIsSafeMode");
  431. BOOL fIsSafeMode;
  432. fIsSafeMode = ( ::GetSystemMetrics( SM_CLEANBOOT ) != 0 );
  433. TraceFunctLeave();
  434. return( fIsSafeMode );
  435. }
  436. /***************************************************************************/
  437. BOOL CRestoreManager::GetIsSmgrAvailable()
  438. {
  439. TraceFunctEnter("CRestoreManager::GetIsSmgrAvailable");
  440. #if BUGBUG //NYI
  441. WCHAR szTitle[MAX_STR_TITLE];
  442. WCHAR szFmt[MAX_STR_MSG];
  443. WCHAR szMsg[MAX_STR_MSG];
  444. DWORD dwType, dwValue, dwSize, dwRet;
  445. WCHAR szBuf[16];
  446. HRESULT hr = S_OK;
  447. BOOL fSmgrUnavailable = FALSE ;
  448. VALIDATE_INPUT_ARGUMENT(pfSmgr);
  449. //
  450. // If StateMgr is not alive
  451. //
  452. if ( NULL == FindWindow(s_cszIDCSTATEMGRPROC, s_cszIDSAPPTITLE))
  453. {
  454. PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  455. PCHLoadString( IDS_ERR_RSTR_SMGR_NOT_ALIVE, szMsg, MAX_STR_MSG );
  456. ::MessageBox( m_hWndShell, szMsg, szTitle, MB_OK | MB_ICONINFORMATION );
  457. fSmgrUnavailable = TRUE ;
  458. }
  459. //
  460. // If SM is frozen
  461. //
  462. dwType = REG_DWORD;
  463. dwSize = sizeof(dwValue);
  464. dwRet = ::SHGetValue(HKEY_LOCAL_MACHINE,
  465. s_cszReservedDiskSpaceKey,
  466. s_cszStatus, &dwType, &dwValue, &dwSize );
  467. if ( dwRet == ERROR_SUCCESS && dwValue == SMCONFIG_FROZEN )
  468. {
  469. dwType = REG_DWORD;
  470. dwSize = sizeof(DWORD);
  471. dwRet = ::SHGetValue(HKEY_LOCAL_MACHINE,
  472. s_cszReservedDiskSpaceKey,
  473. s_cszMin, &dwType, &dwValue, &dwSize );
  474. if ( dwRet != ERROR_SUCCESS || dwValue == 0 )
  475. dwValue = SMCONFIG_MIN;
  476. PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  477. PCHLoadString( IDS_RESTORE_SMFROZEN, szFmt, MAX_STR_MSG );
  478. ::wsprintf( szMsg, szFmt, dwValue );
  479. ::MessageBox( m_hWndShell, szMsg, szTitle, MB_OK | MB_ICONINFORMATION );
  480. fSmgrUnavailable = TRUE ;
  481. }
  482. else {
  483. //
  484. // If SR is disabled
  485. //
  486. dwType = REG_SZ;
  487. dwSize = sizeof(szBuf)-1;
  488. dwRet = ::SHGetValue( HKEY_LOCAL_MACHINE,
  489. L"System\\CurrentControlSet\\Services\\VxD\\VxDMon",
  490. L"SystemRestore", &dwType, szBuf, &dwSize );
  491. if ( dwRet != ERROR_SUCCESS || StrCmpI( szBuf, L"Y" ) != 0 )
  492. {
  493. PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  494. PCHLoadString( IDS_RESTORE_DISABLED, szMsg, MAX_STR_MSG );
  495. ::MessageBox( m_hWndShell, szMsg, szTitle, MB_OK | MB_ICONINFORMATION );
  496. fSmgrUnavailable = TRUE ;
  497. }
  498. };
  499. if ( fSmgrUnavailable ) {
  500. *pfSmgr = VARIANT_TRUE ;
  501. }
  502. else
  503. *pfSmgr = VARIANT_FALSE ;
  504. #endif //BUGBUG
  505. TraceFunctLeave();
  506. return( TRUE );
  507. }
  508. /***************************************************************************/
  509. BOOL CRestoreManager::GetIsUndo()
  510. {
  511. TraceFunctEnter("CRestoreManager::GetIsUndo");
  512. TraceFunctLeave();
  513. return( GET_FLAG( SRRMF_ISUNDO ) );
  514. }
  515. /***************************************************************************/
  516. int CRestoreManager::GetLastRestore()
  517. {
  518. TraceFunctEnter("CRestoreManager::GetLastRestore");
  519. int nLastRP;
  520. if ( UpdateRestorePointList() )
  521. nLastRP = m_nLastRestore;
  522. else
  523. nLastRP = -1;
  524. TraceFunctLeave();
  525. return( nLastRP );
  526. }
  527. /***************************************************************************/
  528. int CRestoreManager::GetMainOption()
  529. {
  530. TraceFunctEnter("CRestoreManager::GetMainOption");
  531. TraceFunctLeave();
  532. return( m_nMainOption );
  533. }
  534. /***************************************************************************/
  535. LPCWSTR CRestoreManager::GetManualRPName()
  536. {
  537. TraceFunctEnter("CRestoreManager::GetManualRPName");
  538. TraceFunctLeave();
  539. return( m_strManualRP );
  540. }
  541. /***************************************************************************/
  542. void CRestoreManager::GetMaxDate( PSYSTEMTIME pstMax )
  543. {
  544. TraceFunctEnter("CRestoreManager::GetMaxDate");
  545. m_stRPMax.GetTime( pstMax );
  546. TraceFunctLeave();
  547. }
  548. /***************************************************************************/
  549. void CRestoreManager::GetMinDate( PSYSTEMTIME pstMin )
  550. {
  551. TraceFunctEnter("CRestoreManager::GetMinDate");
  552. m_stRPMin.GetTime( pstMin );
  553. TraceFunctLeave();
  554. }
  555. /***************************************************************************/
  556. int CRestoreManager::GetRealPoint()
  557. {
  558. TraceFunctEnter("CRestoreManager::GetRealPoint");
  559. TraceFunctLeave();
  560. return( m_nRealPoint );
  561. }
  562. /***************************************************************************/
  563. PSRFI CRestoreManager::GetRFI( int nIndex )
  564. {
  565. TraceFunctEnter("CRestoreManager::GetRFI");
  566. PSRFI pRet = NULL;
  567. if ( nIndex < 0 || nIndex >= m_aryRFI.GetSize() )
  568. {
  569. ErrorTrace(TRACE_ID, "Out of range, nIndex=%d - m_nRFI=%d", nIndex, m_aryRFI.GetSize());
  570. goto Exit;
  571. }
  572. pRet = m_aryRFI[nIndex];
  573. if ( pRet == NULL )
  574. {
  575. ErrorTrace(TRACE_ID, "FATAL, entry is NULL: nIndex=%d, m_nRFI=%d", nIndex, m_aryRFI.GetSize());
  576. goto Exit;
  577. }
  578. Exit:
  579. TraceFunctLeave();
  580. return( pRet );
  581. }
  582. /***************************************************************************/
  583. int CRestoreManager::GetRFICount()
  584. {
  585. TraceFunctEnter("CRestoreManager::GetRFICount");
  586. TraceFunctLeave();
  587. return( m_aryRFI.GetSize() );
  588. }
  589. /***************************************************************************/
  590. PSRPI CRestoreManager::GetRPI( int nIndex )
  591. {
  592. TraceFunctEnter("CRestoreManager::GetRPI");
  593. PSRPI pRet = NULL;
  594. if ( nIndex < 0 || nIndex >= m_aryRPI.GetSize() )
  595. {
  596. ErrorTrace(TRACE_ID, "Out of range, nIndex=%d - m_nRPI=%d", nIndex, m_aryRPI.GetSize());
  597. goto Exit;
  598. }
  599. pRet = m_aryRPI[nIndex];
  600. if ( pRet == NULL )
  601. {
  602. ErrorTrace(TRACE_ID, "FATAL, entry is NULL: nIndex=%d, m_nRPI=%d", nIndex, m_aryRPI.GetSize());
  603. goto Exit;
  604. }
  605. Exit:
  606. TraceFunctLeave();
  607. return( pRet );
  608. }
  609. /***************************************************************************/
  610. int CRestoreManager::GetRPICount()
  611. {
  612. TraceFunctEnter("CRestoreManager::GetRPICount");
  613. TraceFunctLeave();
  614. return( m_aryRPI.GetSize() );
  615. }
  616. /***************************************************************************/
  617. void CRestoreManager::GetSelectedDate( PSYSTEMTIME pstSel )
  618. {
  619. TraceFunctEnter("CRestoreManager::GetSelectedDate");
  620. m_stSelected.GetTime( pstSel );
  621. TraceFunctLeave();
  622. }
  623. /***************************************************************************/
  624. LPCWSTR CRestoreManager::GetSelectedName()
  625. {
  626. TraceFunctEnter("CRestoreManager::GetSelectedName");
  627. TraceFunctLeave();
  628. return( m_strSelected );
  629. }
  630. /***************************************************************************/
  631. int CRestoreManager::GetSelectedPoint()
  632. {
  633. TraceFunctEnter("CRestoreManager::GetSelectedPoint");
  634. TraceFunctLeave();
  635. return( m_nSelectedRP );
  636. }
  637. /***************************************************************************/
  638. int CRestoreManager::GetStartMode()
  639. {
  640. TraceFunctEnter("CRestoreManager::GetStartMode");
  641. TraceFunctLeave();
  642. return( m_nStartMode );
  643. }
  644. /***************************************************************************/
  645. void CRestoreManager::GetToday( PSYSTEMTIME pstToday )
  646. {
  647. TraceFunctEnter("CRestoreManager::GetToday");
  648. m_stToday.GetTime( pstToday );
  649. TraceFunctLeave();
  650. }
  651. /***************************************************************************/
  652. void CRestoreManager::SetIsRPSelected( BOOL fSel )
  653. {
  654. TraceFunctEnter("CRestoreManager::SetIsRPSelected");
  655. SET_FLAG( SRRMF_ISRPSELECTED, fSel );
  656. TraceFunctLeave();
  657. }
  658. /***************************************************************************/
  659. void CRestoreManager::SetIsUndo( BOOL fUndo )
  660. {
  661. TraceFunctEnter("CRestoreManager::SetIsUndo");
  662. SET_FLAG( SRRMF_ISUNDO, fUndo );
  663. TraceFunctLeave();
  664. }
  665. /***************************************************************************/
  666. BOOL CRestoreManager::SetMainOption( int nOpt )
  667. {
  668. TraceFunctEnter("CRestoreManager::SetMainOption");
  669. BOOL fRet = FALSE;
  670. if ( nOpt >= RMO_RESTORE && nOpt < RMO_MAX )
  671. {
  672. m_nMainOption = nOpt;
  673. fRet = TRUE;
  674. }
  675. TraceFunctLeave();
  676. return( fRet );
  677. }
  678. /***************************************************************************/
  679. void CRestoreManager::SetManualRPName( LPCWSTR cszRPName )
  680. {
  681. TraceFunctEnter("CRestoreManager::SetManualRPName");
  682. m_strManualRP = cszRPName;
  683. TraceFunctLeave();
  684. }
  685. /***************************************************************************/
  686. void CRestoreManager::SetSelectedDate( PSYSTEMTIME pstSel )
  687. {
  688. TraceFunctEnter("CRestoreManager::SetSelectedDate");
  689. int nTop;
  690. int i;
  691. m_stSelected.SetTime( pstSel );
  692. if ( m_aryRPI.GetSize() == 0 )
  693. goto Exit;
  694. nTop = 0;
  695. for ( i = m_aryRPI.GetUpperBound(); i > 0; i-- ) // exclude 0
  696. {
  697. CSRTime &rst = m_aryRPI[i]->stTimeStamp;
  698. if ( m_stSelected.CompareDate( rst ) < 0 )
  699. continue;
  700. if ( rst.Compare( m_aryRPI[nTop]->stTimeStamp ) > 0 )
  701. nTop = i;
  702. }
  703. m_nRealPoint = nTop;
  704. Exit:
  705. TraceFunctLeave();
  706. }
  707. /***************************************************************************/
  708. BOOL CRestoreManager::SetSelectedPoint( int nRP )
  709. {
  710. TraceFunctEnter("CRestoreManager::SetSelectedPoint");
  711. BOOL fRet = FALSE;
  712. if ( nRP < 0 || nRP >= m_aryRPI.GetSize() )
  713. {
  714. ErrorTrace(TRACE_ID, "Index is out of range");
  715. goto Exit;
  716. }
  717. // Set a flag to indicate a RP has been selected
  718. SetIsRPSelected( TRUE );
  719. // Set selected time
  720. m_stSelected = m_aryRPI[nRP]->stTimeStamp;
  721. m_nSelectedRP = nRP;
  722. m_nRealPoint = nRP;
  723. UpdateRestorePoint();
  724. fRet = TRUE;
  725. Exit:
  726. TraceFunctLeave();
  727. return( fRet );
  728. }
  729. /***************************************************************************/
  730. BOOL CRestoreManager::SetStartMode( int nMode )
  731. {
  732. TraceFunctEnter("CRestoreManager::SetStartMode");
  733. BOOL fRet = FALSE;
  734. m_nStartMode = nMode;
  735. if ( nMode != SRRSM_NORMAL )
  736. {
  737. //if ( !LoadSettings() )
  738. // goto Exit;
  739. }
  740. fRet = TRUE;
  741. //Exit:
  742. TraceFunctLeave();
  743. return( fRet );
  744. }
  745. /***************************************************************************/
  746. void CRestoreManager::GetUsedDate( PSYSTEMTIME pstDate )
  747. {
  748. TraceFunctEnter("CRestoreManager::GetUsedDate");
  749. int i;
  750. m_stToday.GetTime( pstDate );
  751. if ( m_nRPUsed <= 0 )
  752. goto Exit;
  753. for ( i = m_aryRPI.GetUpperBound(); i >= 0; i-- )
  754. if ( m_aryRPI[i]->dwNum == (DWORD)m_nRPUsed )
  755. {
  756. m_aryRPI[i]->stTimeStamp.GetTime( pstDate );
  757. break;
  758. }
  759. Exit:
  760. TraceFunctLeave();
  761. }
  762. /***************************************************************************/
  763. LPCWSTR CRestoreManager::GetUsedName()
  764. {
  765. TraceFunctEnter("CRestoreManager::GetUsedName");
  766. LPCWSTR cszName = NULL;
  767. int i;
  768. if ( m_nRPUsed <= 0 )
  769. goto Exit;
  770. for ( i = m_aryRPI.GetUpperBound(); i >= 0; i-- )
  771. if ( m_aryRPI[i]->dwNum == (DWORD)m_nRPUsed )
  772. {
  773. cszName = m_aryRPI[i]->strName;
  774. break;
  775. }
  776. Exit:
  777. TraceFunctLeave();
  778. return( cszName );
  779. }
  780. /***************************************************************************/
  781. DWORD CRestoreManager::GetUsedType()
  782. {
  783. TraceFunctEnter("CRestoreManager::GetUsedType");
  784. DWORD dwType = -1;
  785. int i;
  786. if ( m_nRPUsed <= 0 )
  787. goto Exit;
  788. for ( i = m_aryRPI.GetUpperBound(); i >= 0; i-- )
  789. if ( m_aryRPI[i]->dwNum == (DWORD)m_nRPUsed )
  790. {
  791. dwType = m_aryRPI[i]->dwType;
  792. break;
  793. }
  794. Exit:
  795. TraceFunctLeave();
  796. return( dwType );
  797. }
  798. /////////////////////////////////////////////////////////////////////////////
  799. // CRestoreManager properties - HTML UI specific
  800. BOOL CRestoreManager::GetCanNavigatePage()
  801. {
  802. TraceFunctEnter("CRestoreManager::GetCanNavigatePage");
  803. TraceFunctLeave();
  804. return( GET_FLAG( SRRMF_CANNAVIGATEPAGE ) );
  805. }
  806. void CRestoreManager::SetCanNavigatePage( BOOL fCanNav )
  807. {
  808. TraceFunctEnter("CRestoreManager::SetCanNavigatePage");
  809. SET_FLAG( SRRMF_CANNAVIGATEPAGE, fCanNav );
  810. TraceFunctLeave();
  811. }
  812. /////////////////////////////////////////////////////////////////////////////
  813. // CRestoreManager properties
  814. PSRPI CRestoreManager::GetUsedRP()
  815. {
  816. TraceFunctEnter("CRestoreManager::GetUsedRP");
  817. PSRPI pRPI = NULL;
  818. int i;
  819. if ( m_nRPUsed <= 0 )
  820. goto Exit;
  821. for ( i = m_aryRPI.GetUpperBound(); i >= 0; i-- )
  822. if ( m_aryRPI[i]->dwNum == (DWORD)m_nRPUsed )
  823. {
  824. pRPI = m_aryRPI[i];
  825. goto Exit;
  826. }
  827. Exit:
  828. TraceFunctLeave();
  829. return( pRPI );
  830. }
  831. int CRestoreManager::GetNewRP()
  832. {
  833. TraceFunctEnter("CRestoreManager::GetNewRP");
  834. TraceFunctLeave();
  835. return( m_nRPNew );
  836. }
  837. BOOL CRestoreManager::CheckForDomainChange (WCHAR *pwszFilename, WCHAR *pszMsg)
  838. {
  839. BOOL fError = FALSE;
  840. WCHAR wcsCurrent [MAX_PATH];
  841. WCHAR wcsFile [MAX_PATH];
  842. WCHAR szMsg [MAX_STR_MSG];
  843. if (ERROR_SUCCESS == GetDomainMembershipInfo (NULL, wcsCurrent))
  844. {
  845. HANDLE hFile = CreateFileW ( pwszFilename, // file name
  846. GENERIC_READ, // file access
  847. 0, // share mode
  848. NULL, // SD
  849. OPEN_EXISTING, // how to create
  850. 0, // file attributes
  851. NULL); // handle to template file
  852. if (INVALID_HANDLE_VALUE != hFile)
  853. {
  854. DWORD dwSize = GetFileSize (hFile, NULL);
  855. DWORD cbRead;
  856. if (dwSize != 0xFFFFFFFF && dwSize < MAX_PATH &&
  857. (TRUE == ReadFile (hFile, (BYTE *) wcsFile,
  858. dwSize, &cbRead, NULL)))
  859. {
  860. if (memcmp (wcsCurrent, wcsFile, cbRead) != 0)
  861. fError = TRUE;
  862. }
  863. CloseHandle (hFile);
  864. }
  865. if (fError)
  866. {
  867. WCHAR szTitle[MAX_STR_TITLE];
  868. WCHAR szNone[MAX_STR_TITLE];
  869. WCHAR *pwszComputer2 = wcsFile;
  870. WCHAR *pwszDomain2 = pwszComputer2 + lstrlenW(pwszComputer2)+ 1;
  871. WCHAR *pwszFlag2 = pwszDomain2 + lstrlenW(pwszDomain2) + 1;
  872. WCHAR *pwszComputer1 = wcsCurrent;
  873. WCHAR *pwszDomain1 = pwszComputer1 + lstrlenW(pwszComputer1)+ 1;
  874. WCHAR *pwszFlag1 = pwszDomain1 + lstrlenW (pwszDomain1) + 1;
  875. WCHAR *pwszWorkgroup1 = NULL;
  876. WCHAR *pwszWorkgroup2 = NULL;
  877. if ( ::LoadString( g_hInst, IDS_NONE, szNone, MAX_STR_TITLE) == 0)
  878. {
  879. lstrcpy (szNone, L" "); // use blanks instead
  880. }
  881. pwszWorkgroup1 = szNone;
  882. pwszWorkgroup2 = szNone;
  883. if (pwszFlag1[0] != L'1') // change domain to workgroup
  884. {
  885. WCHAR *pTemp = pwszWorkgroup1;
  886. pwszWorkgroup1 = pwszDomain1;
  887. pwszDomain1 = pTemp;
  888. }
  889. if (pwszFlag2[0] != L'1') // change domain to workgroup
  890. {
  891. WCHAR *pTemp = pwszWorkgroup2;
  892. pwszWorkgroup2 = pwszDomain2;
  893. pwszDomain2 = pTemp;
  894. }
  895. PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  896. ::SRFormatMessage( pszMsg, IDS_ERR_DOMAIN_CHANGED,
  897. pwszComputer1, pwszComputer2,
  898. pwszWorkgroup1, pwszWorkgroup2,
  899. pwszDomain1, pwszDomain2 );
  900. ::MessageBox( m_hwndFrame, pszMsg, szTitle, MB_ICONWARNING | MB_DEFBUTTON2);
  901. }
  902. }
  903. return TRUE;
  904. }
  905. /////////////////////////////////////////////////////////////////////////////
  906. // CRestoreManager operations
  907. // Check Restore
  908. // this creates a restore context (m_pCtx) which will be used by BeginRestore
  909. BOOL CRestoreManager::CheckRestore( BOOL fSilent )
  910. {
  911. TraceFunctEnter("CRestoreManager::CheckRestore");
  912. BOOL fRet = FALSE;
  913. DWORD dwRP;
  914. WCHAR szTitle[MAX_STR_TITLE];
  915. WCHAR szMsg[MAX_STR_MSG];
  916. WCHAR szMsg1[MAX_STR_MSG];
  917. WCHAR szMsg2[MAX_STR_MSG];
  918. WCHAR szOfflineDrives[MAX_STR_MSG];
  919. m_fDenyClose = TRUE;
  920. // Disable FIFO starting from the chosen restore point.
  921. dwRP = m_aryRPI[m_nRealPoint]->dwNum;
  922. if ( !g_pExternal->DisableFIFO( dwRP ) )
  923. {
  924. ErrorTrace(0, "DisableFIFO(%d) failed...", dwRP);
  925. goto Exit;
  926. }
  927. if ( !::PrepareRestore( dwRP, &m_pCtx ) )
  928. {
  929. ErrorTrace(0, "Prepare Restore failed...");
  930. goto Exit;
  931. }
  932. if ( !fSilent )
  933. {
  934. //
  935. // Check if all drives are valid, if some drives are not valid ask user if
  936. // we should continue with the restore process
  937. //
  938. if ( m_pCtx->IsAnyDriveOfflineOrDisabled( szOfflineDrives ) )
  939. {
  940. PCHLoadString( IDS_RESTOREUI_TITLE, szTitle, MAX_STR_TITLE );
  941. PCHLoadString( IDS_ERR_ALL_DRIVES_NOT_ACTIVE1, szMsg1, MAX_STR_MSG );
  942. PCHLoadString( IDS_ERR_ALL_DRIVES_NOT_ACTIVE2, szMsg2, MAX_STR_MSG );
  943. ::wsprintf( szMsg, L"%s %s %s", szMsg1, szOfflineDrives, szMsg2 );
  944. ::MessageBox( m_hwndFrame, szMsg, szTitle,
  945. MB_ICONWARNING | MB_DEFBUTTON2);
  946. }
  947. }
  948. else
  949. {
  950. m_pCtx->SetSilent();
  951. }
  952. if (!fSilent)
  953. {
  954. WCHAR wcsFile [MAX_PATH];
  955. WCHAR wcsDrive [MAX_PATH / 2];
  956. GetSystemDrive (wcsDrive);
  957. MakeRestorePath( wcsFile, wcsDrive, m_aryRPI[m_nRealPoint]->strDir);
  958. lstrcat (wcsFile, L"\\snapshot\\domain.txt");
  959. CheckForDomainChange (wcsFile ,szMsg);
  960. }
  961. if (GET_FLAG(SRRMF_ISUNDO))
  962. {
  963. m_pCtx->SetUndo();
  964. }
  965. fRet = TRUE;
  966. Exit:
  967. m_fDenyClose = FALSE;
  968. if ( !fRet )
  969. SAFE_RELEASE(m_pCtx);
  970. TraceFunctLeave();
  971. return( fRet );
  972. }
  973. /////////////////////////////////////////////////////////////////////////////
  974. // CRestoreManager operations
  975. // this uses a restore context (m_pCtx) which was created by CheckRestore
  976. // CheckRestore must be called before this function is called
  977. BOOL CRestoreManager::BeginRestore( )
  978. {
  979. TraceFunctEnter("CRestoreManager::BeginRestore");
  980. BOOL fRet = FALSE;
  981. DWORD dwRP;
  982. DWORD dwNewRP;
  983. m_fDenyClose = TRUE;
  984. if (NULL == m_pCtx)
  985. {
  986. ErrorTrace(0, "m_pCtx is NULL");
  987. _ASSERT(0);
  988. goto Exit;
  989. }
  990. // Disable FIFO starting from the chosen restore point.
  991. dwRP = m_aryRPI[m_nRealPoint]->dwNum;
  992. if ( !g_pExternal->DisableFIFO( dwRP ) )
  993. {
  994. ErrorTrace(0, "DisableFIFO(%d) failed...", dwRP);
  995. goto Exit;
  996. }
  997. if ( !::InitiateRestore( m_pCtx, &dwNewRP ) )
  998. goto Exit;
  999. m_fNeedReboot = TRUE;
  1000. /*
  1001. if ( ::ExitWindowsEx( EWX_REBOOT, 0 ) )
  1002. {
  1003. DebugTrace(0, "ExitWindowsEx succeeded");
  1004. }
  1005. else
  1006. {
  1007. LPCWSTR cszErr = ::GetSysErrStr();
  1008. DebugTrace(0, "ExitWindowsEx failed - %ls", cszErr);
  1009. if ( !g_pExternal->RemoveRestorePoint( dwNewRP ) )
  1010. goto Exit;
  1011. goto Exit;
  1012. }
  1013. */
  1014. fRet = TRUE;
  1015. Exit:
  1016. m_fDenyClose = FALSE;
  1017. if ( !fRet )
  1018. SAFE_RELEASE(m_pCtx);
  1019. TraceFunctLeave();
  1020. return( fRet );
  1021. }
  1022. /***************************************************************************/
  1023. BOOL CRestoreManager::Cancel()
  1024. {
  1025. TraceFunctEnter("CRestoreManager::Cancel");
  1026. BOOL fRet = FALSE;
  1027. LPCWSTR cszErr;
  1028. WCHAR szTitle[256];
  1029. WCHAR szMsg[1024];
  1030. if ( m_fDenyClose )
  1031. goto Exit;
  1032. /*
  1033. if ( ::LoadString( g_hInst, IDS_RESTOREUI_TITLE, szTitle, sizeof(szTitle ) ) == 0 )
  1034. {
  1035. cszErr = ::GetSysErrStr();
  1036. ErrorTrace(0, "::LoadString(%u) failed - %ls", IDS_RESTOREUI_TITLE, cszErr);
  1037. goto Exit;
  1038. }
  1039. if ( ::LoadString( g_hInst, IDS_CANCEL_RESTORE, szMsg, sizeof(szMsg ) ) == 0 )
  1040. {
  1041. cszErr = ::GetSysErrStr();
  1042. ErrorTrace(0, "::LoadString(%u) failed - %ls", IDS_CANCEL_RESTORE, cszErr);
  1043. goto Exit;
  1044. }
  1045. if ( ::MessageBox( m_hwndFrame, szMsg, szTitle, MB_YESNO ) == IDNO )
  1046. goto Exit;
  1047. */
  1048. fRet = TRUE;
  1049. Exit:
  1050. TraceFunctLeave();
  1051. return( fRet );
  1052. }
  1053. /***************************************************************************/
  1054. BOOL CRestoreManager::CancelRestorePoint()
  1055. {
  1056. TraceFunctEnter("CRestoreManager::CancelRestorePoint");
  1057. BOOL fRet = FALSE;
  1058. RESTOREPOINTINFO sRPInfo;
  1059. STATEMGRSTATUS sSmgrStatus;
  1060. HCURSOR hCursor;
  1061. hCursor = ::SetCursor( ::LoadCursor( NULL, IDC_WAIT ) );
  1062. /*
  1063. sRPInfo.dwEventType = END_SYSTEM_CHANGE;
  1064. sRPInfo.dwRestorePtType = CANCELLED_OPERATION ;
  1065. sRPInfo.llSequenceNumber = m_ullManualRP;
  1066. //if ( !::SRSetRestorePoint( &sRPInfo, &sSmgrStatus ) )
  1067. if ( !g_pExternal->SetRestorePoint( &sRPInfo, &sSmgrStatus ) )
  1068. {
  1069. // Why SRSetRestorePoint returns FALSE even though it succeeded?
  1070. // 5/16/00 - would this work now?
  1071. //ErrorTrace(TRACE_ID, "SRSetRestorePoint cancellation failed");
  1072. goto Exit;
  1073. }
  1074. */
  1075. if ( !UpdateRestorePointList() )
  1076. goto Exit;
  1077. fRet = TRUE;
  1078. Exit:
  1079. if ( hCursor != NULL )
  1080. ::SetCursor( hCursor );
  1081. TraceFunctLeave();
  1082. return( fRet );
  1083. }
  1084. /***************************************************************************/
  1085. BOOL CRestoreManager::CreateRestorePoint()
  1086. {
  1087. TraceFunctEnter("CRestoreManager::CreateRestorePoint");
  1088. BOOL fRet = FALSE;
  1089. HCURSOR hCursor;
  1090. hCursor = ::SetCursor( ::LoadCursor( NULL, IDC_WAIT ) );
  1091. if ( !g_pExternal->SetRestorePoint( m_strManualRP, NULL ) )
  1092. goto Exit;
  1093. //m_ullManualRP = sSmgrStatus.llSequenceNumber;
  1094. if ( !UpdateRestorePointList() )
  1095. goto Exit;
  1096. fRet = TRUE;
  1097. Exit:
  1098. if ( hCursor != NULL )
  1099. ::SetCursor( hCursor );
  1100. TraceFunctLeave();
  1101. return( fRet );
  1102. }
  1103. /***************************************************************************/
  1104. BOOL CRestoreManager::DisableFIFO()
  1105. {
  1106. TraceFunctEnter("CRestoreManager::DisableFIFO");
  1107. BOOL fRet = FALSE;
  1108. DWORD dwSize;
  1109. if ( !g_pExternal->DisableFIFO( 1 ) )
  1110. {
  1111. ErrorTrace(TRACE_ID, "DisableFIFO(1) failed...");
  1112. goto Exit;
  1113. }
  1114. fRet = TRUE;
  1115. Exit:
  1116. TraceFunctLeave();
  1117. return( fRet );
  1118. }
  1119. /***************************************************************************/
  1120. BOOL CRestoreManager::EnableFIFO()
  1121. {
  1122. TraceFunctEnter("CRestoreManager::EnableFIFO");
  1123. BOOL fRet = FALSE;
  1124. DWORD dwSize;
  1125. if ( g_pExternal->EnableFIFO() != ERROR_SUCCESS )
  1126. {
  1127. ErrorTrace(TRACE_ID, "EnableFIFO() failed...");
  1128. goto Exit;
  1129. }
  1130. fRet = TRUE;
  1131. Exit:
  1132. TraceFunctLeave();
  1133. return( fRet );
  1134. }
  1135. /***************************************************************************/
  1136. BOOL CRestoreManager::FormatDate( PSYSTEMTIME pst, CSRStr &str, BOOL fLongFmt )
  1137. {
  1138. TraceFunctEnter("CRestoreManager::FormatDate");
  1139. BOOL fRet;
  1140. DWORD dwFlag;
  1141. dwFlag = fLongFmt ? DATE_LONGDATE : DATE_SHORTDATE;
  1142. fRet = GetDateStr( pst, str, dwFlag, NULL );
  1143. TraceFunctLeave();
  1144. return( fRet );
  1145. }
  1146. /***************************************************************************/
  1147. BOOL CRestoreManager::FormatLowDiskMsg( LPCWSTR cszFmt, CSRStr &str )
  1148. {
  1149. TraceFunctEnter("CRestoreManager::FormatLowDiskMsg");
  1150. BOOL fRet = FALSE;
  1151. DWORD dwSize;
  1152. WCHAR szBuf[MAX_STR_MESSAGE];
  1153. if ( !::SRGetRegDword( HKEY_LOCAL_MACHINE, s_cszSRRegKey, s_cszDSMin, &dwSize ) )
  1154. dwSize = SR_DEFAULT_DSMIN;
  1155. ::wsprintf( szBuf, cszFmt, dwSize );
  1156. str = szBuf;
  1157. fRet = TRUE;
  1158. TraceFunctLeave();
  1159. return( fRet );
  1160. }
  1161. /***************************************************************************/
  1162. BOOL CRestoreManager::FormatTime( PSYSTEMTIME pst, CSRStr &str )
  1163. {
  1164. TraceFunctEnter("CRestoreManager::FormatTime");
  1165. BOOL fRet;
  1166. fRet = GetTimeStr( pst, str, 0 );
  1167. TraceFunctLeave();
  1168. return( fRet );
  1169. }
  1170. /***************************************************************************/
  1171. BOOL CRestoreManager::GetLocaleDateFormat( PSYSTEMTIME pst, LPCWSTR cszFmt, CSRStr &str )
  1172. {
  1173. TraceFunctEnter("CRestoreManager::GetLocaleDateFormat");
  1174. BOOL fRet;
  1175. fRet = GetDateStr( pst, str, 0, cszFmt );
  1176. TraceFunctLeave();
  1177. return( fRet );
  1178. }
  1179. /***************************************************************************/
  1180. BOOL CRestoreManager::GetYearMonthStr( int nYear, int nMonth, CSRStr &str )
  1181. {
  1182. TraceFunctEnter("CRestoreManager::GetYearMonthStr");
  1183. BOOL fRet;
  1184. SYSTEMTIME st;
  1185. st.wYear = (WORD)nYear;
  1186. st.wMonth = (WORD)nMonth;
  1187. st.wDay = 1;
  1188. fRet = GetDateStr( &st, str, DATE_YEARMONTH, NULL );
  1189. TraceFunctLeave();
  1190. return( fRet );
  1191. }
  1192. /***************************************************************************/
  1193. BOOL CRestoreManager::InitializeAll()
  1194. {
  1195. TraceFunctEnter("CRestoreManager::InitializeAll");
  1196. BOOL fRet = FALSE;
  1197. //
  1198. // The InitializeAll function is called every time the user goes to Screen 2
  1199. // to display the calendar so get the system calendar type and set it here
  1200. //
  1201. SRUtil_SetCalendarTypeBasedOnLocale(LOCALE_USER_DEFAULT);
  1202. if ( !UpdateRestorePointList() )
  1203. goto Exit;
  1204. fRet = TRUE;
  1205. Exit:
  1206. TraceFunctLeave();
  1207. return( fRet );
  1208. }
  1209. /***************************************************************************/
  1210. BOOL CRestoreManager::Restore( HWND hwndProgress )
  1211. {
  1212. TraceFunctEnter("CRestoreManager::Restore");
  1213. #if BUGBUG
  1214. DWORD dwThreadId ;
  1215. m_hwndProgress = (HWND)hwndProgress;
  1216. //
  1217. // Reset the current bar size
  1218. //
  1219. m_lCurrentBarSize = 0 ;
  1220. //
  1221. // Create thread to run the restore map init
  1222. //
  1223. m_RSThread = CreateThread(NULL,
  1224. 0,
  1225. RestoreThreadStart,
  1226. this,
  1227. 0,
  1228. &dwThreadId);
  1229. if( NULL == m_RSThread )
  1230. {
  1231. FatalTrace(TRACE_ID, "Unable to create Restore thread; hr=0x%x", GetLastError());
  1232. hr = E_FAIL ;
  1233. }
  1234. #endif //BUGBUG
  1235. TraceFunctLeave();
  1236. return( TRUE );
  1237. }
  1238. /////////////////////////////////////////////////////////////////////////////
  1239. // CRestoreManager operations
  1240. BOOL CRestoreManager::AddRenamedFolder( PSRFI pRFI )
  1241. {
  1242. TraceFunctEnter("CRestoreManager::AddRenamedFolder");
  1243. BOOL fRet;
  1244. fRet = m_aryRFI.AddItem( pRFI );
  1245. TraceFunctLeave();
  1246. return( fRet );
  1247. }
  1248. /***************************************************************************/
  1249. BOOL CRestoreManager::SetRPsUsed( int nRPUsed, int nRPNew )
  1250. {
  1251. TraceFunctEnter("CRestoreManager::SetRPsUsed");
  1252. BOOL fRet = FALSE;
  1253. DWORD dwRet;
  1254. WCHAR szSysDrv[MAX_PATH];
  1255. WCHAR szRPDir[MAX_PATH];
  1256. WCHAR szSSPath[MAX_PATH];
  1257. CSnapshot cSS;
  1258. if ( !UpdateRestorePointList() )
  1259. goto Exit;
  1260. m_nRPUsed = nRPUsed;
  1261. m_nRPNew = nRPNew;
  1262. // Calls CSnapshot::CleanupAfterRestore. It is supposed to be safe
  1263. // to call even if there was no restore, so I'm just calling it
  1264. // whenever the log file validation happens.
  1265. ::GetSystemDrive( szSysDrv );
  1266. ::wsprintf( szRPDir, L"%s%d", s_cszRPDir, nRPUsed );
  1267. ::MakeRestorePath( szSSPath, szSysDrv, szRPDir );
  1268. dwRet = cSS.CleanupAfterRestore( szSSPath );
  1269. if ( dwRet != ERROR_SUCCESS )
  1270. {
  1271. LPCWSTR cszErr = ::GetSysErrStr(dwRet);
  1272. ErrorTrace(0, "CSnapshot::CleanupAfterRestore failed - %ls", cszErr);
  1273. // ignore the error
  1274. }
  1275. fRet = TRUE;
  1276. Exit:
  1277. TraceFunctLeave();
  1278. return( fRet );
  1279. }
  1280. /***************************************************************************/
  1281. BOOL CRestoreManager::SilentRestore( DWORD dwRP )
  1282. {
  1283. TraceFunctEnter("CRestoreManager::SilentRestore");
  1284. BOOL fRet = FALSE;
  1285. int i;
  1286. if ( !CanRunRestore( FALSE ) )
  1287. goto Exit;
  1288. if ( !UpdateRestorePointList() )
  1289. goto Exit;
  1290. if ( dwRP == 0xFFFFFFFF )
  1291. {
  1292. if ( m_aryRPI.GetSize() == 0 )
  1293. {
  1294. goto Exit;
  1295. }
  1296. m_nRealPoint = m_aryRPI.GetUpperBound();
  1297. }
  1298. else
  1299. {
  1300. for ( i = m_aryRPI.GetUpperBound(); i >= 0; i-- )
  1301. {
  1302. if ( m_aryRPI[i]->dwNum == dwRP )
  1303. {
  1304. m_nRealPoint = i;
  1305. break;
  1306. }
  1307. }
  1308. if ( i < 0 )
  1309. {
  1310. goto Exit;
  1311. }
  1312. }
  1313. DebugTrace(0, "m_nRealPoint=%d, m_nRP=%d", m_nRealPoint, m_aryRPI[m_nRealPoint]->dwNum);
  1314. if ( !CheckRestore(TRUE) )
  1315. {
  1316. ErrorTrace(0, "CheckRestore failed");
  1317. goto Exit;
  1318. }
  1319. if ( !BeginRestore( ) )
  1320. {
  1321. ErrorTrace(0, "BeginRestore failed");
  1322. goto Exit;
  1323. }
  1324. m_fNeedReboot = TRUE;
  1325. fRet = TRUE;
  1326. Exit:
  1327. TraceFunctLeave();
  1328. return( fRet );
  1329. }
  1330. /////////////////////////////////////////////////////////////////////////////
  1331. // CRestoreManager operations - internal
  1332. void CRestoreManager::Cleanup()
  1333. {
  1334. TraceFunctEnter("CRestoreManager::Cleanup");
  1335. int i;
  1336. for ( i = m_aryRPI.GetUpperBound(); i >= 0; i-- )
  1337. {
  1338. if ( m_aryRPI[i] != NULL )
  1339. delete m_aryRPI[i];
  1340. }
  1341. m_aryRPI.Empty();
  1342. for ( i = m_aryRFI.GetUpperBound(); i >= 0; i-- )
  1343. {
  1344. if ( m_aryRFI[i] != NULL )
  1345. delete m_aryRFI[i];
  1346. }
  1347. m_aryRFI.Empty();
  1348. TraceFunctLeave();
  1349. }
  1350. /***************************************************************************/
  1351. BOOL CRestoreManager::GetDateStr( PSYSTEMTIME pst, CSRStr &str, DWORD dwFlags, LPCWSTR cszFmt )
  1352. {
  1353. TraceFunctEnter("CRestoreManager::GetDateStr");
  1354. BOOL fRet = FALSE;
  1355. int nRet;
  1356. WCHAR szBuf[MAX_STR_DATETIME];
  1357. nRet = ::GetDateFormat( LOCALE_USER_DEFAULT, dwFlags, pst, cszFmt, szBuf, MAX_STR_DATETIME );
  1358. if ( nRet == 0 )
  1359. {
  1360. LPCWSTR cszErr = ::GetSysErrStr();
  1361. ErrorTrace(TRACE_ID, "::GetDateFormat failed - %s", cszErr);
  1362. goto Exit;
  1363. }
  1364. str = szBuf;
  1365. fRet = TRUE;
  1366. Exit:
  1367. TraceFunctLeave();
  1368. return( fRet );
  1369. }
  1370. /***************************************************************************/
  1371. BOOL CRestoreManager::GetTimeStr( PSYSTEMTIME pst, CSRStr &str, DWORD dwFlags )
  1372. {
  1373. TraceFunctEnter("CRestoreManager::GetTimeStr");
  1374. BOOL fRet = FALSE;
  1375. int nRet;
  1376. WCHAR szBuf[MAX_STR_DATETIME];
  1377. nRet = ::GetTimeFormat( LOCALE_USER_DEFAULT, dwFlags, pst, NULL, szBuf, MAX_STR_DATETIME );
  1378. if ( nRet == 0 )
  1379. {
  1380. LPCWSTR cszErr = ::GetSysErrStr();
  1381. ErrorTrace(TRACE_ID, "::GetTimeFormat failed - %s", cszErr);
  1382. goto Exit;
  1383. }
  1384. str = szBuf;
  1385. fRet = TRUE;
  1386. Exit:
  1387. TraceFunctLeave();
  1388. return( fRet );
  1389. }
  1390. /***************************************************************************/
  1391. void CRestoreManager::UpdateRestorePoint()
  1392. {
  1393. TraceFunctEnter("CRestoreManager::UpdateRestorePoint");
  1394. PSRPI pRPI;
  1395. SYSTEMTIME st;
  1396. WCHAR szBuf[MAX_STR_MESSAGE];
  1397. CSRStr strTime;
  1398. m_strSelected.Empty();
  1399. //if ( m_nRPI <= 0 || m_aryRPI == NULL )
  1400. // goto Exit;
  1401. pRPI = m_aryRPI[m_nSelectedRP];
  1402. pRPI->stTimeStamp.GetTime( &st );
  1403. GetTimeStr( &st, strTime, TIME_NOSECONDS );
  1404. ::lstrcpy( szBuf, strTime );
  1405. ::lstrcat( szBuf, L" " );
  1406. ::lstrcat( szBuf, pRPI->strName );
  1407. m_strSelected = szBuf;
  1408. //Exit:
  1409. TraceFunctLeave();
  1410. }
  1411. /***************************************************************************/
  1412. struct SRPINode
  1413. {
  1414. PSRPI pRPI;
  1415. SRPINode *pNext;
  1416. };
  1417. BOOL CRestoreManager::UpdateRestorePointList()
  1418. {
  1419. TraceFunctEnter("CRestoreManager::UpdateRestorePointList");
  1420. BOOL fRet = FALSE;
  1421. int i;
  1422. CSRTime stRP;
  1423. //BUGBUG - Release old restore point list
  1424. m_aryRPI.DeleteAll();
  1425. if ( !g_pExternal->BuildRestorePointList( &m_aryRPI ) )
  1426. goto Exit;
  1427. DebugTrace(TRACE_ID, "# of RP=%d", m_aryRPI.GetSize());
  1428. m_stToday.SetToCurrent();
  1429. m_stRPMin = m_stToday;
  1430. m_stRPMax = m_stToday;
  1431. m_nLastRestore = -1;
  1432. for ( i = 0; i < m_aryRPI.GetSize(); i++ )
  1433. {
  1434. // Find last "Restore"
  1435. if ( m_aryRPI[i]->dwType == RESTORE )
  1436. m_nLastRestore = i;
  1437. // Get range of dates
  1438. stRP = m_aryRPI[i]->stTimeStamp;
  1439. if ( ( i == 0 ) || ( stRP.Compare( m_stRPMin ) < 0 ) )
  1440. m_stRPMin = stRP;
  1441. if ( stRP.Compare( m_stRPMax ) > 0 )
  1442. m_stRPMax = stRP;
  1443. }
  1444. //
  1445. // BUGBUG - what happens if there were one or more RP, and then when
  1446. // UI refreshes, everything got FIFOed. Need a thoroughful review...
  1447. //
  1448. if ( m_aryRPI.GetSize() > 0 )
  1449. {
  1450. m_nSelectedRP = m_aryRPI.GetUpperBound();
  1451. m_nRealPoint = m_aryRPI.GetUpperBound();
  1452. UpdateRestorePoint();
  1453. }
  1454. fRet = TRUE;
  1455. Exit:
  1456. TraceFunctLeave();
  1457. return( fRet );
  1458. }
  1459. /////////////////////////////////////////////////////////////////////////////
  1460. // CRestoreManager attributes
  1461. HWND CRestoreManager::GetFrameHwnd()
  1462. {
  1463. TraceFunctEnter("CRestoreManager::GetFrameHwnd");
  1464. TraceFunctLeave();
  1465. return( m_hwndFrame );
  1466. }
  1467. void CRestoreManager::SetFrameHwnd( HWND hWnd )
  1468. {
  1469. TraceFunctEnter("CRestoreManager::SetFrameHwnd");
  1470. m_hwndFrame = hWnd;
  1471. TraceFunctLeave();
  1472. }
  1473. /***************************************************************************/
  1474. /*
  1475. int CRestoreManager::GetStatus()
  1476. {
  1477. TraceFunctEnter("CRestoreManager::GetStatus");
  1478. DebugTrace(TRACE_ID, "m_nStatus=%d", m_nStatus);
  1479. TraceFunctLeave();
  1480. return( m_nStatus );
  1481. }
  1482. */
  1483. /***************************************************************************/
  1484. BOOL CRestoreManager::DenyClose()
  1485. {
  1486. TraceFunctEnter("CRestoreManager::DenyClose");
  1487. DebugTrace(TRACE_ID, "m_fDenyClose=%d", m_fDenyClose);
  1488. TraceFunctLeave();
  1489. return( m_fDenyClose );
  1490. }
  1491. /***************************************************************************/
  1492. BOOL CRestoreManager::NeedReboot()
  1493. {
  1494. TraceFunctEnter("CRestoreManager::NeedReboot");
  1495. DebugTrace(TRACE_ID, "m_fNeedReboot=%d", m_fNeedReboot);
  1496. TraceFunctLeave();
  1497. return( m_fNeedReboot );
  1498. }
  1499. // end of file