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.

597 lines
18 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module SsDlg.cpp | Implementation of the Snapshot Set dialog
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 07/23/1999
  9. Revision History:
  10. Name Date Comments
  11. aoltean 07/23/1999 Created
  12. aoltean 08/05/1999 Splitting wizard functionality in a base class
  13. Removing some memory leaks
  14. Adding Test provider
  15. Fixing an assert
  16. aoltean 09/27/1999 Small changes
  17. --*/
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Includes
  20. #include "stdafx.hxx"
  21. #include "resource.h"
  22. #include "vsswprv.h"
  23. #include "GenDlg.h"
  24. #include "SwTstDlg.h"
  25. #include "SsDlg.h"
  26. #include "AsyncDlg.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Constants and defines
  34. #define STR2W(str) ((LPTSTR)((LPCTSTR)(str)))
  35. const WCHAR wszGUIDDefinition[] = L"{00000000-0000-0000-0000-000000000000}";
  36. const WCHAR wszVolumeDefinition[] = L"\\\\?\\Volume";
  37. const WCHAR wszHarddiskDefinition[] = L"\\Device\\Harddisk";
  38. const WCHAR wszDriveLetterDefinition[] = L"_:\\";
  39. // {F9566CC7-D588-416d-9243-921E93613C92}
  40. static const VSS_ID VSS_TESTAPP_SampleAppId =
  41. { 0xf9566cc7, 0xd588, 0x416d, { 0x92, 0x43, 0x92, 0x1e, 0x93, 0x61, 0x3c, 0x92 } };
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CSnapshotSetDlg dialog
  44. CSnapshotSetDlg::CSnapshotSetDlg(
  45. IVssCoordinator *pICoord,
  46. VSS_ID SnapshotSetId,
  47. CWnd* pParent /*=NULL*/
  48. )
  49. : CVssTestGenericDlg(CSnapshotSetDlg::IDD, pParent),
  50. m_pICoord(pICoord),
  51. m_SnapshotSetId(SnapshotSetId)
  52. {
  53. //{{AFX_DATA_INIT(CSnapshotSetDlg)
  54. //}}AFX_DATA_INIT
  55. m_strSnapshotSetId.Empty();
  56. m_nSnapshotsCount = 0;
  57. m_nAttributes = 0;
  58. m_bAsync = TRUE;
  59. m_bDo = false; // "Add" enabled by default
  60. m_pProvidersList = NULL;
  61. }
  62. CSnapshotSetDlg::~CSnapshotSetDlg()
  63. {
  64. if (m_pProvidersList)
  65. delete m_pProvidersList;
  66. /* REMOVED:
  67. if (m_pVolumesList)
  68. delete m_pVolumesList;
  69. */
  70. }
  71. void CSnapshotSetDlg::DoDataExchange(CDataExchange* pDX)
  72. {
  73. CVssTestGenericDlg::DoDataExchange(pDX);
  74. //{{AFX_DATA_MAP(CSnapshotSetDlg)
  75. DDX_Text(pDX, IDC_SS_ID, m_strSnapshotSetId);
  76. DDX_Text(pDX, IDC_SS_COUNT, m_nSnapshotsCount);
  77. DDX_Control(pDX, IDC_SS_VOLUMES, m_cbVolumes);
  78. DDX_Control(pDX, IDC_SS_PROVIDERS, m_cbProviders);
  79. DDX_Text(pDX, IDC_SS_ATTR, m_nAttributes);
  80. DDX_Check(pDX,IDC_SS_ASYNC, m_bAsync);
  81. //}}AFX_DATA_MAP
  82. }
  83. BEGIN_MESSAGE_MAP(CSnapshotSetDlg, CVssTestGenericDlg)
  84. //{{AFX_MSG_MAP(CSnapshotSetDlg)
  85. ON_BN_CLICKED(IDC_NEXT, OnNext)
  86. ON_BN_CLICKED(ID_BACK, OnBack)
  87. ON_BN_CLICKED(IDC_SS_ADD, OnAdd)
  88. ON_BN_CLICKED(IDC_SS_DO, OnDo)
  89. //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CSnapshotSetDlg message handlers
  93. void CSnapshotSetDlg::InitVolumes()
  94. {
  95. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CSnapshotSetDlg::InitVolumes" );
  96. USES_CONVERSION;
  97. try
  98. {
  99. HANDLE hSearch;
  100. WCHAR wszVolumeName[MAX_PATH];
  101. hSearch = ::FindFirstVolume(wszVolumeName, MAX_PATH);
  102. if (hSearch == INVALID_HANDLE_VALUE)
  103. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"FindfirstVolume cannot start an enumeration");
  104. while (true)
  105. {
  106. WCHAR wszEnumeratedDosVolumeName[4];
  107. WCHAR wszEnumeratedVolumeName[MAX_PATH];
  108. WCHAR wszLinkName[MAX_PATH];
  109. UCHAR wchDriveLetter;
  110. WCHAR chTmp;
  111. // Check if it is a hard-disk
  112. // TBD - generalize this code!!!
  113. chTmp = wszVolumeName[48];
  114. wszVolumeName[48] = L'\0';
  115. ::QueryDosDevice(&wszVolumeName[4], wszLinkName, MAX_PATH);
  116. wszVolumeName[48] = chTmp;
  117. if (::wcsncmp(wszLinkName, wszHarddiskDefinition, ::wcslen(wszHarddiskDefinition)) == 0)
  118. {
  119. // Get the DOS drive letter, if possible
  120. BOOL bFind = FALSE;
  121. wcscpy(wszEnumeratedDosVolumeName, wszDriveLetterDefinition);
  122. for (wchDriveLetter = L'A'; wchDriveLetter <= L'Z'; wchDriveLetter++)
  123. {
  124. wszEnumeratedDosVolumeName[0] = wchDriveLetter;
  125. ::GetVolumeNameForVolumeMountPoint(
  126. wszEnumeratedDosVolumeName,
  127. wszEnumeratedVolumeName,
  128. MAX_PATH
  129. );
  130. if (::wcscmp(wszVolumeName, wszEnumeratedVolumeName) == 0)
  131. {
  132. bFind = TRUE;
  133. break;
  134. }
  135. }
  136. // Inserting the volume into combo box.
  137. int nIndex = m_cbVolumes.AddString( W2T(bFind? wszEnumeratedDosVolumeName: wszVolumeName) );
  138. if (nIndex < 0)
  139. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error adding string in combo box");
  140. /* REMOVED
  141. // Getting the volume GUID
  142. GUID VolumeId;
  143. BS_ASSERT(::wcslen(wszVolumeDefinition) + ::wcslen(wszGUIDDefinition) + 1 == ::wcslen(wszVolumeName));
  144. WCHAR* pwszVolumeGuid = wszVolumeName + ::wcslen(wszVolumeDefinition);
  145. pwszVolumeGuid[::wcslen(wszGUIDDefinition)] = L'\0';
  146. ft.hr = ::CLSIDFromString(W2OLE(pwszVolumeGuid), &VolumeId);
  147. if ( ft.HrFailed() )
  148. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on recognizing Volume Id. hr = 0x%08lx", ft.hr);
  149. // Allocating a new item in the volume guid list
  150. GuidList* pVolumeGuid = new GuidList(VolumeId);
  151. if ( pVolumeGuid == NULL )
  152. ft.ErrBox( VSSDBG_VSSTEST, E_OUTOFMEMORY, L"Memory allocation error");
  153. // Inserting the volume into combo box.
  154. int nIndex = m_cbVolumes.AddString( W2T(bFind? wszEnumeratedDosVolumeName: wszVolumeName) );
  155. if (nIndex < 0)
  156. {
  157. delete pVolumeGuid;
  158. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error adding string in combo box");
  159. }
  160. int nResult = m_cbVolumes.SetItemDataPtr(nIndex, pVolumeGuid);
  161. if (nResult == CB_ERR)
  162. {
  163. delete pVolumeGuid;
  164. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error setting data to an item in combo box");
  165. }
  166. pVolumeGuid->m_pPrev = m_pVolumesList;
  167. m_pVolumesList = pVolumeGuid;
  168. */
  169. }
  170. // Find next volume
  171. BOOL bResult = ::FindNextVolume(hSearch, wszVolumeName, MAX_PATH);
  172. if (!bResult)
  173. break;
  174. }
  175. // Close enumeration
  176. ::FindVolumeClose(hSearch);
  177. // Select the first element
  178. if (m_cbVolumes.GetCount() > 0)
  179. m_cbVolumes.SetCurSel(0);
  180. }
  181. VSS_STANDARD_CATCH(ft)
  182. }
  183. void CSnapshotSetDlg::InitProviders()
  184. {
  185. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CSnapshotSetDlg::InitProviders" );
  186. USES_CONVERSION;
  187. try
  188. {
  189. //
  190. // Adding the Software provider item
  191. //
  192. // Allocating a GUID. It will be deallocated on OnClose
  193. GuidList* pProviderGuid = new GuidList(VSS_SWPRV_ProviderId);
  194. if ( pProviderGuid == NULL )
  195. ft.ErrBox( VSSDBG_VSSTEST, E_OUTOFMEMORY, L"Memory allocation error");
  196. // Inserting the software provider name into combo box.
  197. int nIndex = m_cbProviders.AddString( _T("Software Provider") );
  198. if (nIndex < 0)
  199. {
  200. delete pProviderGuid;
  201. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error adding string in combo box");
  202. }
  203. int nResult = m_cbProviders.SetItemDataPtr(nIndex, &(pProviderGuid->m_Guid));
  204. if (nResult == CB_ERR)
  205. {
  206. delete pProviderGuid;
  207. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error setting data to an item in combo box");
  208. }
  209. pProviderGuid->m_pPrev = m_pProvidersList;
  210. m_pProvidersList = pProviderGuid;
  211. //
  212. // Adding the NULL provider item
  213. //
  214. pProviderGuid = new GuidList(GUID_NULL);
  215. if ( pProviderGuid == NULL )
  216. ft.ErrBox( VSSDBG_VSSTEST, E_OUTOFMEMORY, L"Memory allocation error");
  217. // Inserting the software provider name into combo box.
  218. nIndex = m_cbProviders.AddString( _T("NULL Provider") );
  219. if (nIndex < 0)
  220. {
  221. delete pProviderGuid;
  222. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error adding string in combo box");
  223. }
  224. nResult = m_cbProviders.SetItemDataPtr(nIndex, &(pProviderGuid->m_Guid));
  225. if (nResult == CB_ERR)
  226. {
  227. delete pProviderGuid;
  228. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error setting data to an item in combo box");
  229. }
  230. pProviderGuid->m_pPrev = m_pProvidersList;
  231. m_pProvidersList = pProviderGuid;
  232. // Select the first element
  233. if (m_cbProviders.GetCount() > 0)
  234. m_cbProviders.SetCurSel(0);
  235. }
  236. VSS_STANDARD_CATCH(ft)
  237. }
  238. void CSnapshotSetDlg::InitMembers()
  239. {
  240. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CSnapshotSetDlg::InitMembers" );
  241. USES_CONVERSION;
  242. try
  243. {
  244. // Initializing the radio buttons // bug??
  245. BOOL bRes = ::CheckRadioButton( m_hWnd, IDC_SS_ADD, IDC_SS_ADD, IDC_SS_ADD );
  246. _ASSERTE( bRes );
  247. // Initializing Snapshot Set ID
  248. LPOLESTR strGUID;
  249. ft.hr = ::StringFromCLSID( m_SnapshotSetId, &strGUID );
  250. if ( ft.HrFailed() )
  251. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on calling StringFromCLSID. hr = 0x%08lx", ft.hr);
  252. m_strSnapshotSetId = OLE2T(strGUID);
  253. ::CoTaskMemFree(strGUID);
  254. }
  255. VSS_STANDARD_CATCH(ft)
  256. }
  257. BOOL CSnapshotSetDlg::OnInitDialog()
  258. {
  259. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CSnapshotSetDlg::OnInitDialog" );
  260. USES_CONVERSION;
  261. try
  262. {
  263. CVssTestGenericDlg::OnInitDialog();
  264. InitVolumes();
  265. InitProviders();
  266. InitMembers();
  267. UpdateData(FALSE);
  268. }
  269. VSS_STANDARD_CATCH(ft)
  270. return TRUE; // return TRUE unless you set the focus to a control
  271. }
  272. void CSnapshotSetDlg::OnNext()
  273. {
  274. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CSnapshotSetDlg::OnNext" );
  275. USES_CONVERSION;
  276. LPTSTR ptszVolumeName = NULL;
  277. try
  278. {
  279. UpdateData();
  280. if (m_bDo)
  281. {
  282. if (m_bAsync)
  283. {
  284. CComPtr<IVssAsync> pAsync;
  285. ft.hr = m_pICoord->DoSnapshotSet(
  286. NULL,
  287. &pAsync
  288. );
  289. if ( ft.HrFailed() )
  290. {
  291. BS_ASSERT(pAsync == NULL);
  292. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  293. L"Error on calling DoSnapshotSet. hr = 0x%08lx", ft.hr);
  294. }
  295. BS_ASSERT(pAsync);
  296. ShowWindow(SW_HIDE);
  297. CAsyncDlg dlg(pAsync);
  298. if (dlg.DoModal() == IDCANCEL)
  299. EndDialog(IDCANCEL);
  300. else
  301. ShowWindow(SW_SHOW);
  302. }
  303. else
  304. {
  305. ft.hr = m_pICoord->DoSnapshotSet(
  306. NULL,
  307. NULL
  308. );
  309. if ( ft.HrFailed() )
  310. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  311. L"Error on calling DoSnapshotSet. hr = 0x%08lx", ft.hr);
  312. }
  313. // Get all snapshot attributes
  314. if (m_pSnap)
  315. {
  316. /*
  317. VSS_OBJECT_PROP_Ptr ptrSnapshot;
  318. ptrSnapshot.InitializeAsSnapshot( ft,
  319. GUID_NULL,
  320. GUID_NULL,
  321. NULL,
  322. NULL,
  323. GUID_NULL,
  324. NULL,
  325. VSS_SWPRV_ProviderId,
  326. NULL,
  327. 0,
  328. 0,
  329. VSS_SS_UNKNOWN,
  330. 0,
  331. 0,
  332. 0,
  333. NULL
  334. );
  335. VSS_SNAPSHOT_PROP* pSnap = &(ptrSnapshot.GetStruct()->Obj.Snap);
  336. ft.hr = m_pSnap->GetProperties( pSnap);
  337. WCHAR wszBuffer[2048];
  338. ptrSnapshot.Print(ft, wszBuffer, 2048);
  339. ft.MsgBox( L"Results", wszBuffer);
  340. */
  341. LPWSTR wszName;
  342. ft.hr = m_pSnap->GetDevice( &wszName );
  343. if (ft.HrFailed())
  344. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  345. L"Error on getting the snapshot name 0x%08lx", ft.hr);
  346. ft.MsgBox( L"Snapshot name = %s", wszName);
  347. ::VssFreeString(wszName);
  348. }
  349. ft.MsgBox( L"OK", L"Snapshot Set created!" );
  350. EndDialog(IDOK);
  351. }
  352. else
  353. {
  354. // Getting the Volume Id
  355. int nIndex = m_cbVolumes.GetCurSel();
  356. if (nIndex == CB_ERR)
  357. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on getting the currently selected volume");
  358. // REMOVED: GUID* pVolumeGuid = (GUID*)m_cbVolumes.GetItemDataPtr(nIndex);
  359. int nBufferLen = m_cbVolumes.GetLBTextLen(nIndex);
  360. if (nBufferLen == CB_ERR)
  361. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on getting the currently selected volume");
  362. ptszVolumeName = new TCHAR[nBufferLen+1];
  363. if (ptszVolumeName == NULL)
  364. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on getting the currently selected volume");
  365. if ( m_cbVolumes.GetLBText( nIndex, ptszVolumeName ) == CB_ERR)
  366. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on getting the currently selected volume");
  367. LPWSTR pwszVolumeName = T2W(ptszVolumeName);
  368. // Getting the Provider Id
  369. nIndex = m_cbProviders.GetCurSel();
  370. if (nIndex == CB_ERR)
  371. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on getting the currently selected provider");
  372. GUID* pProviderGuid = (GUID*)m_cbProviders.GetItemDataPtr(nIndex);
  373. if ( *pProviderGuid == VSS_SWPRV_ProviderId )
  374. {
  375. CComPtr<IVssSnapshot> pSnapshot;
  376. m_pSnap = NULL;
  377. ft.hr = m_pICoord->AddToSnapshotSet(
  378. pwszVolumeName,
  379. VSS_SWPRV_ProviderId,
  380. &m_pSnap
  381. );
  382. if ( ft.HrFailed() )
  383. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on calling AddToSnapshotSet. hr = 0x%08lx", ft.hr);
  384. // Increment the number of snapshots
  385. m_nSnapshotsCount++;
  386. }
  387. else if ( *pProviderGuid == GUID_NULL )
  388. {
  389. #if 0
  390. // Software provider
  391. ShowWindow(SW_HIDE);
  392. CSoftwareSnapshotTestDlg dlg;
  393. if (dlg.DoModal() == IDCANCEL)
  394. EndDialog(IDCANCEL);
  395. else
  396. ShowWindow(SW_SHOW);
  397. // See if it is read-only
  398. if (! dlg.m_bReadOnly)
  399. lAttributes |= VSS_VOLSNAP_ATTR_READ_WRITE;
  400. else
  401. lAttributes &= ~VSS_VOLSNAP_ATTR_READ_WRITE;
  402. #endif
  403. m_pSnap = NULL;
  404. ft.hr = m_pICoord->AddToSnapshotSet(
  405. pwszVolumeName,
  406. *pProviderGuid,
  407. &m_pSnap
  408. );
  409. if ( ft.HrFailed() )
  410. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Error on calling AddToSnapshotSet. hr = 0x%08lx", ft.hr);
  411. /*
  412. CComPtr<IVsSoftwareSnapshot> pSnapshot;
  413. ft.hr = m_pSnap->SafeQI( IVsSoftwareSnapshot, &pSnapshot );
  414. if ( ft.HrFailed() )
  415. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  416. L"Error querying the IVssSnapshot interface. hr = 0x%08lx", ft.hr);
  417. BS_ASSERT( m_pSnap != NULL);
  418. ft.hr = pSnapshot->SetInitialAllocation( dlg.m_nLogFileSize*1024*1024 );
  419. if ( ft.HrFailed() )
  420. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED,
  421. L"Error on calling SetInitialAllocation. hr = 0x%08lx", ft.hr);
  422. */
  423. // Increment the number of snapshots
  424. m_nSnapshotsCount++;
  425. }
  426. else
  427. {
  428. BS_ASSERT( false );
  429. }
  430. CWnd* pWnd = GetDlgItem(IDC_SS_DO);
  431. if (pWnd)
  432. pWnd->EnableWindow(TRUE);
  433. UpdateData(FALSE);
  434. }
  435. }
  436. VSS_STANDARD_CATCH(ft)
  437. delete ptszVolumeName;
  438. }
  439. void CSnapshotSetDlg::OnBack()
  440. {
  441. EndDialog(ID_BACK);
  442. }
  443. void CSnapshotSetDlg::OnClose()
  444. {
  445. CVssTestGenericDlg::OnClose();
  446. }
  447. void CSnapshotSetDlg::EnableGroup()
  448. {
  449. CWnd *pWnd;
  450. pWnd = GetDlgItem(IDC_SS_VOLUMES);
  451. if (pWnd)
  452. pWnd->EnableWindow(!m_bDo);
  453. pWnd = GetDlgItem(IDC_SS_PROVIDERS);
  454. if (pWnd)
  455. pWnd->EnableWindow(!m_bDo);
  456. /*
  457. pWnd = GetDlgItem(IDC_SS_ATTR);
  458. if (pWnd)
  459. pWnd->EnableWindow(!m_bDo);
  460. */
  461. /*
  462. pWnd = GetDlgItem(IDC_SS_PARTIAL_COMMIT);
  463. if (pWnd)
  464. pWnd->EnableWindow(m_bDo);
  465. pWnd = GetDlgItem(IDC_SS_WRITER_VETOES);
  466. if (pWnd)
  467. pWnd->EnableWindow(m_bDo);
  468. pWnd = GetDlgItem(IDC_SS_WRITER_CANCEL);
  469. if (pWnd)
  470. pWnd->EnableWindow(m_bDo);
  471. pWnd = GetDlgItem(IDC_SS_ASYNC);
  472. if (pWnd)
  473. pWnd->EnableWindow(m_bDo);
  474. */
  475. }
  476. void CSnapshotSetDlg::OnAdd()
  477. {
  478. m_bDo = FALSE;
  479. EnableGroup();
  480. }
  481. void CSnapshotSetDlg::OnDo()
  482. {
  483. m_bDo = TRUE;
  484. EnableGroup();
  485. }