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.

461 lines
11 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. rstrpriv.h
  5. Abstract:
  6. This file defines common constants and utility macros, and contains the
  7. declarations of private utility functions.
  8. Revision History:
  9. Seong Kook Khang (SKKhang) 07/07/99
  10. created
  11. ******************************************************************************/
  12. #ifndef _RSTRPRIV_H__INCLUDED_
  13. #define _RSTRPRIV_H__INCLUDED_
  14. #pragma once
  15. //#include <changelog.h>
  16. #include <srdefs.h>
  17. #include <srrestoreptapi.h>
  18. #include <ppath.h>
  19. #include <utils.h>
  20. #include <snapshot.h>
  21. #include <srshell.h>
  22. // System Restore Application Start Mode
  23. enum
  24. {
  25. SRASM_NORMAL, // Show Main Page
  26. SRASM_SUCCESS, // Show Success Result Page
  27. SRASM_FAIL, // Show Failure Result Page
  28. SRASM_FAILLOWDISK, // Show Fail-Low-Disk Result Page
  29. SRASM_FAILINTERRUPTED
  30. };
  31. #ifdef TEST_UI_ONLY
  32. ////////////////////////////////////////////////////////////////////////////
  33. // Temporary definitions until entire SR components are in place
  34. ////////////////////////////////////////////////////////////////////////////
  35. // from constants.h
  36. static LPCTSTR s_cszHiddenSFPEnableVal = TEXT("2567");
  37. static LPCTSTR s_cszHiddenSFPDisableVal = TEXT("2803");
  38. #if 0
  39. // statemgr.dll
  40. BOOL DisableArchivingI( BOOL fMode );
  41. #define DisableArchiving DisableArchivingI
  42. // from sfpcapi.h
  43. extern BOOL DisableSFP( BOOL fDisable, LPCTSTR pszKey );
  44. extern BOOL DisableFIFO( INT64 llSeqNum );
  45. extern BOOL EnableFIFO();
  46. // from restoreptlog.h
  47. typedef struct _RestorePtLogEntry
  48. {
  49. DWORD m_dwSize;
  50. DWORD m_dwType;
  51. INT64 m_llSeqNum;
  52. time_t ltime;
  53. WCHAR m_szCab[16];
  54. CHAR m_bDesc[1];
  55. } RESTOREPTLOGENTRY, *PRESTOREPTLOGENTRY;
  56. // from restoreptapi.h
  57. BOOL FindFirstRestorePt( PRESTOREPTLOGENTRY *ppEntry );
  58. BOOL FindNextRestorePt( PRESTOREPTLOGENTRY *ppEntry );
  59. BOOL ShutRestorePtAPI(PRESTOREPTLOGENTRY *ppEntry);
  60. #endif
  61. // from srrestoreptapi.h
  62. // from chglogapi.h
  63. extern BOOL InitChgLogAPI();
  64. extern BOOL ShutChgLogAPI();
  65. extern VOID FreeChgLogPtr( LPVOID pPtr );
  66. extern BOOL GetArchiveDir( LPTSTR* ppszArchiveDir );
  67. extern BOOL RequestDSAccess( BOOL fMode );
  68. // from vxdlog.h
  69. enum
  70. {
  71. OPR_UNKNOWN = 0,
  72. OPR_FILE_ADD = 1,
  73. OPR_FILE_DELETE = 2,
  74. OPR_FILE_MODIFY = 3,
  75. OPR_RENAME = 4,
  76. OPR_SETATTRIB = 5,
  77. OPR_DIR_CREATE = 6,
  78. OPR_DIR_DELETE = 7
  79. };
  80. typedef struct VXD_LOG_ENTRY
  81. {
  82. DWORD m_dwSize;
  83. DWORD m_dwType;
  84. DWORD m_dwAttrib;
  85. DWORD m_dwSfp;
  86. DWORD m_dwFlags;
  87. INT64 m_llSeq;
  88. CHAR m_szProc[16];
  89. BYTE m_bDrive[16];
  90. CHAR m_szTemp[16];
  91. CHAR m_bData[1];
  92. } VxdLogEntry;
  93. #define MAX_VXD_LOG_ENTRY ( sizeof(VxdLogEntry) + 3 * MAX_PPATH_SIZE )
  94. // from restmap.h
  95. typedef struct RESTORE_MAP_ENTRY
  96. {
  97. DWORD m_dwSize;
  98. DWORD m_dwOperation ;
  99. DWORD m_dwAttribute ;
  100. BYTE m_bDrive[16];
  101. BYTE m_szCab [16];
  102. BYTE m_szTemp[16];
  103. CHAR m_bData [ 1 ];
  104. } RestoreMapEntry;
  105. extern BOOL CreateRestoreMap( INT64 nSeqNum, LPTSTR szRestFile, DWORD *pdwErrorCode );
  106. ////////////////////////////////////////////////////////////////////////////
  107. // END of Temporary stuffs
  108. ////////////////////////////////////////////////////////////////////////////
  109. #endif //def TEST_UI_ONLY
  110. #ifdef TEST_UI_ONLY
  111. #else
  112. //extern "C" __declspec(dllimport) BOOL DisableArchiving( BOOL fMode );
  113. #endif
  114. // RESTORE SHELL
  115. #define TID_RSTR_MAIN 0x0500
  116. #define TID_RSTR_CLIWND 0x0501
  117. #define TID_RSTR_RPDATA 0x0502
  118. #define TID_RSTR_RSTRMAP 0x0503
  119. #define TID_RSTR_UTIL 0x0504
  120. #define TID_RSTR_LOGFILE 0x0505
  121. #define TID_RSTR_PROCLIST 0x0506
  122. #define TID_RSTR_RSTRCAL 0x0507
  123. #define TID_RSTR_RSTRPROG 0x0508
  124. #define TID_RSTR_RSTRSHL 0x0509
  125. #define TID_RSTR_RSTREDIT 0x050A
  126. #define TID_RSTR_UNDO 0x050B
  127. #define MAX_STR_TITLE 256
  128. #define MAX_STR_MSG 1024
  129. #define SAFE_RELEASE(p) \
  130. if ( (p) != NULL ) \
  131. { \
  132. (p)->Release(); \
  133. p = NULL; \
  134. } \
  135. #define SAFE_DELETE(p) \
  136. if ( (p) != NULL ) \
  137. { \
  138. delete p; \
  139. p = NULL; \
  140. } \
  141. #define SAFE_DEL_ARRAY(p) \
  142. if ( (p) != NULL ) \
  143. { \
  144. delete [] p; \
  145. p = NULL; \
  146. } \
  147. #define VALIDATE_INPUT_ARGUMENT(x) \
  148. { \
  149. _ASSERT(NULL != x); \
  150. if (NULL == x) \
  151. { \
  152. ErrorTrace(TRACE_ID, "Invalid Argument, NULL input parameter"); \
  153. hr = E_INVALIDARG; \
  154. goto Exit; \
  155. } \
  156. }
  157. #define VALIDATE_INPUT_VARIANT(var,type) \
  158. if (V_VT(&var) != type) \
  159. { \
  160. ErrorTrace(TRACE_ID, "Invalid Argument, V_VT(var)=%d is not expected type %d",V_VT(&var),type); \
  161. hr = E_INVALIDARG; \
  162. goto Exit; \
  163. } \
  164. #define COPYBSTR_AND_CHECK_ERROR(bstrDest,bstrSrc) \
  165. { \
  166. _ASSERT(bstrSrc.Length() > 0); \
  167. bstrDest = bstrSrc; \
  168. if (!bstrDest) \
  169. { \
  170. FatalTrace(TRACE_ID, "Out of memory, cannot allocate string"); \
  171. hr = E_OUTOFMEMORY; \
  172. goto Exit; \
  173. } \
  174. }
  175. #define COPYBSTRFROMLPCTSTR_AND_CHECK_ERROR(bstrDest,szSrc) \
  176. { \
  177. _ASSERT(szSrc); \
  178. _ASSERT(szSrc[0] != TCHAR('\0')); \
  179. bstrDest = szSrc; \
  180. if (!bstrDest) \
  181. { \
  182. FatalTrace(TRACE_ID, "Out of memory, cannot allocate string"); \
  183. hr = E_OUTOFMEMORY; \
  184. goto Exit; \
  185. } \
  186. }
  187. #define ALLOCATEBSTR_AND_CHECK_ERROR(pbstrDest,bstrSrc) \
  188. { \
  189. if ( (LPCWSTR)(bstrSrc) == NULL || ((LPCWSTR)(bstrSrc))[0] == L'\0' ) \
  190. { \
  191. pbstrDest = NULL; \
  192. } \
  193. else \
  194. { \
  195. *pbstrDest = ::SysAllocString(bstrSrc); \
  196. if (NULL == *pbstrDest) \
  197. { \
  198. FatalTrace(TRACE_ID, "Out of memory, cannot allocate string"); \
  199. hr = E_OUTOFMEMORY; \
  200. goto Exit; \
  201. } \
  202. } \
  203. }
  204. #define STR_REGPATH_RUNONCE L"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce"
  205. #define STR_REGVAL_RUNONCE L"*Restore"
  206. #define UNDOTYPE_LOWDISK 1
  207. #define UNDOTYPE_INTERRUPTED 2
  208. #define RSTRMAP_MIN_WIN_DISK_SPACE_MB (50) // 50 MB limit for now
  209. #define RSTRMAP_LOW_WIN_DISK_SPACE_MB (10) // 10 MB limit for now
  210. //
  211. // Registry key strings from the file constants.h
  212. //
  213. static LPCWSTR s_cszUIFreezeSize = L"UIFreezeSize";
  214. static LPCWSTR s_cszSeqNumPath = L"system\\restore\\rstrseq.log";
  215. //extern HWND g_hFrameWnd;
  216. //
  217. // Global Variables from MAIN.CPP
  218. //
  219. extern HINSTANCE g_hInst;
  220. inline int PCHLoadString( UINT uID, LPWSTR lpBuf, int nBufMax )
  221. {
  222. return( ::LoadString( g_hInst, uID, lpBuf, nBufMax ) );
  223. }
  224. //
  225. // Functions from UNDO.CPP
  226. //
  227. extern BOOL UndoRestore( int nType );
  228. extern BOOL CancelRestorePoint( void );
  229. //
  230. // Functions from UTIL.CPP
  231. //
  232. extern int SRUtil_SetCalendarTypeBasedOnLocale(LCID locale);
  233. extern LPCWSTR GetSysErrStr();
  234. extern LPCWSTR GetSysErrStr( DWORD dwErr );
  235. extern LPSTR IStrDupA( LPCSTR szSrc );
  236. extern LPWSTR IStrDupW( LPCWSTR wszSrc );
  237. extern BOOL SRFormatMessage( LPWSTR szMsg, UINT uFmtId, ... );
  238. extern BOOL ShowSRErrDlg( UINT uMsgId, ... );
  239. extern BOOL SRGetRegDword( HKEY hKey, LPCWSTR cszSubKey, LPCWSTR cszValue, DWORD *pdwData );
  240. //extern LPWSTR PathElem2Str( PathElement *pElem );
  241. //extern LPWSTR ParsedPath2Str( ParsedPath *pPath, LPCWSTR wszDrive );
  242. extern BOOL IsFreeSpaceOnWindowsDrive( void );
  243. extern LANGID GetDefaultUILang(void);
  244. extern BOOL ShutDownStateMgr(void);
  245. #ifdef UNICODE
  246. #define IStrDup IStrDupW
  247. #else
  248. #define IStrDup IStrDupA
  249. #endif //ifdef UNICODE
  250. //
  251. // String handling class
  252. //
  253. class CSRStr
  254. {
  255. public:
  256. CSRStr();
  257. CSRStr( LPCWSTR wszSrc );
  258. CSRStr( LPCSTR szSrc );
  259. ~CSRStr();
  260. // Attributes
  261. public:
  262. int LengthW();
  263. int LengthA();
  264. inline int Length()
  265. {
  266. #ifdef UNICODE
  267. return( LengthW() );
  268. #else
  269. return( LengthA() );
  270. #endif
  271. }
  272. operator LPCWSTR();
  273. operator LPCSTR();
  274. protected:
  275. int m_cchW;
  276. LPWSTR m_strW;
  277. int m_cchA;
  278. LPSTR m_strA;
  279. // Operations
  280. public:
  281. void Empty();
  282. BOOL SetStr( LPCWSTR wszSrc, int cch = -1 );
  283. BOOL SetStr( LPCSTR szSrc, int cch = -1 );
  284. const CSRStr& operator =( LPCWSTR wszSrc );
  285. const CSRStr& operator =( LPCSTR szSrc );
  286. protected:
  287. BOOL ConvertA2W();
  288. BOOL ConvertW2A();
  289. void Release();
  290. };
  291. //
  292. // Dynamic Array class
  293. //
  294. template<class type, int nBlock>
  295. class CSRDynPtrArray
  296. {
  297. public:
  298. CSRDynPtrArray();
  299. ~CSRDynPtrArray();
  300. // Attributes
  301. public:
  302. int GetSize()
  303. { return( m_nCur ); }
  304. int GetUpperBound()
  305. { return( m_nCur-1 ); }
  306. type GetItem( int nItem );
  307. type operator[]( int nItem )
  308. { return( GetItem( nItem ) ); }
  309. protected:
  310. int m_nMax; // Maximum Item Count
  311. int m_nCur; // Current Item Count
  312. type *m_ppTable;
  313. // Operations
  314. public:
  315. BOOL AddItem( type item );
  316. BOOL Empty();
  317. void DeleteAll();
  318. void ReleaseAll();
  319. };
  320. template<class type, int nBlock>
  321. CSRDynPtrArray<type, nBlock>::CSRDynPtrArray()
  322. {
  323. m_nMax = 0;
  324. m_nCur = 0;
  325. m_ppTable = NULL;
  326. }
  327. template<class type, int nBlock>
  328. CSRDynPtrArray<type, nBlock>::~CSRDynPtrArray()
  329. {
  330. Empty();
  331. }
  332. template<class type, int nBlock>
  333. type CSRDynPtrArray<type, nBlock>::GetItem( int nItem )
  334. {
  335. if ( nItem < 0 || nItem >= m_nCur )
  336. {
  337. // ERROR - Out of Range
  338. }
  339. return( m_ppTable[nItem] );
  340. }
  341. template<class type, int nBlock>
  342. BOOL CSRDynPtrArray<type, nBlock>::AddItem( type item )
  343. {
  344. type *ppTableNew;
  345. if ( m_nCur == m_nMax )
  346. {
  347. m_nMax += nBlock;
  348. // Assuming m_ppTable and m_nMax are always in sync.
  349. // Review if it's necessary to validate this assumption.
  350. if ( m_ppTable == NULL )
  351. ppTableNew = (type*)::HeapAlloc( ::GetProcessHeap(), 0, m_nMax*sizeof(type) );
  352. else
  353. ppTableNew = (type*)::HeapReAlloc( ::GetProcessHeap(), 0, m_ppTable, m_nMax * sizeof(type) );
  354. if ( ppTableNew == NULL )
  355. {
  356. // FATAL, Memory Insufficient...
  357. return FALSE;
  358. }
  359. m_ppTable = ppTableNew;
  360. }
  361. m_ppTable[m_nCur++] = item;
  362. return( TRUE );
  363. }
  364. template<class type, int nBlock>
  365. BOOL CSRDynPtrArray<type, nBlock>::Empty()
  366. {
  367. if ( m_ppTable != NULL )
  368. {
  369. ::HeapFree( ::GetProcessHeap(), 0, m_ppTable );
  370. m_ppTable = NULL;
  371. m_nMax = 0;
  372. m_nCur = 0;
  373. }
  374. return( TRUE );
  375. }
  376. template<class type, int nBlock>
  377. void CSRDynPtrArray<type, nBlock>::DeleteAll()
  378. {
  379. for ( int i = m_nCur-1; i >= 0; i-- )
  380. delete m_ppTable[i];
  381. Empty();
  382. }
  383. template<class type, int nBlock>
  384. void CSRDynPtrArray<type, nBlock>::ReleaseAll()
  385. {
  386. for ( int i = m_nCur-1; i >= 0; i-- )
  387. m_ppTable[i]->Release();
  388. Empty();
  389. }
  390. #endif //_RSTRPRIV_H__INCLUDED_