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.

357 lines
9.3 KiB

  1. //////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // AppManager.cpp
  4. //
  5. // Copyright (C) 1998, 1999 Microsoft Corporation. All rights reserved.
  6. //
  7. //////////////////////////////////////////////////////////////////////////////////////////////
  8. #include "stdafx.h"
  9. #include "AppManDispatch.h"
  10. #include "AppManager.h"
  11. #include "AppEntry.h"
  12. #include "AppMan.h"
  13. #include "AppManDebug.h"
  14. //To flag as DBG_APPMANDP
  15. #ifdef DBG_MODULE
  16. #undef DBG_MODULE
  17. #endif
  18. #define DBG_MODULE DBG_APPMANDP
  19. //////////////////////////////////////////////////////////////////////////////////////////////
  20. //
  21. //////////////////////////////////////////////////////////////////////////////////////////////
  22. CAppManager::CAppManager(void)
  23. {
  24. DPFCONSTRUCTOR("CAppManager()");
  25. m_fInitialized = FALSE;
  26. //
  27. // Get the required interfaces
  28. //
  29. if (SUCCEEDED(CoInitialize(NULL)))
  30. {
  31. if (SUCCEEDED(CoCreateInstance(CLSID_ApplicationManager, NULL, CLSCTX_INPROC_SERVER, IID_ApplicationManager, (LPVOID *) &m_IApplicationManager)))
  32. {
  33. m_fInitialized = TRUE;
  34. }
  35. }
  36. }
  37. //////////////////////////////////////////////////////////////////////////////////////////////
  38. //
  39. //////////////////////////////////////////////////////////////////////////////////////////////
  40. CAppManager::~CAppManager(void)
  41. {
  42. DPFDESTRUCTOR("~CAppManager()");
  43. m_IApplicationManager->Release();
  44. m_fInitialized = FALSE;
  45. }
  46. //////////////////////////////////////////////////////////////////////////////////////////////
  47. //
  48. //////////////////////////////////////////////////////////////////////////////////////////////
  49. STDMETHODIMP CAppManager::get_AdvancedMode(long * lpAdvancedModeMask)
  50. {
  51. FUNCTION("CAppManager::get_AdvancedMode()");
  52. HRESULT hResult = E_FAIL;
  53. //
  54. // Make sure the IApplicationManager interface was successfully instantiated
  55. //
  56. if (TRUE == m_fInitialized)
  57. {
  58. //
  59. // Get the advanced mode
  60. //
  61. hResult = m_IApplicationManager->GetAdvancedMode((DWORD *)lpAdvancedModeMask);
  62. }
  63. return hResult;
  64. }
  65. //////////////////////////////////////////////////////////////////////////////////////////////
  66. //
  67. //////////////////////////////////////////////////////////////////////////////////////////////
  68. STDMETHODIMP CAppManager::get_MaximumAvailableKilobytes(long lSpaceCategory, long * lplKilobytes)
  69. {
  70. FUNCTION("CAppManager::get_MaximumAvailableKilobytes()");
  71. HRESULT hResult = E_FAIL;
  72. DWORD dwMaximumKilobytes, dwOptimalKilobytes;
  73. //
  74. // Make sure the IApplicationManager interface was successfully instantiated
  75. //
  76. if (TRUE == m_fInitialized)
  77. {
  78. //
  79. // Get the space information
  80. //
  81. hResult = m_IApplicationManager->GetAvailableSpace((const DWORD) lSpaceCategory, &dwMaximumKilobytes, &dwOptimalKilobytes);
  82. if (SUCCEEDED(hResult))
  83. {
  84. *lplKilobytes = (long) dwMaximumKilobytes;
  85. }
  86. }
  87. return hResult;
  88. }
  89. //////////////////////////////////////////////////////////////////////////////////////////////
  90. //
  91. //////////////////////////////////////////////////////////////////////////////////////////////
  92. STDMETHODIMP CAppManager::get_OptimalAvailableKilobytes(long lSpaceCategory, long * lplKilobytes)
  93. {
  94. FUNCTION("CAppManager::get_OptimalAvailableKilobytes()");
  95. HRESULT hResult = E_FAIL;
  96. DWORD dwMaximumKilobytes, dwOptimalKilobytes;
  97. //
  98. // Make sure the IApplicationManager interface was successfully instantiated
  99. //
  100. if (TRUE == m_fInitialized)
  101. {
  102. //
  103. // Get the space information
  104. //
  105. hResult = m_IApplicationManager->GetAvailableSpace((const DWORD) lSpaceCategory, &dwMaximumKilobytes, &dwOptimalKilobytes);
  106. if (SUCCEEDED(hResult))
  107. {
  108. *lplKilobytes = (long) dwOptimalKilobytes;
  109. }
  110. }
  111. return hResult;
  112. }
  113. //////////////////////////////////////////////////////////////////////////////////////////////
  114. //
  115. //////////////////////////////////////////////////////////////////////////////////////////////
  116. STDMETHODIMP CAppManager::get_ApplicationCount(long * lpVal)
  117. {
  118. FUNCTION("CAppManager::get_ApplicationCount()");
  119. HRESULT hResult = E_FAIL;
  120. IApplicationEntry * lpApplicationEntry;
  121. //
  122. // Make sure the IApplicationManager interface was successfully instantiated
  123. //
  124. if (TRUE == m_fInitialized)
  125. {
  126. //
  127. // By default there are 0 applications
  128. //
  129. *lpVal = 0;
  130. //
  131. // Create an application entry instance
  132. //
  133. if (SUCCEEDED(m_IApplicationManager->CreateApplicationEntry(&lpApplicationEntry)))
  134. {
  135. //
  136. // Enumerate all the applications and count them
  137. //
  138. while (SUCCEEDED(m_IApplicationManager->EnumApplications((DWORD) *lpVal, lpApplicationEntry)))
  139. {
  140. (*lpVal)++;
  141. }
  142. hResult = S_OK;
  143. }
  144. }
  145. return hResult;
  146. }
  147. //////////////////////////////////////////////////////////////////////////////////////////////
  148. //
  149. //////////////////////////////////////////////////////////////////////////////////////////////
  150. STDMETHODIMP CAppManager::CreateApplicationEntry(IAppEntry ** lppAppEntry)
  151. {
  152. FUNCTION("CAppManager::CreateApplicationEntry()");
  153. HRESULT hResult = E_FAIL;
  154. CAppEntry * lpAppEntry;
  155. //
  156. // Make sure the IApplicationManager interface was successfully instantiated
  157. //
  158. if (TRUE == m_fInitialized)
  159. {
  160. //
  161. // Create an IAppEntry instance
  162. //
  163. if (SUCCEEDED(CoCreateInstance(CLSID_AppEntry, NULL, CLSCTX_INPROC_SERVER, IID_IAppEntry, (LPVOID *) &lpAppEntry)))
  164. {
  165. if (NULL != lpAppEntry)
  166. {
  167. hResult = lpAppEntry->Initialize();
  168. if (SUCCEEDED(hResult))
  169. {
  170. *lppAppEntry = (IAppEntry *) lpAppEntry;
  171. }
  172. else
  173. {
  174. delete lpAppEntry;
  175. *lppAppEntry = NULL;
  176. }
  177. }
  178. }
  179. }
  180. return hResult;
  181. }
  182. //////////////////////////////////////////////////////////////////////////////////////////////
  183. //
  184. //////////////////////////////////////////////////////////////////////////////////////////////
  185. STDMETHODIMP CAppManager::GetApplicationInfo(IAppEntry * lpAppEntry)
  186. {
  187. FUNCTION("CAppManager::GetApplicationInfo()");
  188. HRESULT hResult = E_FAIL;
  189. CAppEntry * lpCAppEntry;
  190. IApplicationEntry * lpApplicationEntry;
  191. //
  192. // Make sure the IApplicationManager interface was successfully instantiated
  193. //
  194. if (TRUE == m_fInitialized)
  195. {
  196. //
  197. // Cast lpAppEntry to lpCAppEntry
  198. //
  199. lpCAppEntry = (CAppEntry *) lpAppEntry;
  200. lpCAppEntry->GetApplicationEntryPtr(&lpApplicationEntry);
  201. //
  202. // Get the application info
  203. //
  204. hResult = m_IApplicationManager->GetApplicationInfo(lpApplicationEntry);
  205. }
  206. return hResult;
  207. }
  208. //////////////////////////////////////////////////////////////////////////////////////////////
  209. //
  210. //////////////////////////////////////////////////////////////////////////////////////////////
  211. STDMETHODIMP CAppManager::EnumApplications(long lApplicationIndex, IAppEntry * lpAppEntry)
  212. {
  213. FUNCTION("CAppManager::EnumApplications()");
  214. HRESULT hResult = E_FAIL;
  215. CAppEntry * lpCAppEntry;
  216. IApplicationEntry * lpApplicationEntry;
  217. //
  218. // Make sure the IApplicationManager interface was successfully instantiated
  219. //
  220. if (TRUE == m_fInitialized)
  221. {
  222. //
  223. // Cast lpAppEntry to lpCAppEntry
  224. //
  225. lpCAppEntry = (CAppEntry *) lpAppEntry;
  226. lpCAppEntry->GetApplicationEntryPtr(&lpApplicationEntry);
  227. //
  228. // Get the application info
  229. //
  230. hResult = m_IApplicationManager->EnumApplications(lApplicationIndex, lpApplicationEntry);
  231. }
  232. return hResult;
  233. }
  234. //////////////////////////////////////////////////////////////////////////////////////////////
  235. //
  236. //////////////////////////////////////////////////////////////////////////////////////////////
  237. STDMETHODIMP CAppManager::EnumDeviceAvailableKilobytes(long lTempSpaceIndex, long * lTempSpaceKilobytes)
  238. {
  239. FUNCTION("CAppManager::EnumDeviceAvailableKilobytes()");
  240. HRESULT hResult = E_FAIL;
  241. DWORD dwExclusionMask;
  242. CHAR szString[MAX_PATH];
  243. hResult = m_IApplicationManager->EnumDevices((DWORD) lTempSpaceIndex, (LPDWORD) lTempSpaceKilobytes, &dwExclusionMask, APP_PROPERTY_STR_ANSI, szString, sizeof(szString));
  244. return hResult;
  245. }
  246. //////////////////////////////////////////////////////////////////////////////////////////////
  247. //
  248. //////////////////////////////////////////////////////////////////////////////////////////////
  249. STDMETHODIMP CAppManager::EnumDeviceRootPaths(long lTempSpaceIndex, BSTR * lpstrRootPath)
  250. {
  251. FUNCTION("CAppManager::EnumDeviceRootPaths()");
  252. HRESULT hResult = E_FAIL;
  253. DWORD dwKilobytes, dwExclusionMask;
  254. OLECHAR wszString[MAX_PATH];
  255. hResult = m_IApplicationManager->EnumDevices((DWORD) lTempSpaceIndex, &dwKilobytes, &dwExclusionMask, APP_PROPERTY_STR_UNICODE, wszString, sizeof(wszString));
  256. if (SUCCEEDED(hResult))
  257. {
  258. *lpstrRootPath = SysAllocString(wszString);
  259. }
  260. return hResult;
  261. }
  262. //////////////////////////////////////////////////////////////////////////////////////////////
  263. //
  264. //////////////////////////////////////////////////////////////////////////////////////////////
  265. STDMETHODIMP CAppManager::EnumDeviceExclusionMask(long lTempSpaceIndex, long * lExclusionMask)
  266. {
  267. FUNCTION("CAppManager::EnumDeviceExclusionMask()");
  268. HRESULT hResult = E_FAIL;
  269. DWORD dwKilobytes;
  270. CHAR szString[MAX_PATH];
  271. hResult = m_IApplicationManager->EnumDevices((DWORD) lTempSpaceIndex, &dwKilobytes, (LPDWORD) lExclusionMask, APP_PROPERTY_STR_ANSI, szString, sizeof(szString));
  272. return hResult;
  273. }