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.

1144 lines
36 KiB

  1. /*
  2. **------------------------------------------------------------------------------
  3. ** Module: Disk Cleanup Applet
  4. ** File: dmgrdlg.cpp
  5. **
  6. ** Purpose: Implements the Disk Space Cleanup Drive dialog
  7. ** Notes:
  8. ** Mod Log: Created by Jason Cobb (2/97)
  9. **
  10. ** Copyright (c)1997 Microsoft Corporation, All Rights Reserved
  11. **------------------------------------------------------------------------------
  12. */
  13. /*
  14. **------------------------------------------------------------------------------
  15. ** Project include files
  16. **------------------------------------------------------------------------------
  17. */
  18. #include "common.h"
  19. #include "dmgrdlg.h"
  20. #include "dmgrinfo.h"
  21. #include "diskutil.h"
  22. #include "msprintf.h"
  23. #include <help.h>
  24. // To work around a "feature" of listview we need the ability to temporarily ignore certain LVN_ITEMCHANGED messages:
  25. BOOL g_bIgnoreCheckStateChanges = TRUE;
  26. /*
  27. **------------------------------------------------------------------------------
  28. ** Local defines
  29. **------------------------------------------------------------------------------
  30. */
  31. #define crSliceUsed RGB( 0, 0, 255 )
  32. #define crSliceFree RGB( 255, 0, 255)
  33. #define crSliceCleanup RGB( 255, 255, 0 )
  34. const DWORD aHelpIDs[]=
  35. {
  36. IDC_INTRO_TEXT, IDH_CLEANMGR_INTRO_TEXT,
  37. IDC_FILES_TO_REMOVE_TEXT, IDH_CLEANMGR_CLIENT_LIST,
  38. IDC_CLIENT_LIST, IDH_CLEANMGR_CLIENT_LIST,
  39. IDC_TOTAL_SPACE_DESCRIPTION, IDH_CLEANMGR_TOTAL_SPACE,
  40. IDC_TOTAL_SPACE_TEXT, IDH_CLEANMGR_TOTAL_SPACE,
  41. IDC_DESCRIPTION_GROUP, IDH_CLEANMGR_DESCRIPTION_GROUP,
  42. IDC_DESCRIPTION_TEXT, IDH_CLEANMGR_DESCRIPTION_GROUP,
  43. IDC_DETAILS_BUTTON, IDH_CLEANMGR_DETAILS_BUTTON,
  44. IDC_WINDOWS_SETUP_ICON, IDH_CLEANMGR_SETUP_GROUP,
  45. IDC_WINDOWS_SETUP_GROUP, IDH_CLEANMGR_SETUP_GROUP,
  46. IDC_WINDOWS_SETUP_TEXT, IDH_CLEANMGR_SETUP_GROUP,
  47. IDC_WINDOWS_SETUP_BUTTON, IDH_CLEANMGR_SETUP_BUTTON,
  48. IDC_INSTALLED_PROGRAMS_ICON, IDH_CLEANMGR_PROGRAMS_GROUP,
  49. IDC_INSTALLED_PROGRAMS_GROUP, IDH_CLEANMGR_PROGRAMS_GROUP,
  50. IDC_INSTALLED_PROGRAMS_TEXT, IDH_CLEANMGR_PROGRAMS_GROUP,
  51. IDC_INSTALLED_PROGRAMS_BUTTON, IDH_CLEANMGR_PROGRAMS_BUTTON,
  52. IDC_SYSTEM_RESTORE_ICON, IDH_CLEANMGR_SYSTEM_RESTORE_GROUP,
  53. IDC_SYSTEM_RESTORE_GROUP, IDH_CLEANMGR_SYSTEM_RESTORE_GROUP,
  54. IDC_SYSTEM_RESTORE_TEXT, IDH_CLEANMGR_SYSTEM_RESTORE_GROUP,
  55. IDC_SYSTEM_RESTORE_BUTTON, IDH_CLEANMGR_SYSTEM_RESTORE_BUTTON,
  56. IDC_AUTO_LAUNCH, IDH_CLEANMGR_AUTO_LAUNCH,
  57. IDC_DRIVE_ICON_LOCATION, ((DWORD)-1),
  58. IDC_SETTINGS_DRIVE_TEXT, ((DWORD)-1),
  59. 0, 0
  60. };
  61. /*
  62. **------------------------------------------------------------------------------
  63. ** Local function prototypes
  64. **------------------------------------------------------------------------------
  65. */
  66. BOOL CleanupMgrDlgInit (HWND hDlg, LPARAM lParam);
  67. void CleanupMgrDlgCleanup (HWND hDlg);
  68. BOOL CleanupMgrDlgCommand (HWND hDlg, WPARAM wParam, LPARAM lParam);
  69. BOOL CleanupMgrDlgNotify (HWND hDlg, UINT uiMessage, WPARAM wParam, LPARAM lParam);
  70. BOOL CleanupMgrDlgInitText (HWND hDlg);
  71. BOOL CleanupMgrDlgInitList (HWND hDlg);
  72. VOID UpdateTotalSpaceToBeFreed(HWND hDlg);
  73. INT_PTR CALLBACK MoreOptionsDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
  74. INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam);
  75. LPARAM ListView_GetItemData(HWND hwndList, int i)
  76. {
  77. LVITEM lvi = {0};
  78. lvi.iItem = i;
  79. lvi.mask = LVIF_PARAM;
  80. if ( ListView_GetItem(hwndList, &lvi) )
  81. {
  82. return lvi.lParam;
  83. }
  84. return NULL;
  85. }
  86. /*
  87. **------------------------------------------------------------------------------
  88. ** DisplayCleanMgrProperties
  89. **
  90. ** Purpose: Creates the Cleanup Manager property sheet
  91. ** Parameters:
  92. ** hDlg - Handle to dialog window
  93. ** lParam - DWORD to pass onto the property pages
  94. ** Return: 1 if user pressed "OK"
  95. ** 0 if user pressed "Cancel"
  96. ** Notes;
  97. ** Mod Log: Created by Jason Cobb (7/97)
  98. **------------------------------------------------------------------------------
  99. */
  100. DWORD
  101. DisplayCleanMgrProperties(
  102. HWND hWnd,
  103. LPARAM lParam
  104. )
  105. {
  106. DWORD dwRet;
  107. TCHAR *psz;
  108. PROPSHEETPAGE psp;
  109. PROPSHEETHEADER psh;
  110. HPROPSHEETPAGE hpsp[2];
  111. CleanupMgrInfo * pcmi = (CleanupMgrInfo *)lParam;
  112. if (pcmi == NULL)
  113. {
  114. //
  115. //Error - passed in invalid CleanupMgrInfo info
  116. //
  117. return 0;
  118. }
  119. memset(&psh, 0, sizeof(PROPSHEETHEADER));
  120. psp.dwSize = sizeof(PROPSHEETPAGE);
  121. psp.dwFlags = PSP_DEFAULT | PSP_USETITLE;
  122. psp.hInstance = g_hInstance;
  123. psp.lParam = lParam;
  124. psp.pszTitle = MAKEINTRESOURCE(IDS_DISKCLEANUP);
  125. psp.pszTemplate = MAKEINTRESOURCE(IDD_DISK_CLEANER);
  126. psp.pfnDlgProc = DiskCleanupManagerProc;
  127. hpsp[0] = CreatePropertySheetPage(&psp);
  128. if (!(pcmi->dwUIFlags & FLAG_SAGESET))
  129. {
  130. // Only display the second tab if the user is an admin
  131. if (IsUserAnAdmin())
  132. {
  133. psp.pszTitle = MAKEINTRESOURCE(IDS_MOREOPTIONS);
  134. psp.pszTemplate = MAKEINTRESOURCE(IDD_MORE_OPTIONS);
  135. psp.pfnDlgProc = MoreOptionsDlgProc;
  136. hpsp[1] = CreatePropertySheetPage(&psp);
  137. // commented out until after BEta 2
  138. // psp.pszTitle = MAKEINTRESOURCE(IDS_SETTINGS);
  139. // psp.pszTemplate = MAKEINTRESOURCE(IDD_SETTINGS);
  140. // psp.pfnDlgProc = SettingsDlgProc;
  141. // hpsp[2] = CreatePropertySheetPage(&psp);
  142. // psh.nPages = 3;
  143. psh.nPages = 2;
  144. }
  145. else
  146. {
  147. // User is not an admin so only display the first tab
  148. psh.nPages = 1;
  149. }
  150. //
  151. //Create the dialog title
  152. //
  153. psz = SHFormatMessage( MSG_APP_TITLE, pcmi->szVolName, pcmi->szRoot[0]);
  154. }
  155. else
  156. {
  157. psh.nPages = 1;
  158. //
  159. //Create the dialog title
  160. //
  161. psz = SHFormatMessage( MSG_APP_SETTINGS_TITLE );
  162. }
  163. psh.dwSize = sizeof(PROPSHEETHEADER);
  164. psh.dwFlags = PSH_NOAPPLYNOW | PSH_USEICONID;
  165. psh.hInstance = g_hInstance;
  166. psh.hwndParent = hWnd;
  167. psh.pszIcon = MAKEINTRESOURCE(ICON_CLEANMGR);
  168. psh.phpage = hpsp;
  169. psh.pszCaption = psz;
  170. dwRet = (DWORD)PropertySheet(&psh);
  171. LocalFree(psz);
  172. return dwRet;
  173. }
  174. /*
  175. **------------------------------------------------------------------------------
  176. ** DiskCleanupManagerProc
  177. **
  178. ** Purpose: Dialog routine for Disk Cleanup Manager Property Sheet
  179. ** Parameters:
  180. ** hDlg - Handle to dialog window
  181. ** uMessage - behavior type
  182. ** wParam - depends on message
  183. ** lParam - depends on message
  184. ** Return: TRUE on sucess
  185. ** FALSE on failure
  186. ** Notes;
  187. ** Mod Log: Created by Jason Cobb (2/97)
  188. **------------------------------------------------------------------------------
  189. */
  190. INT_PTR CALLBACK
  191. DiskCleanupManagerProc(
  192. HWND hDlg,
  193. UINT uiMessage,
  194. WPARAM wParam,
  195. LPARAM lParam
  196. )
  197. {
  198. switch (uiMessage)
  199. {
  200. case WM_INITDIALOG:
  201. return CleanupMgrDlgInit(hDlg, lParam);
  202. case WM_DESTROY:
  203. CleanupMgrDlgCleanup(hDlg);
  204. break;
  205. case WM_COMMAND:
  206. return CleanupMgrDlgCommand(hDlg, wParam, lParam);
  207. case WM_NOTIFY:
  208. return CleanupMgrDlgNotify(hDlg, uiMessage, wParam, lParam);
  209. case WM_HELP:
  210. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, NULL,
  211. HELP_WM_HELP, (DWORD_PTR)(LPTSTR) aHelpIDs);
  212. return TRUE;
  213. case WM_CONTEXTMENU:
  214. WinHelp((HWND) wParam, NULL, HELP_CONTEXTMENU,
  215. (DWORD_PTR)(LPVOID) aHelpIDs);
  216. return TRUE;
  217. case WM_SYSCOLORCHANGE:
  218. SendMessage( GetDlgItem(hDlg, IDC_CLIENT_LIST), uiMessage, wParam, lParam);
  219. break;
  220. }
  221. //Non-handled message
  222. return FALSE;
  223. }
  224. /*
  225. **------------------------------------------------------------------------------
  226. ** CleanupMgrDlgInit
  227. **
  228. ** Purpose: Handles dialog initialization
  229. ** Parameters:
  230. ** hDlg - Handle to dialog window
  231. ** lParam - Property Sheet pointer
  232. ** Return: TRUE on sucess
  233. ** FALSE on failure
  234. ** Notes;
  235. ** Mod Log: Created by Jason Cobb (2/97)
  236. **------------------------------------------------------------------------------
  237. */
  238. BOOL
  239. CleanupMgrDlgInit(
  240. HWND hDlg,
  241. LPARAM lParam
  242. )
  243. {
  244. LPPROPSHEETPAGE lppsp;
  245. g_hDlg = hDlg;
  246. //
  247. //Make sure we have an invalid pointer to start out with
  248. //
  249. SetWindowLongPtr (hDlg, DWLP_USER, 0L);
  250. //
  251. //Get the CleanupMgrInfo
  252. //
  253. lppsp = (LPPROPSHEETPAGE)lParam;
  254. CleanupMgrInfo * pcmi = (CleanupMgrInfo *)lppsp->lParam;
  255. if (pcmi == NULL)
  256. {
  257. //Error - passed in invalid CleanupMgrInfo info
  258. return FALSE;
  259. }
  260. // now as we are becoming visible, we can dismiss the progress dialog
  261. if ( pcmi->hAbortScanWnd )
  262. {
  263. pcmi->bAbortScan = TRUE;
  264. //
  265. //Wait for scan thread to finish
  266. //
  267. WaitForSingleObject(pcmi->hAbortScanThread, INFINITE);
  268. pcmi->bAbortScan = FALSE;
  269. }
  270. //
  271. //Save pointer to CleanupMgrInfo object
  272. //
  273. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)pcmi);
  274. //
  275. //Initialize all text
  276. //
  277. if (!CleanupMgrDlgInitText(hDlg))
  278. goto HAS_ERROR;
  279. //
  280. //Initialize the icon
  281. //
  282. SendDlgItemMessage(hDlg,IDC_DRIVE_ICON_LOCATION,STM_SETICON,(WPARAM)pcmi->hDriveIcon,0);
  283. //
  284. //If we are in SAGE settings mode then hide the total amount of space text
  285. //
  286. if (pcmi->dwUIFlags & FLAG_SAGESET)
  287. {
  288. ShowWindow(GetDlgItem(hDlg, IDC_TOTAL_SPACE_DESCRIPTION), SW_HIDE);
  289. ShowWindow(GetDlgItem(hDlg, IDC_TOTAL_SPACE_TEXT), SW_HIDE);
  290. }
  291. //
  292. //Initialize the list box (all of the cleanup clients)
  293. //
  294. if (!CleanupMgrDlgInitList(hDlg))
  295. goto HAS_ERROR;
  296. return TRUE;
  297. HAS_ERROR:
  298. //
  299. //Delete any memory structures still hanging around
  300. //
  301. CleanupMgrDlgCleanup (hDlg);
  302. return FALSE;
  303. }
  304. /*
  305. **------------------------------------------------------------------------------
  306. ** CleanupMgrDlgCleanup
  307. **
  308. ** Purpose:
  309. ** Parameters:
  310. ** Notes;
  311. ** Mod Log: Created by Jason Cobb (2/97)
  312. **------------------------------------------------------------------------------
  313. */
  314. void
  315. CleanupMgrDlgCleanup(
  316. HWND hDlg
  317. )
  318. {
  319. //
  320. //Make sure we have a valid parameter
  321. //
  322. if (!hDlg)
  323. return;
  324. //
  325. //Hide the window right away since we might block waiting for a
  326. //COM client to finish.
  327. //
  328. ShowWindow(hDlg, SW_HIDE);
  329. g_hDlg = NULL;
  330. }
  331. /*
  332. **------------------------------------------------------------------------------
  333. ** CleanupMgrWarningPrompt
  334. **
  335. ** Purpose: Asks the user if they are sure they want to delete the files
  336. ** Parameters:
  337. ** hDlg - Handle to dialog window
  338. ** Return: TRUE if user says YES
  339. ** FALSE if user says NO
  340. ** Notes;
  341. ** Mod Log: Created by Jason Cobb (6/97)
  342. **------------------------------------------------------------------------------
  343. */
  344. BOOL
  345. CleanupMgrWarningPrompt(
  346. HWND hDlg
  347. )
  348. {
  349. TCHAR szWarning[256];
  350. TCHAR *pszWarningTitle;
  351. int i;
  352. BOOL bItemSelected = FALSE;
  353. //
  354. //First verify that at least one item is selected. If no items are selected then
  355. //nothing will be deleted so we don't need to bother prompting the user.
  356. //
  357. CleanupMgrInfo * pcmi = GetCleanupMgrInfoPointer(hDlg);
  358. if (pcmi == NULL)
  359. return TRUE;
  360. for (i=0; i<pcmi->iNumVolumeCacheClients; i++)
  361. {
  362. if (pcmi->pClientInfo[i].bSelected == TRUE)
  363. {
  364. bItemSelected = TRUE;
  365. break;
  366. }
  367. }
  368. if (bItemSelected)
  369. {
  370. LoadString(g_hInstance, IDS_DELETEWARNING, szWarning, ARRAYSIZE(szWarning));
  371. pszWarningTitle = SHFormatMessage( MSG_APP_TITLE, pcmi->szVolName, pcmi->szRoot[0]);
  372. if (MessageBox(hDlg, szWarning, pszWarningTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
  373. {
  374. LocalFree(pszWarningTitle);
  375. return TRUE;
  376. }
  377. else
  378. {
  379. LocalFree(pszWarningTitle);
  380. return FALSE;
  381. }
  382. }
  383. //
  384. //No items are selected so just return TRUE since nothing will be deleted.
  385. //
  386. return TRUE;
  387. }
  388. /*
  389. **------------------------------------------------------------------------------
  390. ** CleanupMgrDlgCommand
  391. **
  392. ** Purpose: Handles command messages
  393. ** Parameters:
  394. ** hDlg - Handle to dialog window
  395. ** wParam - depends on command
  396. ** lParam - depends on command
  397. ** Return: TRUE on sucess
  398. ** FALSE on failure
  399. ** Notes;
  400. ** Mod Log: Created by Jason Cobb (2/97)
  401. **------------------------------------------------------------------------------
  402. */
  403. BOOL CleanupMgrDlgCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
  404. {
  405. WORD wID = LOWORD(wParam);
  406. if ( IDC_DETAILS_BUTTON == wID )
  407. {
  408. HWND hWndList = GetDlgItem(hDlg, IDC_CLIENT_LIST);
  409. int wIndex;
  410. wIndex = ListView_GetNextItem(hWndList, -1, LVNI_SELECTED);
  411. if (-1 != wIndex)
  412. {
  413. PCLIENTINFO pClientInfo = (PCLIENTINFO)ListView_GetItemData(hWndList,wIndex);
  414. if ( pClientInfo )
  415. {
  416. pClientInfo->pVolumeCache->ShowProperties(hDlg);
  417. }
  418. }
  419. }
  420. return 0;
  421. }
  422. /*
  423. **------------------------------------------------------------------------------
  424. ** CleanupMgrDlgNotify
  425. **
  426. ** Purpose: Handles notify messages
  427. ** Parameters:
  428. ** hDlg - Handle to dialog window
  429. ** wParam - depends on command
  430. ** lParam - depends on command
  431. ** Return: TRUE on sucess
  432. ** FALSE on failure
  433. ** Notes;
  434. ** Mod Log: Created by Jason Cobb (7/97)
  435. **------------------------------------------------------------------------------
  436. */
  437. BOOL
  438. CleanupMgrDlgNotify(
  439. HWND hDlg,
  440. UINT uiMessage,
  441. WPARAM wParam,
  442. LPARAM lParam
  443. )
  444. {
  445. CleanupMgrInfo *pcmi;
  446. LPNMHDR pnmhdr = (LPNMHDR)lParam;
  447. if (IDC_CLIENT_LIST == pnmhdr->idFrom)
  448. {
  449. // a list view notification
  450. #define pnmlv ((LPNMLISTVIEW)pnmhdr)
  451. switch (pnmhdr->code)
  452. {
  453. case LVN_ITEMCHANGED:
  454. if ( pnmlv->uChanged & LVIF_STATE )
  455. {
  456. LVITEM lvi;
  457. lvi.iItem = pnmlv->iItem;
  458. lvi.iSubItem = pnmlv->iSubItem;
  459. lvi.mask = LVIF_PARAM;
  460. ListView_GetItem( pnmhdr->hwndFrom, &lvi );
  461. PCLIENTINFO pClientInfo = (PCLIENTINFO)lvi.lParam;
  462. // check if an item was selected
  463. if ( pnmlv->uNewState & LVIS_SELECTED )
  464. {
  465. if (pClientInfo->wcsDescription)
  466. {
  467. TCHAR szDescription[DESCRIPTION_LENGTH];
  468. SHUnicodeToTChar(pClientInfo->wcsDescription, szDescription, ARRAYSIZE( szDescription ));
  469. SetDlgItemText(hDlg, IDC_DESCRIPTION_TEXT, szDescription);
  470. }
  471. else
  472. {
  473. SetDlgItemText(hDlg, IDC_DESCRIPTION_TEXT, TEXT(""));
  474. }
  475. //
  476. //Show or Hide the Settings button
  477. //
  478. if (pClientInfo->dwInitializeFlags & EVCF_HASSETTINGS)
  479. {
  480. TCHAR szButton[BUTTONTEXT_LENGTH];
  481. SHUnicodeToTChar(pClientInfo->wcsAdvancedButtonText, szButton, ARRAYSIZE( szButton ));
  482. SetDlgItemText(hDlg, IDC_DETAILS_BUTTON, szButton);
  483. ShowWindow(GetDlgItem(hDlg, IDC_DETAILS_BUTTON), SW_SHOW);
  484. }
  485. else
  486. {
  487. ShowWindow(GetDlgItem(hDlg, IDC_DETAILS_BUTTON), SW_HIDE);
  488. }
  489. }
  490. // Check if the state image changed. This results from checking or unchecking
  491. // one of the list view checkboxes.
  492. if ((pnmlv->uNewState ^ pnmlv->uOldState) & LVIS_STATEIMAGEMASK)
  493. {
  494. if ( !g_bIgnoreCheckStateChanges )
  495. {
  496. pClientInfo->bSelected = ListView_GetCheckState( pnmhdr->hwndFrom, pnmlv->iItem );
  497. UpdateTotalSpaceToBeFreed(hDlg);
  498. }
  499. }
  500. }
  501. break;
  502. }
  503. }
  504. else
  505. {
  506. // must be a property sheet notification
  507. switch(pnmhdr->code)
  508. {
  509. case PSN_RESET:
  510. pcmi = GetCleanupMgrInfoPointer(hDlg);
  511. pcmi->bPurgeFiles = FALSE;
  512. break;
  513. case PSN_APPLY:
  514. pcmi = GetCleanupMgrInfoPointer(hDlg);
  515. if (!(pcmi->dwUIFlags & FLAG_SAGESET))
  516. {
  517. // We're not in SAGESET mode
  518. // Ask the user if they would like to proceed if there are items selected
  519. if (!CleanupMgrWarningPrompt(hDlg))
  520. {
  521. // The user clicked no so drop them back to the main window
  522. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  523. pcmi->bPurgeFiles = FALSE;
  524. return TRUE;
  525. }
  526. // User clicked yes so continue as normal
  527. pcmi->bPurgeFiles = TRUE;
  528. }
  529. else
  530. {
  531. pcmi->bPurgeFiles = TRUE;
  532. }
  533. break;
  534. }
  535. }
  536. return FALSE;
  537. }
  538. /*
  539. **------------------------------------------------------------------------------
  540. ** CleanupMgrDlgInitText
  541. **
  542. ** Purpose:
  543. ** Parameters:
  544. ** hDlg - Handle to dialog window
  545. ** Return: TRUE on sucess
  546. ** FALSE on failure
  547. ** Notes;
  548. ** Mod Log: Created by Jason Cobb (2/97)
  549. **------------------------------------------------------------------------------
  550. */
  551. BOOL
  552. CleanupMgrDlgInitText(
  553. HWND hDlg
  554. )
  555. {
  556. if (hDlg == NULL)
  557. return FALSE;
  558. //
  559. // Step 1. Get pointers to Info structures
  560. //
  561. CleanupMgrInfo * pcmi = GetCleanupMgrInfoPointer(hDlg);
  562. if (pcmi == NULL)
  563. return FALSE;
  564. if (pcmi->dre == Drive_INV)
  565. return FALSE;
  566. //
  567. // Step 2. Extract useful info
  568. //
  569. //
  570. //get vol name
  571. //
  572. TCHAR * pszVolName = pcmi->szVolName;
  573. if (pszVolName == NULL)
  574. pszVolName = TEXT("");
  575. //
  576. //get drive letter
  577. //
  578. TCHAR chDrive = pcmi->dre + 'A';
  579. //
  580. // Step 3. Initialize text
  581. //
  582. //
  583. //Set header
  584. //
  585. if (pcmi->dwUIFlags & FLAG_SAGESET)
  586. {
  587. TCHAR * psz;
  588. psz = SHFormatMessage( MSG_INTRO_SETTINGS_TEXT );
  589. SetDlgItemText (hDlg, IDC_INTRO_TEXT, psz);
  590. LocalFree(psz);
  591. }
  592. else
  593. {
  594. TCHAR * psz;
  595. TCHAR * pszDrive;
  596. TCHAR szBuffer[50];
  597. pszDrive = SHFormatMessage( MSG_VOL_NAME_DRIVE_LETTER, pszVolName, chDrive);
  598. StrFormatKBSize(pcmi->cbEstCleanupSpace.QuadPart, szBuffer, ARRAYSIZE( szBuffer ));
  599. psz = SHFormatMessage( MSG_INTRO_TEXT, pszDrive, szBuffer);
  600. SetDlgItemText (hDlg, IDC_INTRO_TEXT, psz);
  601. LocalFree(pszDrive);
  602. LocalFree(psz);
  603. }
  604. return TRUE;
  605. }
  606. /*
  607. **------------------------------------------------------------------------------
  608. ** UpdateTotalSpaceToBeFreed
  609. **
  610. ** Purpose:
  611. ** Parameters:
  612. ** hDlg - Handle to dialog window
  613. ** Return: NONE
  614. ** Notes;
  615. ** Mod Log: Created by Jason Cobb (7/97)
  616. **------------------------------------------------------------------------------
  617. */
  618. VOID UpdateTotalSpaceToBeFreed(HWND hDlg)
  619. {
  620. int i;
  621. ULARGE_INTEGER TotalSpaceToFree;
  622. TotalSpaceToFree.QuadPart = 0;
  623. if (hDlg == NULL)
  624. return;
  625. CleanupMgrInfo * pcmi = GetCleanupMgrInfoPointer(hDlg);
  626. if (pcmi == NULL)
  627. return;
  628. if (pcmi->dre == Drive_INV)
  629. return;
  630. //
  631. //Calculate the total space to be freed by adding up the dwUsedSpace value
  632. //on all of the selected clients
  633. //
  634. for (i=0; i<pcmi->iNumVolumeCacheClients; i++)
  635. {
  636. if (pcmi->pClientInfo[i].bSelected)
  637. {
  638. TotalSpaceToFree.QuadPart += pcmi->pClientInfo[i].dwUsedSpace.QuadPart;
  639. }
  640. }
  641. //
  642. //Display the total space to be freed
  643. //
  644. TCHAR szBuffer[10];
  645. StrFormatKBSize(TotalSpaceToFree.QuadPart, szBuffer, ARRAYSIZE( szBuffer ));
  646. SetDlgItemText(hDlg, IDC_TOTAL_SPACE_TEXT, szBuffer);
  647. }
  648. /*
  649. **------------------------------------------------------------------------------
  650. ** CleanupMgrDlgInitList
  651. **
  652. ** Purpose:
  653. ** Parameters:
  654. ** hDlg - Handle to dialog window
  655. ** Return: TRUE on sucess
  656. ** FALSE on failure
  657. ** Notes;
  658. ** Mod Log: Created by Jason Cobb (2/97)
  659. **------------------------------------------------------------------------------
  660. */
  661. #define NAME_COL_PERCENT 80
  662. #define SIZE_COL_PERCENT 20
  663. BOOL CleanupMgrDlgInitList(HWND hDlg)
  664. {
  665. int i;
  666. if (hDlg == NULL)
  667. return FALSE;
  668. CleanupMgrInfo * pcmi = GetCleanupMgrInfoPointer(hDlg);
  669. if (pcmi == NULL)
  670. return FALSE;
  671. if (pcmi->dre == Drive_INV)
  672. return FALSE;
  673. HWND hwndList = GetDlgItem(hDlg, IDC_CLIENT_LIST);
  674. RECT rc;
  675. GetClientRect(hwndList, &rc);
  676. int cxList = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  677. // I have no idea what all this TUNEUP and SAGESET stuff means, but the old code
  678. // only drew the sizes if the following condition was true. As such, I'm only
  679. // showing the size column if the same condition is true:
  680. BOOL bShowTwoCols = (!(pcmi->dwUIFlags & FLAG_TUNEUP) && !(pcmi->dwUIFlags & FLAG_SAGESET));
  681. LVCOLUMN lvc;
  682. lvc.mask = LVCF_SUBITEM | LVCF_WIDTH;
  683. lvc.iSubItem = 0;
  684. lvc.cx = bShowTwoCols ? MulDiv(cxList, NAME_COL_PERCENT, 100) : cxList;
  685. ListView_InsertColumn( hwndList, 0, &lvc );
  686. if ( bShowTwoCols )
  687. {
  688. lvc.mask = LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
  689. lvc.iSubItem = 1;
  690. lvc.cx = MulDiv(cxList, SIZE_COL_PERCENT, 100);
  691. lvc.fmt = LVCFMT_RIGHT;
  692. ListView_InsertColumn( hwndList, 1, &lvc );
  693. }
  694. HIMAGELIST himg = ImageList_Create(16, 16, ILC_COLOR|ILC_MASK, 4, 4);
  695. ListView_SetImageList(hwndList, himg, LVSIL_SMALL );
  696. ListView_SetExtendedListViewStyleEx(hwndList, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
  697. // When we add an item to the listview the listview code always initializes the item to the unchecked
  698. // state. It then fires a WM_NOTIFY telling us the state changed to "off" which causes us to nuke our
  699. // bSelected value. As such we need to ignore state image changes during the addition of list view
  700. // items so that we can preserve our bSelected state.
  701. g_bIgnoreCheckStateChanges = TRUE;
  702. for (i=0; i<pcmi->iNumVolumeCacheClients; i++)
  703. {
  704. if ((pcmi->pClientInfo[i].pVolumeCache != NULL) &&
  705. (pcmi->pClientInfo[i].wcsDisplayName != NULL) &&
  706. (pcmi->pClientInfo[i].bShow == TRUE))
  707. {
  708. LPTSTR lpszDisplayName;
  709. ULONG cb;
  710. cb = WideCharToMultiByte(CP_ACP, 0, pcmi->pClientInfo[i].wcsDisplayName, -1, NULL, 0, NULL, NULL);
  711. if ((lpszDisplayName = (LPTSTR)LocalAlloc(LPTR, (cb + 1) * sizeof( TCHAR ))) != NULL)
  712. {
  713. #ifdef UNICODE
  714. StringCchCopy(lpszDisplayName, cb, pcmi->pClientInfo[i].wcsDisplayName);
  715. #else
  716. //
  717. //Convert UNICODE display name to ANSI and then add it to the list
  718. //
  719. WideCharToMultiByte(CP_ACP, 0, pcmi->pClientInfo[i].wcsDisplayName, -1, lpszDisplayName, cb, NULL, NULL);
  720. #endif
  721. //
  722. //Determine where in the list this item should go.
  723. //
  724. int iSortedPossition;
  725. int totalSoFar = ListView_GetItemCount(hwndList);
  726. for (iSortedPossition=0; iSortedPossition<totalSoFar; iSortedPossition++)
  727. {
  728. PCLIENTINFO pClientInfo = (PCLIENTINFO)ListView_GetItemData(hwndList, iSortedPossition);
  729. if (!pClientInfo || (pcmi->pClientInfo[i].dwPriority < pClientInfo->dwPriority))
  730. break;
  731. }
  732. //
  733. //Insert this item at index j in the list
  734. //
  735. LVITEM lvi = {0};
  736. lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
  737. lvi.iItem = iSortedPossition;
  738. lvi.iSubItem = 0;
  739. lvi.pszText = lpszDisplayName;
  740. lvi.lParam = (LPARAM)&(pcmi->pClientInfo[i]);
  741. lvi.iImage = ImageList_AddIcon(himg, pcmi->pClientInfo[i].hIcon);
  742. iSortedPossition = ListView_InsertItem(hwndList, &lvi);
  743. if (bShowTwoCols)
  744. {
  745. TCHAR szBuffer[10];
  746. StrFormatKBSize(pcmi->pClientInfo[i].dwUsedSpace.QuadPart, szBuffer, ARRAYSIZE( szBuffer ));
  747. ListView_SetItemText( hwndList, iSortedPossition, 1, szBuffer );
  748. }
  749. // Set the initial check state. We can't do this when we add the item because the
  750. // list view code specifically ingores your State Image Flags if you have the
  751. // LVS_EX_CHECKBOX style set, which we do.
  752. ListView_SetCheckState( hwndList, iSortedPossition, pcmi->pClientInfo[i].bSelected );
  753. LocalFree( lpszDisplayName );
  754. }
  755. }
  756. }
  757. g_bIgnoreCheckStateChanges = FALSE;
  758. UpdateTotalSpaceToBeFreed(hDlg);
  759. ListView_SetItemState(hwndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  760. return TRUE;
  761. }
  762. typedef DWORD (WINAPI * PFNSRFIFO)(LPCWSTR pwszDrive, DWORD dwTargetRp, INT nPercent,
  763. BOOL fIncludeCurrentRp);
  764. INT_PTR CALLBACK
  765. MoreOptionsDlgProc(
  766. HWND hDlg,
  767. UINT Message,
  768. WPARAM wParam,
  769. LPARAM lParam
  770. )
  771. {
  772. CleanupMgrInfo *pcmi;
  773. switch(Message)
  774. {
  775. case WM_INITDIALOG:
  776. {
  777. LPPROPSHEETPAGE lppsp;
  778. HMODULE hSRClient;
  779. lppsp = (LPPROPSHEETPAGE)lParam;
  780. pcmi = (CleanupMgrInfo *)lppsp->lParam;
  781. if (pcmi == NULL)
  782. {
  783. //Error - passed in invalid CleanupMgrInfo info
  784. return FALSE;
  785. }
  786. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pcmi);
  787. hSRClient = LoadLibraryEx(TEXT("srclient.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
  788. if (hSRClient)
  789. {
  790. FreeLibrary (hSRClient);
  791. }
  792. else
  793. {
  794. EnableWindow(GetDlgItem(hDlg, IDC_SYSTEM_RESTORE_GROUP), FALSE);
  795. ShowWindow(GetDlgItem(hDlg, IDC_SYSTEM_RESTORE_ICON), SW_HIDE);
  796. EnableWindow(GetDlgItem(hDlg, IDC_SYSTEM_RESTORE_TEXT), FALSE);
  797. EnableWindow(GetDlgItem(hDlg, IDC_SYSTEM_RESTORE_BUTTON), FALSE);
  798. }
  799. }
  800. break;
  801. case WM_COMMAND:
  802. switch(LOWORD(wParam))
  803. {
  804. case IDC_WINDOWS_SETUP_BUTTON:
  805. {
  806. TCHAR szSysDir[MAX_PATH];
  807. if ( GetSystemDirectory(szSysDir, ARRAYSIZE(szSysDir)) )
  808. {
  809. TCHAR szParam[MAX_PATH];
  810. StringCchPrintf(szParam, ARRAYSIZE(szParam), SZ_WINDOWS_SETUP, szSysDir);
  811. // Use full path
  812. if (PathAppend(szSysDir, SZ_SYSOCMGR))
  813. {
  814. ShellExecute(NULL, NULL, szSysDir, szParam, NULL, SW_SHOWNORMAL);
  815. }
  816. }
  817. }
  818. break;
  819. case IDC_INSTALLED_PROGRAMS_BUTTON:
  820. {
  821. TCHAR szPath[MAX_PATH];
  822. if (GetSystemDirectory(szPath, ARRAYSIZE(szPath)))
  823. {
  824. // Use full path
  825. if (PathAppend(szPath, SZ_RUNDLL32))
  826. {
  827. ShellExecute(NULL, NULL, szPath, SZ_INSTALLED_PROGRAMS, NULL, SW_SHOWNORMAL);
  828. }
  829. }
  830. }
  831. break;
  832. case IDC_SYSTEM_RESTORE_BUTTON:
  833. pcmi = (CleanupMgrInfo *) GetWindowLongPtr (hDlg, DWLP_USER);
  834. if (pcmi)
  835. {
  836. HMODULE hSRClient = NULL;
  837. PFNSRFIFO pfnSRFifo;
  838. TCHAR szCaption[100];
  839. TCHAR szMessage[200];
  840. INT iResult;
  841. LoadString(g_hInstance, IDS_DISKCLEANUP, szCaption, ARRAYSIZE(szCaption));
  842. LoadString(g_hInstance, IDS_SYSTEM_RESTORE_MESSAGE, szMessage, ARRAYSIZE(szMessage));
  843. iResult = MessageBox(hDlg, szMessage, szCaption, MB_YESNO | MB_ICONQUESTION);
  844. if (iResult == IDYES)
  845. {
  846. hSRClient = LoadLibrary(TEXT("srclient.dll"));
  847. if (hSRClient)
  848. {
  849. pfnSRFifo = (PFNSRFIFO) GetProcAddress (hSRClient, "SRFifo");
  850. if (pfnSRFifo)
  851. {
  852. pfnSRFifo ((LPCWSTR)pcmi->szRoot, NULL, 0, FALSE);
  853. }
  854. FreeLibrary (hSRClient);
  855. }
  856. }
  857. }
  858. break;
  859. }
  860. break;
  861. case WM_HELP:
  862. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, NULL,
  863. HELP_WM_HELP, (DWORD_PTR)(LPTSTR) aHelpIDs);
  864. return TRUE;
  865. case WM_CONTEXTMENU:
  866. WinHelp((HWND) wParam, NULL, HELP_CONTEXTMENU,
  867. (DWORD_PTR)(LPVOID) aHelpIDs);
  868. return TRUE;
  869. default:
  870. return FALSE;
  871. }
  872. return TRUE;
  873. }
  874. INT_PTR CALLBACK
  875. SettingsDlgProc(
  876. HWND hDlg,
  877. UINT Message,
  878. WPARAM wParam,
  879. LPARAM lParam
  880. )
  881. {
  882. LPPROPSHEETPAGE lppsp;
  883. CleanupMgrInfo *pcmi;
  884. DWORD dwType, cbBytes;
  885. DWORD dwLDSDisable;
  886. HKEY hk;
  887. switch(Message)
  888. {
  889. case WM_INITDIALOG:
  890. {
  891. TCHAR * psz;
  892. hardware hwType;
  893. lppsp = (LPPROPSHEETPAGE)lParam;
  894. pcmi = (CleanupMgrInfo *)lppsp->lParam;
  895. if (pcmi == NULL)
  896. {
  897. //Error - passed in invalid CleanupMgrInfo info
  898. return FALSE;
  899. }
  900. //
  901. //Save pointer to CleanupMgrInfo object
  902. //
  903. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)pcmi);
  904. TCHAR * pszVolName = pcmi->szVolName;
  905. if (pszVolName == NULL)
  906. pszVolName = TEXT("");
  907. TCHAR chDrive = pcmi->dre + TCHAR('A');
  908. psz = SHFormatMessage( MSG_INTRO_SETTINGS_TAB, pszVolName, chDrive );
  909. SetDlgItemText (hDlg, IDC_SETTINGS_DRIVE_TEXT, psz);
  910. LocalFree(psz);
  911. //
  912. //Initialize the icon
  913. //
  914. SendDlgItemMessage(hDlg,IDC_DRIVE_ICON_LOCATION,STM_SETICON,(WPARAM)pcmi->hDriveIcon,0);
  915. //
  916. //Initialize the auto launch check box
  917. //
  918. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_FILESYSTEM, 0, KEY_READ, &hk) == ERROR_SUCCESS)
  919. {
  920. dwLDSDisable = 0;
  921. dwType = REG_DWORD;
  922. cbBytes = sizeof(dwLDSDisable);
  923. if (RegQueryValueEx(hk, REGSTR_VAL_DRIVE_LDS_BDCAST_DISABLE, NULL, &dwType, (LPBYTE)&dwLDSDisable, &cbBytes) == ERROR_SUCCESS)
  924. {
  925. if (dwLDSDisable & (0x01 << pcmi->dre))
  926. {
  927. CheckDlgButton(hDlg, IDC_AUTO_LAUNCH, 0);
  928. }
  929. else
  930. {
  931. CheckDlgButton(hDlg, IDC_AUTO_LAUNCH, 1);
  932. }
  933. }
  934. RegCloseKey(hk);
  935. }
  936. //
  937. //Gray out the auto launch option if this is not a fixed disk
  938. //
  939. if (!GetHardwareType(pcmi->dre, hwType) ||
  940. (hwType != hwFixed))
  941. {
  942. CheckDlgButton(hDlg, IDC_AUTO_LAUNCH, 0);
  943. EnableWindow(GetDlgItem(hDlg, IDC_AUTO_LAUNCH), FALSE);
  944. }
  945. }
  946. break;
  947. case WM_NOTIFY:
  948. switch(((NMHDR *)lParam)->code)
  949. {
  950. case PSN_APPLY:
  951. pcmi = (CleanupMgrInfo *)GetWindowLongPtr (hDlg, DWLP_USER);
  952. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_FILESYSTEM, 0, KEY_READ | KEY_WRITE, &hk) == ERROR_SUCCESS)
  953. {
  954. dwLDSDisable = 0;
  955. dwType = REG_DWORD;
  956. cbBytes = sizeof(dwLDSDisable);
  957. if (RegQueryValueEx(hk, REGSTR_VAL_DRIVE_LDS_BDCAST_DISABLE, NULL, &dwType, (LPBYTE)&dwLDSDisable, &cbBytes) == ERROR_SUCCESS)
  958. {
  959. if (IsDlgButtonChecked(hDlg, IDC_AUTO_LAUNCH))
  960. {
  961. dwLDSDisable &= ~(0x01 << pcmi->dre);
  962. }
  963. else
  964. {
  965. dwLDSDisable |= (0x01 << pcmi->dre);
  966. }
  967. RegSetValueEx(hk, REGSTR_VAL_DRIVE_LDS_BDCAST_DISABLE, 0, REG_DWORD,
  968. (LPBYTE)&dwLDSDisable, sizeof(dwLDSDisable));
  969. }
  970. RegCloseKey(hk);
  971. }
  972. break;
  973. case PSN_RESET:
  974. break;
  975. }
  976. break;
  977. case WM_HELP:
  978. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, NULL,
  979. HELP_WM_HELP, (DWORD_PTR)(LPTSTR) aHelpIDs);
  980. return TRUE;
  981. case WM_CONTEXTMENU:
  982. WinHelp((HWND) wParam, NULL, HELP_CONTEXTMENU,
  983. (DWORD_PTR)(LPVOID) aHelpIDs);
  984. return TRUE;
  985. default:
  986. return FALSE;
  987. }
  988. return TRUE;
  989. }