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.

180 lines
5.4 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2000-2001 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** vsreq.h
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Sample program to
  15. ** - obtain and display the Writer metadata.
  16. ** - create a snapshot set
  17. **
  18. ** Author:
  19. **
  20. ** Adi Oltean [aoltean] 05-Dec-2000
  21. **
  22. ** The sample is based on the Metasnap test program written by Michael C. Johnson.
  23. **
  24. **
  25. ** Revision History:
  26. **
  27. **--
  28. */
  29. /*
  30. ** Defines
  31. **
  32. **
  33. ** C4290: C++ Exception Specification ignored
  34. ** warning C4511: 'CVssCOMApplication' : copy constructor could not be generated
  35. ** warning C4127: conditional expression is constant
  36. */
  37. #pragma warning(disable:4290)
  38. #pragma warning(disable:4511)
  39. #pragma warning(disable:4127)
  40. /*
  41. ** Includes
  42. */
  43. #include <windows.h>
  44. #include <wtypes.h>
  45. #include <stddef.h>
  46. #include <stdlib.h>
  47. #include <stdio.h>
  48. #include <time.h>
  49. #include <string.h>
  50. #include <vss.h>
  51. #include <vswriter.h>
  52. #include <vsbackup.h>
  53. #include <oleauto.h>
  54. #define ATLASSERT(_condition)
  55. #include <atlconv.h>
  56. #include <atlbase.h>
  57. extern CComModule _Module;
  58. #include <atlcom.h>
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // Useful macros
  61. #define WSTR_GUID_FMT L"{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}"
  62. #define GUID_PRINTF_ARG( X ) \
  63. (X).Data1, \
  64. (X).Data2, \
  65. (X).Data3, \
  66. (X).Data4[0], (X).Data4[1], (X).Data4[2], (X).Data4[3], \
  67. (X).Data4[4], (X).Data4[5], (X).Data4[6], (X).Data4[7]
  68. // Execute the given call and check that the return code must be S_OK
  69. #define CHECK_SUCCESS( Call ) \
  70. { \
  71. m_hr = Call; \
  72. if (m_hr != S_OK) \
  73. Error(1, L"\nError in %S(%d): \n\t- Call %S not succeeded. \n" \
  74. L"\t Error code = 0x%08lx. Error description = %s\n", \
  75. __FILE__, __LINE__, #Call, m_hr, GetStringFromFailureType(m_hr)); \
  76. }
  77. #define CHECK_NOFAIL( Call ) \
  78. { \
  79. m_hr = Call; \
  80. if (FAILED(m_hr)) \
  81. Error(1, L"\nError in %S(%d): \n\t- Call %S not succeeded. \n" \
  82. L"\t Error code = 0x%08lx. Error description = %s\n", \
  83. __FILE__, __LINE__, #Call, m_hr, GetStringFromFailureType(m_hr)); \
  84. }
  85. ///////////////////////////////////////////////////////////////////////////////
  86. // Constants
  87. const MAX_VOLUMES = 64;
  88. const MAX_TEXT_BUFFER = 512;
  89. ///////////////////////////////////////////////////////////////////////////////
  90. // Main class
  91. class CVssSampleRequestor
  92. {
  93. // Constructors& destructors
  94. public:
  95. CVssSampleRequestor();
  96. ~CVssSampleRequestor();
  97. // Attributes
  98. public:
  99. // Operations
  100. public:
  101. // Initialize internal members
  102. void Initialize();
  103. // Parse command line arguments
  104. void ParseCommandLine(
  105. IN INT nArgsCount,
  106. IN WCHAR ** ppwszArgsArray
  107. );
  108. // Creates a snapshot set
  109. void CreateSnapshotSet();
  110. // Completes the backup
  111. void BackupComplete();
  112. void GatherWriterMetadata();
  113. void GatherWriterStatus(
  114. IN LPCWSTR wszWhen
  115. );
  116. // Private methods:
  117. private:
  118. LPCWSTR GetStringFromUsageType (VSS_USAGE_TYPE eUsageType);
  119. LPCWSTR GetStringFromSourceType (VSS_SOURCE_TYPE eSourceType);
  120. LPCWSTR GetStringFromRestoreMethod (VSS_RESTOREMETHOD_ENUM eRestoreMethod);
  121. LPCWSTR GetStringFromWriterRestoreMethod (VSS_WRITERRESTORE_ENUM eWriterRestoreMethod);
  122. LPCWSTR GetStringFromComponentType (VSS_COMPONENT_TYPE eComponentType);
  123. LPCWSTR GetStringFromFailureType (HRESULT hrStatus);
  124. LPCWSTR GetStringFromWriterStatus(VSS_WRITER_STATE eWriterStatus);
  125. void PrintUsage();
  126. void Error(INT nReturnCode, const WCHAR* pwszMsgFormat, ...);
  127. void PrintFiledesc (IVssWMFiledesc *pFiledesc, LPCWSTR wszDescription);
  128. void AddVolumeForComponent( IN IVssWMFiledesc* pFileDesc );
  129. bool AddVolume( IN WCHAR* pwszVolume, OUT bool & bAdded );
  130. // Implementation
  131. private:
  132. CComPtr<IVssBackupComponents> m_pBackupComponents;
  133. bool m_bCoInitializeSucceeded;
  134. bool m_bBootableSystemState;
  135. bool m_bComponentSelectionEnabled;
  136. INT m_nVolumesCount;
  137. WCHAR* m_ppwszVolumesList[MAX_VOLUMES];
  138. WCHAR* m_ppwszVolumeNamesList[MAX_VOLUMES];
  139. HRESULT m_hr;
  140. bool m_bMetadataGathered;
  141. WCHAR* m_pwszXmlFile;
  142. FILE* m_pXmlFile;
  143. };