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.

387 lines
11 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 <srrpcapi.h>
  15. #include "enumlogs.h"
  16. #include "rstrpriv.h"
  17. #include "rstrmgr.h"
  18. #include "extwrap.h"
  19. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. // CSRExternalWrapper class
  22. //
  23. /////////////////////////////////////////////////////////////////////////////
  24. class CSRExternalWrapper : public ISRExternalWrapper
  25. {
  26. // ISRExternalWrapper methods
  27. public:
  28. BOOL BuildRestorePointList( CDPA_RPI *paryRPI );
  29. BOOL DisableFIFO( DWORD dwRP );
  30. DWORD EnableFIFO();
  31. //BOOL SetRestorePoint( RESTOREPOINTINFO *pRPI, STATEMGRSTATUS *pStatus );
  32. BOOL SetRestorePoint( LPCWSTR cszDesc, INT64 *pllRP );
  33. BOOL RemoveRestorePoint( DWORD dwRP );
  34. BOOL Release();
  35. };
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CSRExternalWrapper - ISRExternalWrapper methods
  38. BOOL CSRExternalWrapper::BuildRestorePointList( CDPA_RPI *paryRPI )
  39. {
  40. TraceFunctEnter("CSRExternalWrapper::BuildRestorePointList");
  41. BOOL fRet = FALSE;
  42. BOOL fExist;
  43. CRestorePointEnum cRPEnum;
  44. CRestorePoint cRP;
  45. DWORD dwRes;
  46. PSRPI pRPI;
  47. dwRes = cRPEnum.FindFirstRestorePoint( cRP );
  48. // if rp.log doesn't exist for a restore point, we skip it and list all others
  49. while ( dwRes == ERROR_SUCCESS || dwRes == ERROR_FILE_NOT_FOUND)
  50. {
  51. // Ignoring any nonstandard restore point types (e.g. shutdown),
  52. // assuming they can no longer be created on Whistler.
  53. // skip restore points that don't have rp.log +
  54. // skip cancelled restore points
  55. if (dwRes != ERROR_FILE_NOT_FOUND && ! cRP.IsDefunct())
  56. {
  57. pRPI = new SRestorePointInfo;
  58. if ( pRPI == NULL )
  59. {
  60. ErrorTrace(TRACE_ID, "Cannot create RPI Instance...");
  61. goto Exit;
  62. }
  63. pRPI->dwType = cRP.GetType();
  64. pRPI->dwNum = cRP.GetNum();
  65. pRPI->strDir = cRP.GetDir();
  66. pRPI->strName = cRP.GetName();
  67. pRPI->stTimeStamp.SetTime( cRP.GetTime(), FALSE );
  68. if ( !paryRPI->AddItem( pRPI ) )
  69. goto Exit;
  70. }
  71. else
  72. {
  73. DebugTrace(TRACE_ID, "Ignoring cancelled restore point");
  74. }
  75. dwRes = cRPEnum.FindNextRestorePoint( cRP );
  76. }
  77. fRet = TRUE;
  78. Exit:
  79. //BUGBUG - keep an eye on this, dummy at this moment
  80. cRPEnum.FindClose();
  81. TraceFunctLeave();
  82. return( fRet );
  83. }
  84. /***************************************************************************/
  85. BOOL CSRExternalWrapper::DisableFIFO( DWORD dwRP )
  86. {
  87. TraceFunctEnter("CSRExternalWrapper::DisableFIFO");
  88. BOOL fRet = FALSE;
  89. DWORD dwRes;
  90. dwRes = ::DisableFIFO( dwRP );
  91. if ( dwRes != ERROR_SUCCESS )
  92. {
  93. LPCWSTR cszErr = ::GetSysErrStr( dwRes );
  94. ErrorTrace(0, "::DisableFIFO failed - %ls", cszErr);
  95. goto Exit;
  96. }
  97. fRet = TRUE;
  98. Exit:
  99. TraceFunctLeave();
  100. return( fRet );
  101. }
  102. /***************************************************************************/
  103. DWORD CSRExternalWrapper::EnableFIFO()
  104. {
  105. TraceFunctEnter("CSRExternalWrapper::EnableFIFO");
  106. DWORD dwRes;
  107. dwRes = ::EnableFIFO();
  108. if ( dwRes != ERROR_SUCCESS )
  109. {
  110. LPCWSTR cszErr = ::GetSysErrStr( dwRes );
  111. ErrorTrace(0, "::EnableFIFO failed - %ls", cszErr);
  112. goto Exit;
  113. }
  114. Exit:
  115. TraceFunctLeave();
  116. return( dwRes );
  117. }
  118. /*
  119. BOOL CSRExternalWrapper::SetRestorePoint( RESTOREPOINTINFO *pRPI, STATEMGRSTATUS *pStatus )
  120. {
  121. return( TRUE );
  122. }
  123. */
  124. /***************************************************************************/
  125. BOOL CSRExternalWrapper::SetRestorePoint( LPCWSTR cszDesc, INT64 *pllRP )
  126. {
  127. TraceFunctEnter("CSRExternalWrapper::SetRestorePoint");
  128. BOOL fRet = FALSE;
  129. RESTOREPOINTINFO sRPInfo;
  130. STATEMGRSTATUS sSmgrStatus;
  131. sRPInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
  132. sRPInfo.dwRestorePtType = CHECKPOINT;
  133. sRPInfo.llSequenceNumber = 0;
  134. sRPInfo.szDescription[MAX_DESC_W-1] = L'\0';
  135. ::lstrcpyn( sRPInfo.szDescription, cszDesc, MAX_DESC_W );
  136. if ( !::SRSetRestorePoint( &sRPInfo, &sSmgrStatus ) )
  137. {
  138. ErrorTrace(0, "::SRSetRestorePoint failed, status=%d", sSmgrStatus.nStatus);
  139. goto Exit;
  140. }
  141. if ( pllRP != NULL )
  142. *pllRP = sSmgrStatus.llSequenceNumber;
  143. fRet = TRUE;
  144. Exit:
  145. TraceFunctLeave();
  146. return( fRet );
  147. }
  148. /***************************************************************************/
  149. BOOL CSRExternalWrapper::RemoveRestorePoint( DWORD dwRP )
  150. {
  151. TraceFunctEnter("CSRExternalWrapper::RemoveRestorePoint");
  152. BOOL fRet = FALSE;
  153. DWORD dwRes;
  154. dwRes = ::SRRemoveRestorePoint( dwRP );
  155. if ( dwRes != ERROR_SUCCESS )
  156. {
  157. LPCWSTR cszErr = ::GetSysErrStr( dwRes );
  158. ErrorTrace(0, "::SRRemoveRestorePoint failed - %ls", cszErr);
  159. goto Exit;
  160. }
  161. fRet = TRUE;
  162. Exit:
  163. TraceFunctLeave();
  164. return( fRet );
  165. }
  166. /***************************************************************************/
  167. BOOL CSRExternalWrapper::Release()
  168. {
  169. TraceFunctEnter("CSRExternalWrapper::Release");
  170. delete this;
  171. TraceFunctLeave();
  172. return( TRUE );
  173. }
  174. /////////////////////////////////////////////////////////////////////////////
  175. //
  176. // CSRExternalWrapperStub class
  177. //
  178. /////////////////////////////////////////////////////////////////////////////
  179. class CSRExternalWrapperStub : public ISRExternalWrapper
  180. {
  181. // ISRExternalWrapper methods
  182. public:
  183. BOOL BuildRestorePointList( CDPA_RPI *paryRPI );
  184. BOOL DisableFIFO( DWORD dwRP );
  185. DWORD EnableFIFO();
  186. //BOOL SetRestorePoint( RESTOREPOINTINFO *pRPI, STATEMGRSTATUS *pStatus );
  187. BOOL SetRestorePoint( LPCWSTR cszDesc, INT64 *pllRP );
  188. BOOL RemoveRestorePoint( DWORD dwRP );
  189. BOOL Release();
  190. };
  191. /////////////////////////////////////////////////////////////////////////////
  192. // CSRExternalWrapperStub - ISRExternalWrapper methods
  193. #define FTUNITPERDAY ((INT64)24*60*60*1000*1000*10)
  194. struct SRPIStub
  195. {
  196. DWORD dwType;
  197. LPCWSTR cszName;
  198. //CSRTime stTime;
  199. };
  200. static SRPIStub s_aryRPIList[] =
  201. {
  202. { CHECKPOINT, L"System Check Point" },
  203. { APPLICATION_INSTALL, L"Office 2000 Install" },
  204. { RESTORE, L"Restore" },
  205. { CHECKPOINT, L"System Check Point" },
  206. { CHECKPOINT, L"System Check Point" },
  207. { CHECKPOINT, L"System Check Point" },
  208. { APPLICATION_INSTALL, L"InocuLan Install" },
  209. { APPLICATION_INSTALL, L"Flight Simulator 2000 Install" },
  210. { APPLICATION_INSTALL, L"Norton Utilities Install" },
  211. { CHECKPOINT, L"System Check Point" },
  212. { APPLICATION_INSTALL, L"Evil App Install" },
  213. { CHECKPOINT, L"System Check Point" },
  214. { RESTORE, L"Restore" },
  215. { RESTORE, L"Restore" },
  216. { CHECKPOINT, L"System Check Point" },
  217. { CHECKPOINT, L"System Check Point" }
  218. };
  219. #define COUNT_RPI_ENTRY (sizeof(s_aryRPIList)/sizeof(SRPIStub))
  220. static int s_nRPTimeOff[COUNT_RPI_ENTRY] =
  221. { -60, -59, -57, -57, -31, -30, -6, -6, -6, -6, -4, -3, -2, -2, -1, 0 };
  222. BOOL CSRExternalWrapperStub::BuildRestorePointList( CDPA_RPI *paryRPI )
  223. {
  224. TraceFunctEnter("CSRExternalWrapperStub::BuildRestorePointList");
  225. BOOL fRet = FALSE;
  226. int i;
  227. PSRPI pRPI;
  228. ULARGE_INTEGER ullTime;
  229. ULARGE_INTEGER ullOff;
  230. ::GetSystemTimeAsFileTime( (PFILETIME)&ullTime );
  231. for ( i = 0; i < COUNT_RPI_ENTRY; i++ )
  232. {
  233. pRPI = new SRestorePointInfo;
  234. if ( pRPI == NULL )
  235. {
  236. ErrorTrace(TRACE_ID, "Insufficient memory, cannot allocate RPI");
  237. goto Exit;
  238. }
  239. pRPI->dwType = s_aryRPIList[i].dwType;
  240. pRPI->strDir = L"c:\\some\\dummy\\directory\\name";
  241. pRPI->strName = s_aryRPIList[i].cszName;
  242. ullOff = ullTime;
  243. ullOff.QuadPart += s_nRPTimeOff[i] * FTUNITPERDAY;
  244. pRPI->stTimeStamp.SetTime( (PFILETIME)&ullOff );
  245. paryRPI->AddItem( pRPI );
  246. }
  247. fRet = TRUE;
  248. Exit:
  249. TraceFunctLeave();
  250. return( fRet );
  251. }
  252. /***************************************************************************/
  253. BOOL CSRExternalWrapperStub::DisableFIFO( DWORD )
  254. {
  255. TraceFunctEnter("CSRExternalWrapperStub::DisableFIFO");
  256. TraceFunctLeave();
  257. return( TRUE );
  258. }
  259. /***************************************************************************/
  260. DWORD CSRExternalWrapperStub::EnableFIFO()
  261. {
  262. TraceFunctEnter("CSRExternalWrapperStub::EnableFIFO");
  263. TraceFunctLeave();
  264. return( ERROR_SUCCESS );
  265. }
  266. /*
  267. BOOL CSRExternalWrapperStub::SetRestorePoint( RESTOREPOINTINFO *pRPI, STATEMGRSTATUS *pStatus )
  268. {
  269. TraceFunctEnter("CSRExternalWrapperStub::SetRestorePoint");
  270. TraceFunctLeave();
  271. return( TRUE );
  272. }
  273. */
  274. /***************************************************************************/
  275. BOOL CSRExternalWrapperStub::SetRestorePoint( LPCWSTR, INT64* )
  276. {
  277. TraceFunctEnter("CSRExternalWrapperStub::SetRestorePoint");
  278. TraceFunctLeave();
  279. return( TRUE );
  280. }
  281. /***************************************************************************/
  282. BOOL CSRExternalWrapperStub::RemoveRestorePoint( DWORD )
  283. {
  284. TraceFunctEnter("CSRExternalWrapperStub::RemoveRestorePoint");
  285. TraceFunctLeave();
  286. return( TRUE );
  287. }
  288. /***************************************************************************/
  289. BOOL CSRExternalWrapperStub::Release()
  290. {
  291. TraceFunctEnter("CSRExternalWrapperStub::Release");
  292. delete this;
  293. TraceFunctLeave();
  294. return( TRUE );
  295. }
  296. /////////////////////////////////////////////////////////////////////////////
  297. //
  298. // CreateSRExternalWrapper
  299. //
  300. /////////////////////////////////////////////////////////////////////////////
  301. BOOL CreateSRExternalWrapper( BOOL fUseStub, ISRExternalWrapper **ppExtWrap )
  302. {
  303. TraceFunctEnter("CreateSRExternalWrapper");
  304. BOOL fRet = FALSE;
  305. if ( fUseStub )
  306. *ppExtWrap = new CSRExternalWrapperStub;
  307. else
  308. *ppExtWrap = new CSRExternalWrapper;
  309. if ( *ppExtWrap == NULL )
  310. {
  311. ErrorTrace(TRACE_ID, "Insufficient memory...");
  312. goto Exit;
  313. }
  314. fRet = TRUE;
  315. Exit:
  316. TraceFunctLeave();
  317. return( fRet );
  318. }
  319. // end of file