Source code of Windows XP (NT5)
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.

171 lines
5.1 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // CLEANUP.CPP / Tuneup
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1998
  7. // All rights reserved
  8. //
  9. // Functions for the cleanup manager task wizard page.
  10. //
  11. // 8/98 - Jason Cohen (JCOHEN)
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. // Internal include files.
  15. //
  16. #include <windows.h>
  17. #include <tchar.h>
  18. //#include <initguid.h>
  19. #include <emptyvc.h>
  20. BOOL GetCleanupSettings(HWND hLB)
  21. {
  22. HKEY hKeyVolCache,
  23. hClientKey;
  24. CLSID clsid;
  25. LPEMPTYVOLUMECACHE pVolumeCache;
  26. LPWSTR wcsDisplayName,
  27. wcsDescription;
  28. TCHAR szRegKeyName[64];
  29. DWORD iSubKey;
  30. TCHAR szVolCacheClient[MAX_PATH];
  31. TCHAR szGUID[MAX_PATH];
  32. DWORD dwGUIDSize,
  33. dwType,
  34. dwSize,
  35. dwRes;
  36. BOOL bRet = TRUE;
  37. TCHAR szDisplayName[128];
  38. static TCHAR szRoot[] = _T("c:\\");
  39. static TCHAR szRegVolumeCache[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\explorer\\VolumeCaches");
  40. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegVolumeCache, 0, KEY_READ, &hKeyVolCache) != ERROR_SUCCESS)
  41. return FALSE;
  42. // Enumerate through all of the clients to see how large we need to make the pClientInfo array
  43. //
  44. iSubKey = 0;
  45. while ( RegEnumKey(hKeyVolCache, iSubKey, szVolCacheClient, sizeof(szVolCacheClient)) != ERROR_NO_MORE_ITEMS )
  46. iSubKey++;
  47. // Fill in the pClientInfo data structure and initialize all of the volume cache clients
  48. //
  49. iSubKey = 0;
  50. while ( RegEnumKey(hKeyVolCache, iSubKey++, szVolCacheClient, sizeof(szVolCacheClient)) != ERROR_NO_MORE_ITEMS )
  51. {
  52. if ( RegOpenKeyEx(hKeyVolCache, szVolCacheClient, 0, KEY_ALL_ACCESS, &hClientKey) != ERROR_SUCCESS )
  53. continue;
  54. lstrcpy(szRegKeyName, szVolCacheClient);
  55. // Check whether the StateFlags is non zero.
  56. //
  57. wsprintf(szDisplayName, _T("StateFlags%04d"), 0);
  58. dwSize = sizeof(DWORD);
  59. dwType = REG_DWORD;
  60. dwRes = 0;
  61. if ( RegQueryValueEx(hClientKey, szDisplayName, NULL, &dwType, (LPBYTE)&dwRes, &dwSize) == ERROR_SUCCESS )
  62. {
  63. // StateFlags overrides the flags got from Initialize(), so if it's set explicitly
  64. // as 0, then it's not a selected cleaner.
  65. //
  66. if (dwRes == 0)
  67. goto next;
  68. }
  69. // Get its GUID, call Initialize method to get the display name.
  70. //
  71. dwGUIDSize = sizeof(szGUID);
  72. dwType = REG_SZ;
  73. if ( RegQueryValueEx(hClientKey, NULL, NULL, &dwType, (LPBYTE)szGUID, &dwGUIDSize) == ERROR_SUCCESS )
  74. {
  75. HRESULT hr;
  76. WCHAR wcsFmtID[39];
  77. WCHAR wcsRoot[MAX_PATH];
  78. #ifdef _UNICODE
  79. lstrcpy(wcsFmtID, szGUID);
  80. #else // _UNICODE
  81. // Convert to Unicode.
  82. //
  83. MultiByteToWideChar(CP_ACP, 0, szGUID, -1, wcsFmtID, 39) ;
  84. #endif // _UNICODE
  85. // Convert to GUID.
  86. //
  87. hr = CLSIDFromString((LPOLESTR)wcsFmtID, &clsid);
  88. *szDisplayName = 0;
  89. // Create an instance of the COM object for this cleanup client
  90. //
  91. pVolumeCache = NULL;
  92. hr = CoCreateInstance(clsid,
  93. NULL,
  94. CLSCTX_INPROC_SERVER,
  95. IID_IEmptyVolumeCache,
  96. (void **) &pVolumeCache);
  97. if ( SUCCEEDED(hr) )
  98. {
  99. // Set the flags to pass to the cleanup client.
  100. //
  101. DWORD dwInitializeFlags = EVCF_SETTINGSMODE;
  102. #ifdef _UNICODE
  103. lstrcpy(wcsRoot, szRoot);
  104. #else // _UNICODE
  105. // Convert szRoot to UNICODE.
  106. //
  107. MultiByteToWideChar(CP_ACP, 0, szRoot, -1, wcsRoot, MAX_PATH);
  108. #endif // _UNICODE
  109. hr = pVolumeCache->Initialize(hClientKey,
  110. (LPCWSTR) wcsRoot,
  111. &((LPWSTR) wcsDisplayName),
  112. &((LPWSTR) wcsDescription),
  113. &dwInitializeFlags);
  114. if ( (dwRes == 0) && !(dwInitializeFlags & EVCF_ENABLEBYDEFAULT_AUTO) )
  115. // dwRes is 0 and still reach here, means there's no StateFlags, we
  116. // reference the dwInitializeFlags at this case
  117. //
  118. goto next;
  119. if ( SUCCEEDED(hr) && (S_OK == hr) && wcsDisplayName)
  120. #ifdef _UNICODE
  121. lstrcpy(szDisplayName, wcsDisplayName);
  122. #else // _UNICODE
  123. WideCharToMultiByte(CP_ACP, 0, wcsDisplayName, -1, szDisplayName, 128, NULL, NULL);
  124. #endif // _UNICODE
  125. else
  126. {
  127. // If the client did not return the DisplayName via the Initialize
  128. // Interface then we need to get it from the registry.
  129. // First check if their is a "display" value for the client's
  130. // name that is displayed in the list box. If not then use
  131. // the key name itself.
  132. //
  133. dwSize = 128;
  134. dwType = REG_SZ;
  135. if ( RegQueryValueEx(hClientKey, _T("display"), NULL, &dwType, (LPBYTE)szDisplayName, &dwSize) != ERROR_SUCCESS )
  136. // Count not find "display" value so use the key name instead.
  137. //
  138. lstrcpy(szDisplayName, szVolCacheClient);
  139. }
  140. }
  141. if (*szDisplayName)
  142. SendMessage(hLB, LB_ADDSTRING, 0, (LPARAM)szDisplayName);
  143. }
  144. next:
  145. RegCloseKey(hClientKey);
  146. }
  147. RegCloseKey(hKeyVolCache);
  148. return bRet;
  149. }