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.

204 lines
6.6 KiB

  1. // Hosting.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "utils.h"
  5. #include "Hosting.h"
  6. #include "uihelp.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CHosting dialog
  14. CHosting::CHosting(CWnd* pParent /*=NULL*/)
  15. : CDialog(CHosting::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CHosting)
  18. m_strVolume = _T("");
  19. //}}AFX_DATA_INIT
  20. m_strComputer = _T("");
  21. }
  22. CHosting::CHosting(LPCTSTR pszComputer, LPCTSTR pszVolume, CWnd* pParent /*=NULL*/)
  23. : CDialog(CHosting::IDD, pParent)
  24. {
  25. m_strComputer = pszComputer + (TWO_WHACKS(pszComputer) ? 2 : 0);
  26. m_strVolume = pszVolume;
  27. }
  28. void CHosting::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CHosting)
  32. DDX_Control(pDX, IDC_HOSTING_FREE_DISKSPACE, m_ctrlFreeSpace);
  33. DDX_Control(pDX, IDC_HOSTING_TOTAL_DISKSPACE, m_ctrlTotalSpace);
  34. DDX_Control(pDX, IDC_HOSTING_VOLUMELIST, m_ctrlVolumeList);
  35. DDX_Text(pDX, IDC_HOSTING_VOLUME, m_strVolume);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CHosting, CDialog)
  39. //{{AFX_MSG_MAP(CHosting)
  40. ON_WM_CONTEXTMENU()
  41. ON_WM_HELPINFO()
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CHosting message handlers
  46. BOOL CHosting::OnInitDialog()
  47. {
  48. CDialog::OnInitDialog();
  49. // init listview control
  50. HWND hwnd = m_ctrlVolumeList.m_hWnd;
  51. AddLVColumns(
  52. hwnd,
  53. IDS_HOSTINGLIST_COLUMN_VOLUME,
  54. IDS_HOSTINGLIST_COLUMN_DIFFLIMITS - IDS_HOSTINGLIST_COLUMN_VOLUME + 1);
  55. ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT);
  56. CString strNoLimits;
  57. strNoLimits.LoadString(IDS_NOLIMITS);
  58. TCHAR szDiskSpace[MAX_PATH];
  59. DWORD dwSize = 0;
  60. int nIndex = 0;
  61. LVITEM lvItem = {0};
  62. for (VSSUI_DIFFAREA_LIST::iterator i = m_DiffAreaList.begin(); i != m_DiffAreaList.end(); i++)
  63. {
  64. ZeroMemory(&lvItem, sizeof(LVITEM));
  65. lvItem.mask = LVIF_TEXT;
  66. lvItem.pszText = (*i)->pszVolumeDisplayName;
  67. lvItem.iSubItem = 0;
  68. nIndex = m_ctrlVolumeList.InsertItem(&lvItem);
  69. lvItem.iItem = nIndex;
  70. if ((*i)->llMaximumDiffSpace == VSS_ASSOC_NO_MAX_SPACE)
  71. {
  72. lvItem.pszText = (PTSTR)(LPCTSTR)strNoLimits;
  73. } else
  74. {
  75. dwSize = sizeof(szDiskSpace)/sizeof(TCHAR);
  76. DiskSpaceToString((*i)->llMaximumDiffSpace, szDiskSpace, &dwSize);
  77. lvItem.pszText = szDiskSpace;
  78. }
  79. lvItem.iSubItem = IDS_HOSTINGLIST_COLUMN_DIFFLIMITS - IDS_HOSTINGLIST_COLUMN_VOLUME;
  80. m_ctrlVolumeList.SetItem(&lvItem);
  81. dwSize = sizeof(szDiskSpace)/sizeof(TCHAR);
  82. DiskSpaceToString((*i)->llUsedDiffSpace, szDiskSpace, &dwSize);
  83. lvItem.pszText = szDiskSpace;
  84. lvItem.iSubItem = IDS_HOSTINGLIST_COLUMN_DIFFCONSUMPTION - IDS_HOSTINGLIST_COLUMN_VOLUME;
  85. m_ctrlVolumeList.SetItem(&lvItem);
  86. }
  87. dwSize = sizeof(szDiskSpace)/sizeof(TCHAR);
  88. DiskSpaceToString(m_llDiffVolumeFreeSpace, szDiskSpace, &dwSize);
  89. m_ctrlFreeSpace.SetWindowText(szDiskSpace);
  90. dwSize = sizeof(szDiskSpace)/sizeof(TCHAR);
  91. DiskSpaceToString(m_llDiffVolumeTotalSpace, szDiskSpace, &dwSize);
  92. m_ctrlTotalSpace.SetWindowText(szDiskSpace);
  93. return TRUE; // return TRUE unless you set the focus to a control
  94. // EXCEPTION: OCX Property Pages should return FALSE
  95. }
  96. HRESULT CHosting::Init(
  97. IVssDifferentialSoftwareSnapshotMgmt* i_piDiffSnapMgmt,
  98. VSSUI_VOLUME_LIST* i_pVolumeList,
  99. IN LPCTSTR i_pszVolumeDisplayName,
  100. IN ULONGLONG i_llDiffVolumeTotalSpace,
  101. IN ULONGLONG i_llDiffVolumeFreeSpace
  102. )
  103. {
  104. if (!i_piDiffSnapMgmt ||
  105. !i_pVolumeList ||
  106. !i_pszVolumeDisplayName || !*i_pszVolumeDisplayName)
  107. return E_INVALIDARG;
  108. m_strVolume = i_pszVolumeDisplayName;
  109. m_llDiffVolumeTotalSpace = i_llDiffVolumeTotalSpace;
  110. m_llDiffVolumeFreeSpace = i_llDiffVolumeFreeSpace;
  111. FreeDiffAreaList(&m_DiffAreaList);
  112. CComPtr<IVssEnumMgmtObject> spiEnum;
  113. HRESULT hr = i_piDiffSnapMgmt->QueryDiffAreasOnVolume((PTSTR)i_pszVolumeDisplayName, &spiEnum);
  114. if (FAILED(hr))
  115. return hr;
  116. VSS_MGMT_OBJECT_PROP Prop;
  117. VSS_DIFF_AREA_PROP* pDiffAreaProp = &(Prop.Obj.DiffArea);
  118. ULONG ulFetched = 0;
  119. while (SUCCEEDED(spiEnum->Next(1, &Prop, &ulFetched)) && ulFetched > 0)
  120. {
  121. if (VSS_MGMT_OBJECT_DIFF_AREA != Prop.Type)
  122. return E_FAIL;
  123. VSSUI_DIFFAREA *pDiffAreaInfo = (VSSUI_DIFFAREA *)calloc(1, sizeof(VSSUI_DIFFAREA));
  124. if (pDiffAreaInfo)
  125. {
  126. PTSTR pszVolumeDisplayName = GetDisplayName(i_pVolumeList, pDiffAreaProp->m_pwszVolumeName);
  127. PTSTR pszDiffVolumeDisplayName = GetDisplayName(i_pVolumeList, pDiffAreaProp->m_pwszDiffAreaVolumeName);
  128. if (pszVolumeDisplayName && pszDiffVolumeDisplayName)
  129. {
  130. lstrcpyn(pDiffAreaInfo->pszVolumeDisplayName, pszVolumeDisplayName, MAX_PATH);
  131. lstrcpyn(pDiffAreaInfo->pszDiffVolumeDisplayName, pszDiffVolumeDisplayName, MAX_PATH);
  132. pDiffAreaInfo->llMaximumDiffSpace = pDiffAreaProp->m_llMaximumDiffSpace;
  133. pDiffAreaInfo->llUsedDiffSpace = pDiffAreaProp->m_llAllocatedDiffSpace;
  134. m_DiffAreaList.push_back(pDiffAreaInfo);
  135. } else
  136. {
  137. free(pDiffAreaInfo); // indicate something inconsistent happened on the DiffVol, disgard this result.
  138. }
  139. } else
  140. {
  141. FreeDiffAreaList(&m_DiffAreaList);
  142. hr = E_OUTOFMEMORY;
  143. }
  144. ::CoTaskMemFree(pDiffAreaProp->m_pwszVolumeName);
  145. ::CoTaskMemFree(pDiffAreaProp->m_pwszDiffAreaVolumeName);
  146. }
  147. return hr;
  148. }
  149. void CHosting::OnContextMenu(CWnd* pWnd, CPoint point)
  150. {
  151. if (!pWnd)
  152. return;
  153. ::WinHelp(pWnd->GetSafeHwnd(),
  154. VSSUI_CTX_HELP_FILE,
  155. HELP_CONTEXTMENU,
  156. (DWORD_PTR)(PVOID)aMenuHelpIDsForViewFiles);
  157. }
  158. BOOL CHosting::OnHelpInfo(HELPINFO* pHelpInfo)
  159. {
  160. if (!pHelpInfo ||
  161. pHelpInfo->iContextType != HELPINFO_WINDOW ||
  162. pHelpInfo->iCtrlId < 0)
  163. return FALSE;
  164. ::WinHelp((HWND)pHelpInfo->hItemHandle,
  165. VSSUI_CTX_HELP_FILE,
  166. HELP_WM_HELP,
  167. (DWORD_PTR)(PVOID)aMenuHelpIDsForViewFiles);
  168. return TRUE;
  169. }