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.

352 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module DiffDlg.cpp | Implementation of the diff dialog
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 01/25/2000
  9. Revision History:
  10. Name Date Comments
  11. aoltean 01/25/2000 Created
  12. --*/
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Includes
  15. #include "stdafx.hxx"
  16. #include "resource.h"
  17. #include "vsswprv.h"
  18. #include "GenDlg.h"
  19. #include "VssTest.h"
  20. #include "DiffDlg.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. #define STR2W(str) ((LPTSTR)((LPCTSTR)(str)))
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CDiffDlg dialog
  29. CDiffDlg::CDiffDlg(
  30. IVssCoordinator *pICoord,
  31. CWnd* pParent /*=NULL*/
  32. )
  33. : CVssTestGenericDlg(CDiffDlg::IDD, pParent), m_pICoord(pICoord)
  34. {
  35. //{{AFX_DATA_INIT(CDiffDlg)
  36. m_strVolumeName.Empty();
  37. m_strVolumeMountPoint.Empty();
  38. m_strVolumeDevice.Empty();
  39. m_strVolumeID.Empty();
  40. m_strUsedBytes.Empty();
  41. m_strAllocatedBytes.Empty();
  42. m_strMaximumBytes.Empty();
  43. //}}AFX_DATA_INIT
  44. }
  45. CDiffDlg::~CDiffDlg()
  46. {
  47. }
  48. void CDiffDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CVssTestGenericDlg::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CDiffDlg)
  52. DDX_Text(pDX, IDC_DIFF_VOLUME_NAME, m_strVolumeName);
  53. DDX_Text(pDX, IDC_DIFF_MOUNT, m_strVolumeMountPoint);
  54. DDX_Text(pDX, IDC_DIFF_DEVICE, m_strVolumeDevice);
  55. DDX_Text(pDX, IDC_DIFF_VOLUME_ID, m_strVolumeID);
  56. DDX_Text(pDX, IDC_DIFF_USED, m_strUsedBytes);
  57. DDX_Text(pDX, IDC_DIFF_ALLOCATED, m_strAllocatedBytes);
  58. DDX_Text(pDX, IDC_DIFF_MAXIMUM, m_strMaximumBytes);
  59. //}}AFX_DATA_MAP
  60. }
  61. BEGIN_MESSAGE_MAP(CDiffDlg, CVssTestGenericDlg)
  62. //{{AFX_MSG_MAP(CDiffDlg)
  63. ON_BN_CLICKED(IDC_NEXT, OnNext)
  64. ON_BN_CLICKED(IDC_DIFF_ADD_VOL, OnAddVol)
  65. ON_BN_CLICKED(IDC_DIFF_QUERY_DIFF, OnQueryDiff)
  66. ON_BN_CLICKED(IDC_DIFF_CLEAR_DIFF, OnClearDiff)
  67. ON_BN_CLICKED(IDC_DIFF_GET_SIZES, OnGetSizes)
  68. ON_BN_CLICKED(IDC_DIFF_SET_ALLOCATED, OnSetAllocated)
  69. ON_BN_CLICKED(IDC_DIFF_SET_MAXIMUM, OnSetMaximum)
  70. ON_BN_CLICKED(IDC_DIFF_NEXT_VOLUME, OnNextVolume)
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CDiffDlg message handlers
  75. BOOL CDiffDlg::OnInitDialog()
  76. {
  77. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CDiffDlg::OnInitDialog" );
  78. try
  79. {
  80. CVssTestGenericDlg::OnInitDialog();
  81. m_eMethodType = VSST_F_ADD_VOL;
  82. BOOL bRes = ::CheckRadioButton( m_hWnd,
  83. IDC_DIFF_ADD_VOL,
  84. IDC_DIFF_SET_MAXIMUM,
  85. IDC_DIFF_ADD_VOL );
  86. _ASSERTE( bRes );
  87. UpdateData( FALSE );
  88. }
  89. VSS_STANDARD_CATCH(ft)
  90. return TRUE; // return TRUE unless you set the focus to a control
  91. }
  92. void CDiffDlg::OnNext()
  93. {
  94. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CDiffDlg::OnNext" );
  95. USES_CONVERSION;
  96. /*
  97. try
  98. {
  99. UpdateData();
  100. // Get the volume mount point
  101. LPWSTR pwszVolumeMountPoint = T2W(const_cast<LPTSTR>(LPCTSTR(m_strVolumeName)));
  102. // Get the diff area interface
  103. m_pIDiffArea = NULL;
  104. ft.hr = m_pICoord->GetExtension(
  105. VSS_SWPRV_ProviderId,
  106. pwszVolumeMountPoint,
  107. IID_IVsDiffArea,
  108. reinterpret_cast<IUnknown**>(&m_pIDiffArea)
  109. );
  110. if (ft.HrFailed())
  111. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error getting the diff area interface 0x%08lx", ft.hr);
  112. switch(m_eMethodType)
  113. {
  114. case VSST_F_ADD_VOL:
  115. {
  116. // Get the volume mount point
  117. LPWSTR pwszVolumeMountPoint = T2W(const_cast<LPTSTR>(LPCTSTR(m_strVolumeMountPoint)));
  118. // Add the volume
  119. BS_ASSERT(m_pIDiffArea);
  120. ft.hr = m_pIDiffArea->AddVolume(pwszVolumeMountPoint);
  121. if (ft.HrFailed())
  122. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  123. L"Error adding the volume 0x%08lx", ft.hr);
  124. }
  125. break;
  126. case VSST_F_QUERY_DIFF:
  127. {
  128. // Query the diff area
  129. BS_ASSERT(m_pIDiffArea);
  130. m_pEnum = NULL;
  131. ft.hr = m_pIDiffArea->Query(&m_pEnum);
  132. if (ft.HrFailed())
  133. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  134. L"Error querying the volumes 0x%08lx", ft.hr);
  135. // Enable the "Next volume" button
  136. if (CWnd *pWnd = GetDlgItem(IDC_DIFF_NEXT_VOLUME))
  137. pWnd->EnableWindow(true);
  138. // Print hte results for the first volume
  139. OnNextVolume();
  140. }
  141. break;
  142. case VSST_F_CLEAR_DIFF:
  143. {
  144. // Query the diff area
  145. BS_ASSERT(m_pIDiffArea);
  146. ft.hr = m_pIDiffArea->Clear();
  147. if (ft.HrFailed())
  148. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  149. L"Error clearing the diff area 0x%08lx", ft.hr);
  150. }
  151. break;
  152. case VSST_F_GET_SIZES:
  153. {
  154. // Get the used space
  155. BS_ASSERT(m_pIDiffArea);
  156. LONGLONG llTmp;
  157. ft.hr = m_pIDiffArea->GetUsedVolumeSpace(&llTmp);
  158. if (ft.HrFailed())
  159. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  160. L"Error getting the used disk space 0x%08lx", ft.hr);
  161. m_strUsedBytes.Format( L"%ld", (LONG)(llTmp / 1024) );
  162. ft.hr = m_pIDiffArea->GetAllocatedVolumeSpace(&llTmp);
  163. if (ft.HrFailed())
  164. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  165. L"Error getting the allocated disk space 0x%08lx", ft.hr);
  166. m_strAllocatedBytes.Format( L"%ld", (LONG)(llTmp / 1024) );
  167. ft.hr = m_pIDiffArea->GetMaximumVolumeSpace(&llTmp);
  168. if (ft.HrFailed())
  169. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  170. L"Error getting the max disk space 0x%08lx", ft.hr);
  171. m_strMaximumBytes.Format( L"%ld", (LONG)(llTmp / 1024) );
  172. UpdateData( FALSE );
  173. }
  174. break;
  175. case VSST_F_SET_ALLOCATED:
  176. {
  177. LONG lTmp = 0;
  178. LPWSTR wszSpace = T2W((LPTSTR)(LPCTSTR)m_strAllocatedBytes);
  179. if ( 0==swscanf(wszSpace, L"%ld", &lTmp))
  180. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  181. L"Error getting the allocated disk space from %s", wszSpace);
  182. if ( lTmp < 0)
  183. ft.MsgBox(L"Error", L"Negative allocated space %ld", lTmp);
  184. // Set the allocated space
  185. BS_ASSERT(m_pIDiffArea);
  186. LONGLONG llTmp;
  187. ft.hr = m_pIDiffArea->SetAllocatedVolumeSpace(((LONGLONG)lTmp)*1024);
  188. if (ft.HrFailed())
  189. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  190. L"Error setting the allocated disk space 0x%08lx", ft.hr);
  191. }
  192. break;
  193. case VSST_F_SET_MAXIMUM:
  194. {
  195. LONG lTmp = 0;
  196. LPWSTR wszSpace = T2W((LPTSTR)(LPCTSTR)m_strMaximumBytes);
  197. if ( 0==swscanf(wszSpace, L"%ld", &lTmp))
  198. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  199. L"Error getting the maximum disk space from %s", wszSpace);
  200. if ( lTmp < 0)
  201. ft.MsgBox(L"Error", L"Negative maximum space %ld", lTmp);
  202. // Set the maximum space
  203. BS_ASSERT(m_pIDiffArea);
  204. LONGLONG llTmp;
  205. ft.hr = m_pIDiffArea->SetMaximumVolumeSpace(((LONGLONG)lTmp)*1024);
  206. if (ft.HrFailed())
  207. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  208. L"Error setting the maximum disk space 0x%08lx", ft.hr);
  209. }
  210. break;
  211. default:
  212. BS_ASSERT(false);
  213. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Invalid method type");
  214. }
  215. }
  216. VSS_STANDARD_CATCH(ft)
  217. */
  218. }
  219. void CDiffDlg::OnAddVol()
  220. {
  221. m_eMethodType = VSST_F_ADD_VOL;
  222. }
  223. void CDiffDlg::OnQueryDiff()
  224. {
  225. m_eMethodType = VSST_F_QUERY_DIFF;
  226. }
  227. void CDiffDlg::OnClearDiff()
  228. {
  229. m_eMethodType = VSST_F_CLEAR_DIFF;
  230. }
  231. void CDiffDlg::OnGetSizes()
  232. {
  233. m_eMethodType = VSST_F_GET_SIZES;
  234. }
  235. void CDiffDlg::OnSetAllocated()
  236. {
  237. m_eMethodType = VSST_F_SET_ALLOCATED;
  238. }
  239. void CDiffDlg::OnSetMaximum()
  240. {
  241. m_eMethodType = VSST_F_SET_MAXIMUM;
  242. }
  243. void CDiffDlg::OnNextVolume()
  244. {
  245. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CDiffDlg::OnNextVolume");
  246. if (m_pEnum == NULL)
  247. return;
  248. /*
  249. // Empty the volume fields
  250. m_strVolumeDevice.Empty();
  251. m_strVolumeID.Empty();
  252. m_strVolumeMountPoint.Empty();
  253. // Get the properties
  254. VSS_OBJECT_PROP_Ptr ptrObjProp;
  255. ptrObjProp.InitializeAsEmpty(ft);
  256. VSS_OBJECT_PROP* pProp = ptrObjProp.GetStruct();
  257. BS_ASSERT(pProp);
  258. ULONG ulFetched;
  259. ft.hr = m_pEnum->Next(1, pProp, &ulFetched);
  260. if (ft.HrFailed())
  261. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  262. L"Error querying the next volume 0x%08lx", ft.hr);
  263. // If this is the last volume then disable enumeration
  264. if (ft.hr == S_FALSE)
  265. {
  266. ft.Trace( VSSDBG_VSSTEST, L"End of enumeration");
  267. if (CWnd *pWnd = GetDlgItem(IDC_DIFF_NEXT_VOLUME))
  268. pWnd->EnableWindow(false);
  269. }
  270. // Fill the dialog fields
  271. if (pProp->Type == VSS_OBJECT_VOLUME)
  272. {
  273. VSS_VOLUME_PROP* pVolProp = &(pProp->Obj.Vol);
  274. if (pVolProp->m_pwszVolumeName)
  275. m_strVolumeMountPoint.Format(L"%s", pVolProp->m_pwszVolumeName);
  276. if (pVolProp->m_pwszVolumeDeviceObject)
  277. m_strVolumeDevice.Format(L"%s", pVolProp->m_pwszVolumeDeviceObject);
  278. m_strVolumeID.Format( WSTR_GUID_FMT, GUID_PRINTF_ARG(pVolProp->m_VolumeId) );
  279. }
  280. */
  281. UpdateData( FALSE );
  282. }