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.

585 lines
16 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. PrMrLvl.cpp
  5. Abstract:
  6. Managed Volume Levels Page
  7. Author:
  8. Art Bragg [abragg] 08-Aug-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "PrMrLvl.h"
  13. #include "manvol.h"
  14. static DWORD pHelpIds[] =
  15. {
  16. IDC_STATIC_ACTUAL_FREE_PCT, idh_actual_free_space_percent,
  17. IDC_STATIC_ACTUAL_FREE_PCT_LABEL, idh_actual_free_space_percent,
  18. IDC_STATIC_ACTUAL_FREE_PCT_UNIT, idh_actual_free_space_percent,
  19. IDC_STATIC_FREE_ACTUAL_4DIGIT, idh_actual_free_space_capacity,
  20. IDC_EDIT_LEVEL, idh_desired_free_space_percent,
  21. IDC_SPIN_LEVEL, idh_desired_free_space_percent,
  22. IDC_EDIT_LEVEL_LABEL, idh_desired_free_space_percent,
  23. IDC_EDIT_LEVEL_UNIT, idh_desired_free_space_percent,
  24. IDC_STATIC_FREE_DESIRED_4DIGIT, idh_desired_free_space_capacity,
  25. IDC_EDIT_SIZE, idh_min_file_size_criteria,
  26. IDC_SPIN_SIZE, idh_min_file_size_criteria,
  27. IDC_EDIT_SIZE_LABEL, idh_min_file_size_criteria,
  28. IDC_EDIT_SIZE_UNIT, idh_min_file_size_criteria,
  29. IDC_EDIT_TIME, idh_file_access_date_criteria,
  30. IDC_SPIN_TIME, idh_file_access_date_criteria,
  31. IDC_EDIT_TIME_LABEL, idh_file_access_date_criteria,
  32. IDC_EDIT_TIME_UNIT, idh_file_access_date_criteria,
  33. 0, 0
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CPrMrLvl property page
  37. CPrMrLvl::CPrMrLvl() : CSakVolPropPage(CPrMrLvl::IDD)
  38. {
  39. //{{AFX_DATA_INIT(CPrMrLvl)
  40. m_hsmLevel = 0;
  41. m_fileSize = 0;
  42. m_accessTime = 0;
  43. //}}AFX_DATA_INIT
  44. m_hConsoleHandle = NULL;
  45. m_capacity = 0;
  46. m_fChangingByCode = FALSE;
  47. m_pHelpIds = pHelpIds;
  48. }
  49. CPrMrLvl::~CPrMrLvl()
  50. {
  51. }
  52. void CPrMrLvl::DoDataExchange(CDataExchange* pDX)
  53. {
  54. CSakVolPropPage::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CPrMrLvl)
  56. DDX_Control(pDX, IDC_STATIC_FREE_ACTUAL_4DIGIT, m_staticActual4Digit);
  57. DDX_Control(pDX, IDC_STATIC_FREE_DESIRED_4DIGIT, m_staticDesired4Digit);
  58. DDX_Control(pDX, IDC_EDIT_TIME, m_editTime);
  59. DDX_Control(pDX, IDC_EDIT_SIZE, m_editSize);
  60. DDX_Control(pDX, IDC_EDIT_LEVEL, m_editLevel);
  61. DDX_Control(pDX, IDC_SPIN_TIME, m_spinTime);
  62. DDX_Control(pDX, IDC_SPIN_SIZE, m_spinSize);
  63. DDX_Control(pDX, IDC_SPIN_LEVEL, m_spinLevel);
  64. //}}AFX_DATA_MAP
  65. // blank is valid for multi-select
  66. if( m_bMultiSelect ) {
  67. CString szLevel;
  68. CString szSize;
  69. CString szDays;
  70. m_editLevel.GetWindowText( szLevel );
  71. m_editSize.GetWindowText( szSize );
  72. m_editTime.GetWindowText( szDays );
  73. if( szLevel != L"" ) {
  74. DDX_Text( pDX, IDC_EDIT_LEVEL, m_hsmLevel );
  75. DDV_MinMaxLong( pDX, m_hsmLevel, HSMADMIN_MIN_FREESPACE, HSMADMIN_MAX_FREESPACE );
  76. } else {
  77. m_hsmLevel = HSMADMIN_DEFAULT_MINSIZE;
  78. }
  79. if( szSize != L"" ) {
  80. DDX_Text( pDX, IDC_EDIT_SIZE, m_fileSize );
  81. DDV_MinMaxDWord( pDX, m_fileSize, HSMADMIN_MIN_MINSIZE, HSMADMIN_MAX_MINSIZE );
  82. } else {
  83. m_fileSize = HSMADMIN_DEFAULT_FREESPACE;
  84. }
  85. if( szDays != L"" ) {
  86. DDX_Text( pDX, IDC_EDIT_TIME, m_accessTime );
  87. DDV_MinMaxUInt( pDX, m_accessTime, HSMADMIN_MIN_INACTIVITY, HSMADMIN_MAX_INACTIVITY );
  88. } else {
  89. m_accessTime = HSMADMIN_DEFAULT_INACTIVITY;
  90. }
  91. } else {
  92. //
  93. // Normal validation for single select
  94. //
  95. DDX_Text( pDX, IDC_EDIT_LEVEL, m_hsmLevel );
  96. DDV_MinMaxLong( pDX, m_hsmLevel, HSMADMIN_MIN_FREESPACE, HSMADMIN_MAX_FREESPACE );
  97. DDX_Text( pDX, IDC_EDIT_TIME, m_accessTime );
  98. DDV_MinMaxUInt( pDX, m_accessTime, HSMADMIN_MIN_INACTIVITY, HSMADMIN_MAX_INACTIVITY );
  99. DDX_Text( pDX, IDC_EDIT_SIZE, m_fileSize );
  100. //
  101. // Since we limit the number of characters in the buddy edits, we
  102. // don't expect the previous two DDV's to ever really kick in.
  103. // However, it is possible to enter bad minumum size since both
  104. // '0' and '1' can be entered, but are not in the valid range.
  105. //
  106. // Code is equivalent to:
  107. // DDV_MinMaxDWord( pDX, m_fileSize, HSMADMIN_MIN_MINSIZE, HSMADMIN_MAX_MINSIZE );
  108. //
  109. if( pDX->m_bSaveAndValidate &&
  110. ( m_fileSize < HSMADMIN_MIN_MINSIZE ||
  111. m_fileSize > HSMADMIN_MAX_MINSIZE ) ) {
  112. CString message;
  113. AfxFormatString2( message, IDS_ERR_MINSIZE_RANGE,
  114. CString( WsbLongAsString( (LONG)HSMADMIN_MIN_MINSIZE ) ),
  115. CString( WsbLongAsString( (LONG)HSMADMIN_MAX_MINSIZE ) ) );
  116. AfxMessageBox( message, MB_OK | MB_ICONWARNING );
  117. pDX->Fail();
  118. }
  119. }
  120. }
  121. BEGIN_MESSAGE_MAP(CPrMrLvl, CSakVolPropPage)
  122. //{{AFX_MSG_MAP(CPrMrLvl)
  123. ON_EN_CHANGE(IDC_EDIT_LEVEL, OnChangeEditLevel)
  124. ON_EN_CHANGE(IDC_EDIT_SIZE, OnChangeEditSize)
  125. ON_EN_CHANGE(IDC_EDIT_TIME, OnChangeEditTime)
  126. //}}AFX_MSG_MAP
  127. END_MESSAGE_MAP()
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CPrMrLvl message handlers
  130. BOOL CPrMrLvl::OnInitDialog()
  131. {
  132. HRESULT hr = 0;
  133. CSakVolPropPage::OnInitDialog();
  134. int freePct;
  135. try {
  136. m_bMultiSelect = ( m_pParent->IsMultiSelect() == S_OK );
  137. // Set the spinner ranges
  138. m_spinTime.SetRange( HSMADMIN_MIN_INACTIVITY, HSMADMIN_MAX_INACTIVITY );
  139. m_spinSize.SetRange( HSMADMIN_MIN_MINSIZE, HSMADMIN_MAX_MINSIZE );
  140. m_spinLevel.SetRange( HSMADMIN_MIN_FREESPACE, HSMADMIN_MAX_FREESPACE );
  141. // Set text limits
  142. m_editTime.SetLimitText( 3 );
  143. m_editSize.SetLimitText( 5 );
  144. m_editLevel.SetLimitText( 2 );
  145. if( !m_bMultiSelect )
  146. {
  147. // Single Select
  148. // Show the byte display of desired free space
  149. m_staticDesired4Digit.ShowWindow( SW_SHOW );
  150. m_staticActual4Digit.ShowWindow( SW_SHOW );
  151. // Get the single Fsa Resource pointer
  152. WsbAffirmHr ( m_pVolParent->GetFsaResource( &m_pFsaResource ) );
  153. WsbAffirmPointer (m_pFsaResource);
  154. ULONG hsmLevel = 0;
  155. LONGLONG fileSize = 0;
  156. BOOL isRelative = TRUE; // assumed to be TRUE
  157. FILETIME accessTime;
  158. // Get data from the Fsa object and assign to controls
  159. WsbAffirmHr( m_pFsaResource->GetHsmLevel( &hsmLevel ) );
  160. m_hsmLevel = hsmLevel / FSA_HSMLEVEL_1;
  161. WsbAffirmHr( m_pFsaResource->GetManageableItemLogicalSize( &fileSize ) );
  162. m_fileSize = (DWORD)(fileSize / 1024); // Show KBytes
  163. WsbAffirmHr( m_pFsaResource->GetManageableItemAccessTime( &isRelative, &accessTime ) );
  164. WsbAssert( isRelative, E_FAIL ); // We only do relative time
  165. // Convert FILETIME to days
  166. LONGLONG temp = WSB_FT_TICKS_PER_DAY;
  167. m_accessTime = (UINT) (WsbFTtoLL (accessTime) / temp);
  168. if( m_accessTime > 999 ) {
  169. m_accessTime = 0;
  170. }
  171. LONGLONG total = 0;
  172. LONGLONG free = 0;
  173. LONGLONG premigrated = 0;
  174. LONGLONG truncated = 0;
  175. // Get actual free space and show in % and 4-digit formats
  176. WsbAffirmHr( m_pFsaResource->GetSizes( &total, &free, &premigrated, &truncated ) );
  177. m_capacity = total;
  178. freePct = (int) ((free * 100) / total);
  179. CString sFormat;
  180. sFormat.Format( L"%d", freePct );
  181. SetDlgItemText( IDC_STATIC_ACTUAL_FREE_PCT, sFormat );
  182. WsbAffirmHr( RsGuiFormatLongLong4Char( free, sFormat ) );
  183. SetDlgItemText( IDC_STATIC_FREE_ACTUAL_4DIGIT, sFormat );
  184. // Show the desired in 4-digit - based on the %
  185. SetDesiredFreePctControl( m_hsmLevel );
  186. // Update the controls
  187. UpdateData( FALSE );
  188. } else {
  189. // MULTI-SELECT
  190. // Hide the byte display of desired free space
  191. m_staticDesired4Digit.ShowWindow( SW_HIDE );
  192. m_staticActual4Digit.ShowWindow( SW_HIDE );
  193. InitDialogMultiSelect( );
  194. }
  195. } WsbCatch (hr);
  196. return( TRUE );
  197. }
  198. BOOL CPrMrLvl::OnApply()
  199. {
  200. HRESULT hr = S_OK;
  201. try {
  202. if( !m_bMultiSelect ) {
  203. LONGLONG fileSize = 0;
  204. // Single Select
  205. UpdateData( TRUE );
  206. WsbAffirmHr( m_pFsaResource->SetHsmLevel( m_hsmLevel * FSA_HSMLEVEL_1 ) );
  207. fileSize = ((LONGLONG)m_fileSize) * 1024;
  208. WsbAffirmHr( m_pFsaResource->SetManageableItemLogicalSize( fileSize ) );
  209. // Convert days to FILETIME
  210. FILETIME accessTime;
  211. LONGLONG temp = WSB_FT_TICKS_PER_DAY;
  212. accessTime = WsbLLtoFT( ( (LONGLONG) m_accessTime ) * temp );
  213. WsbAffirmHr( m_pFsaResource->SetManageableItemAccessTime( TRUE, accessTime ) );
  214. } else {
  215. // Multi-Select
  216. WsbAffirmHr( OnApplyMultiSelect( ) );
  217. }
  218. //
  219. // Tell to save
  220. //
  221. CComPtr<IFsaServer> pFsaServer;
  222. WsbAffirmHr( m_pParent->GetFsaServer( &pFsaServer ) );
  223. WsbAffirmHr( RsServerSaveAll( pFsaServer ) );
  224. //
  225. // Now notify all the nodes
  226. //
  227. m_pParent->OnPropertyChange( m_hConsoleHandle );
  228. } WsbCatch( hr );
  229. return CSakVolPropPage::OnApply();
  230. }
  231. ///////////////////////////////////////////////////////////////////////////////
  232. //
  233. // OnChangeEditLevel
  234. //
  235. // Change the display of actual bytes according to the percent setting
  236. //
  237. void CPrMrLvl::OnChangeEditLevel()
  238. {
  239. BOOL fTrans;
  240. int freePct;
  241. freePct = GetDlgItemInt( IDC_EDIT_LEVEL, &fTrans );
  242. if( fTrans ) {
  243. SetDesiredFreePctControl( freePct );
  244. }
  245. if( !m_fChangingByCode ) {
  246. SetModified( TRUE );
  247. }
  248. }
  249. void CPrMrLvl::OnChangeEditSize()
  250. {
  251. if( !m_fChangingByCode ) {
  252. SetModified( TRUE );
  253. }
  254. }
  255. void CPrMrLvl::OnChangeEditTime()
  256. {
  257. if( !m_fChangingByCode ) {
  258. SetModified( TRUE );
  259. }
  260. }
  261. //////////////////////////////////////////////////////////////////////////
  262. //
  263. // SetDesiredFreePctControl
  264. //
  265. // Converts the supplied desired percent to bytes (using m_capacity) and
  266. // displays in the appropriate edit box
  267. //
  268. //
  269. void CPrMrLvl::SetDesiredFreePctControl (int desiredPct)
  270. {
  271. HRESULT hr = 0;
  272. CString sFormat;
  273. LONGLONG desired = (m_capacity * desiredPct) / 100;
  274. try {
  275. WsbAffirmHr (RsGuiFormatLongLong4Char (desired, sFormat));
  276. SetDlgItemText (IDC_STATIC_FREE_DESIRED_4DIGIT, sFormat);
  277. } WsbCatch (hr)
  278. }
  279. //////////////////////////////////////////////////////////////////////////
  280. //
  281. //
  282. HRESULT CPrMrLvl::InitDialogMultiSelect()
  283. {
  284. LONGLONG total;
  285. LONGLONG free;
  286. LONGLONG premigrated;
  287. LONGLONG truncated;
  288. BOOL fLevelSame = TRUE;
  289. BOOL fSizeSame = TRUE;
  290. BOOL fDaysSame = TRUE;
  291. BOOL fFirst = TRUE;
  292. CString szLevel;
  293. CString szSize;
  294. CString szDays;
  295. ULONG hsmLevel = 0;
  296. LONGLONG fileSize = 0;
  297. BOOL isRelative = TRUE; // assumed to be TRUE
  298. FILETIME accessTime;
  299. int hsmLevelPct;
  300. ULONG fileSizeKb;
  301. int accessTimeDays;
  302. int hsmLevelPctSave = 0;
  303. ULONG fileSizeKbSave = 0;
  304. int accessTimeDaysSave = 0;
  305. int freePct;
  306. HRESULT hr = S_OK;
  307. try {
  308. // Set this flag to true because SetEditContents will cause the edit boxes to
  309. // fire a change event, and we don't want that to cause the Finish button to
  310. // be enabled.
  311. m_fChangingByCode = TRUE;
  312. // For each managed resource
  313. int bookMark = 0;
  314. CComPtr<IFsaResource> pFsaResource;
  315. LONGLONG totalCapacity = 0;
  316. LONGLONG totalFree = 0;
  317. while( m_pVolParent->GetNextFsaResource( &bookMark, &pFsaResource ) == S_OK ) {
  318. // Total up volume statistics
  319. WsbAffirmHr (pFsaResource->GetSizes(&total, &free, &premigrated, &truncated));
  320. totalCapacity += total;
  321. totalFree += free;
  322. // Get the levels in the resource
  323. WsbAffirmHr( pFsaResource->GetHsmLevel( &hsmLevel) );
  324. hsmLevelPct = (hsmLevel / FSA_HSMLEVEL_1);
  325. if( ! fFirst ) {
  326. if( hsmLevelPct != hsmLevelPctSave ) {
  327. fLevelSame = FALSE;
  328. }
  329. }
  330. hsmLevelPctSave = hsmLevelPct;
  331. WsbAffirmHr( pFsaResource->GetManageableItemLogicalSize( &fileSize ) );
  332. fileSizeKb = (LONG) ( fileSize / 1024 );
  333. if( !fFirst ) {
  334. if( fileSizeKb != fileSizeKbSave ) {
  335. fSizeSame = FALSE;
  336. }
  337. }
  338. fileSizeKbSave = fileSizeKb;
  339. WsbAffirmHr( pFsaResource->GetManageableItemAccessTime( &isRelative, &accessTime ) );
  340. accessTimeDays = (UINT) ( WsbFTtoLL( accessTime ) / WSB_FT_TICKS_PER_DAY );
  341. if( ! fFirst ) {
  342. if( accessTimeDays != accessTimeDaysSave ) {
  343. fDaysSame = FALSE;
  344. }
  345. }
  346. accessTimeDaysSave = accessTimeDays;
  347. fFirst = FALSE;
  348. pFsaResource.Release( );
  349. } // While
  350. // If all same, put the value in
  351. if( fLevelSame ) {
  352. szLevel.Format( L"%d", hsmLevelPctSave );
  353. } else {
  354. szLevel = L"";
  355. }
  356. if( fSizeSame ) {
  357. szSize.Format( L"%d", fileSizeKbSave );
  358. } else {
  359. szSize = L"";
  360. }
  361. if( fDaysSame ) {
  362. szDays.Format( L"%d", accessTimeDaysSave );
  363. } else {
  364. szDays = L"";
  365. }
  366. // Show volume statistics
  367. if( totalCapacity == 0 ) {
  368. freePct = 0;
  369. } else {
  370. freePct = (int) ( ( totalFree * 100 ) / totalCapacity );
  371. }
  372. CString sFormat;
  373. sFormat.Format( L"%d", freePct );
  374. SetDlgItemText( IDC_STATIC_ACTUAL_FREE_PCT, sFormat );
  375. m_editLevel.SetWindowText( szLevel );
  376. m_editSize.SetWindowText( szSize );
  377. m_editTime.SetWindowText( szDays );
  378. m_fChangingByCode = FALSE;
  379. } WsbCatch( hr );
  380. return( hr );
  381. }
  382. HRESULT CPrMrLvl::OnApplyMultiSelect()
  383. {
  384. HRESULT hr = S_OK;
  385. CComPtr <IFsaResource> pFsaResource;
  386. try {
  387. // For each managed resource
  388. int bookMark = 0;
  389. CComPtr<IFsaResource> pFsaResource;
  390. while( m_pVolParent->GetNextFsaResource( &bookMark, &pFsaResource ) == S_OK ) {
  391. // Set the levels in the resource - only if the edit box was not blank
  392. CString szLevel;
  393. CString szSize;
  394. CString szDays;
  395. m_editLevel.GetWindowText( szLevel );
  396. m_editSize.GetWindowText( szSize );
  397. m_editTime.GetWindowText( szDays );
  398. if( szLevel != L"" ) {
  399. WsbAffirmHr( pFsaResource->SetHsmLevel( m_spinLevel.GetPos( ) * FSA_HSMLEVEL_1 ) );
  400. }
  401. if( szSize != L"" ) {
  402. WsbAffirmHr( pFsaResource->SetManageableItemLogicalSize( (LONGLONG) m_spinSize.GetPos( ) * 1024 ) );
  403. }
  404. if( szDays != L"" ) {
  405. // Convert days to FILETIME
  406. FILETIME accessTime;
  407. accessTime = WsbLLtoFT( ( (LONGLONG) m_spinTime.GetPos( ) ) * WSB_FT_TICKS_PER_DAY);
  408. WsbAffirmHr (pFsaResource->SetManageableItemAccessTime (TRUE, accessTime));
  409. }
  410. pFsaResource.Release( );
  411. }
  412. } WsbCatch (hr);
  413. return( hr );
  414. }