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.

265 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. app.cpp
  5. Abstract:
  6. Source file for dealing with registered apps.
  7. Author:
  8. Jim Schmidt (jimschm) 06-Mar-2001
  9. Revision History:
  10. <alias> <date> <description>
  11. --*/
  12. #include "pch.h"
  13. #include "shappmgrp.h"
  14. ULONGLONG
  15. pComputeWstrChecksum (
  16. IN ULONGLONG Checksum,
  17. IN PCWSTR String
  18. )
  19. {
  20. Checksum = (Checksum << 2) | (Checksum >> 62);
  21. if (String) {
  22. while (*String) {
  23. Checksum = (Checksum << 17) | (Checksum >> 47);
  24. Checksum ^= (ULONGLONG) (*String);
  25. String++;
  26. }
  27. }
  28. return Checksum;
  29. }
  30. PINSTALLEDAPPW
  31. GetInstalledAppsW (
  32. IN OUT PGROWBUFFER Buffer,
  33. OUT PUINT Count OPTIONAL
  34. )
  35. {
  36. IShellAppManager *appManager = NULL;
  37. IEnumInstalledApps *enumApps = NULL;
  38. IInstalledApp *installedApp = NULL;
  39. APPINFODATA appInfoData;
  40. HRESULT hr;
  41. PINSTALLEDAPPW instApp;
  42. UINT orgEnd = Buffer->End;
  43. if (Count) {
  44. *Count = 0;
  45. }
  46. __try {
  47. //
  48. // Create shell manager interface
  49. //
  50. hr = CoCreateInstance (
  51. __uuidof(ShellAppManager),
  52. NULL,
  53. CLSCTX_INPROC_SERVER,
  54. __uuidof(IShellAppManager),
  55. (void**) &appManager
  56. );
  57. if (hr != S_OK) {
  58. DEBUGMSG ((DBG_ERROR, "Can't create ShellAppManager interface. hr=%X", hr));
  59. __leave;
  60. }
  61. //
  62. // Create installed apps enum interface
  63. //
  64. hr = appManager->EnumInstalledApps (&enumApps);
  65. if (hr != S_OK) {
  66. DEBUGMSG ((DBG_ERROR, "Can't create EnumInstalledApps interface. hr=%X", hr));
  67. __leave;
  68. }
  69. //
  70. // Enumerate the apps
  71. //
  72. hr = enumApps->Next (&installedApp);
  73. while (hr == S_OK) {
  74. ZeroMemory (&appInfoData, sizeof (APPINFODATA));
  75. appInfoData.cbSize = sizeof(APPINFODATA);
  76. appInfoData.dwMask = AIM_DISPLAYNAME|
  77. AIM_VERSION|
  78. AIM_PUBLISHER|
  79. AIM_PRODUCTID|
  80. AIM_REGISTEREDOWNER|
  81. AIM_REGISTEREDCOMPANY|
  82. AIM_LANGUAGE|
  83. AIM_SUPPORTURL|
  84. AIM_SUPPORTTELEPHONE|
  85. AIM_HELPLINK|
  86. AIM_INSTALLLOCATION|
  87. AIM_INSTALLSOURCE|
  88. AIM_INSTALLDATE|
  89. AIM_CONTACT|
  90. AIM_COMMENTS|
  91. AIM_IMAGE|
  92. AIM_READMEURL|
  93. AIM_UPDATEINFOURL;
  94. hr = installedApp->GetAppInfo (&appInfoData);
  95. if (hr == S_OK) {
  96. instApp = (PINSTALLEDAPPW) GrowBuffer (Buffer, sizeof (INSTALLEDAPPW));
  97. StringCopyByteCountW (instApp->DisplayName, appInfoData.pszDisplayName, sizeof (instApp->DisplayName));
  98. if (appInfoData.pszVersion) {
  99. StringCopyByteCountW (instApp->Version, appInfoData.pszVersion, sizeof (instApp->Version));
  100. } else {
  101. instApp->Version[0] = 0;
  102. }
  103. if (appInfoData.pszPublisher) {
  104. StringCopyByteCountW (instApp->Publisher, appInfoData.pszPublisher, sizeof (instApp->Publisher));
  105. } else {
  106. instApp->Publisher[0] = 0;
  107. }
  108. if (appInfoData.pszProductID) {
  109. StringCopyByteCountW (instApp->ProductID, appInfoData.pszProductID, sizeof (instApp->ProductID));
  110. } else {
  111. instApp->ProductID[0] = 0;
  112. }
  113. if (appInfoData.pszRegisteredOwner) {
  114. StringCopyByteCountW (instApp->RegisteredOwner, appInfoData.pszRegisteredOwner, sizeof (instApp->RegisteredOwner));
  115. } else {
  116. instApp->RegisteredOwner[0] = 0;
  117. }
  118. if (appInfoData.pszRegisteredCompany) {
  119. StringCopyByteCountW (instApp->RegisteredCompany, appInfoData.pszRegisteredCompany, sizeof (instApp->RegisteredCompany));
  120. } else {
  121. instApp->RegisteredCompany[0] = 0;
  122. }
  123. if (appInfoData.pszLanguage) {
  124. StringCopyByteCountW (instApp->Language, appInfoData.pszLanguage, sizeof (instApp->Language));
  125. } else {
  126. instApp->Language[0] = 0;
  127. }
  128. if (appInfoData.pszSupportUrl) {
  129. StringCopyByteCountW (instApp->SupportUrl, appInfoData.pszSupportUrl, sizeof (instApp->SupportUrl));
  130. } else {
  131. instApp->SupportUrl[0] = 0;
  132. }
  133. if (appInfoData.pszSupportTelephone) {
  134. StringCopyByteCountW (instApp->SupportTelephone, appInfoData.pszSupportTelephone, sizeof (instApp->SupportTelephone));
  135. } else {
  136. instApp->SupportTelephone[0] = 0;
  137. }
  138. if (appInfoData.pszHelpLink) {
  139. StringCopyByteCountW (instApp->HelpLink, appInfoData.pszHelpLink, sizeof (instApp->HelpLink));
  140. } else {
  141. instApp->HelpLink[0] = 0;
  142. }
  143. if (appInfoData.pszInstallLocation) {
  144. StringCopyByteCountW (instApp->InstallLocation, appInfoData.pszInstallLocation, sizeof (instApp->InstallLocation));
  145. } else {
  146. instApp->InstallLocation[0] = 0;
  147. }
  148. if (appInfoData.pszInstallSource) {
  149. StringCopyByteCountW (instApp->InstallSource, appInfoData.pszInstallSource, sizeof (instApp->InstallSource));
  150. } else {
  151. instApp->InstallSource[0] = 0;
  152. }
  153. if (appInfoData.pszInstallDate) {
  154. StringCopyByteCountW (instApp->InstallDate, appInfoData.pszInstallDate, sizeof (instApp->InstallDate));
  155. } else {
  156. instApp->InstallDate[0] = 0;
  157. }
  158. if (appInfoData.pszContact) {
  159. StringCopyByteCountW (instApp->Contact, appInfoData.pszContact, sizeof (instApp->Contact));
  160. } else {
  161. instApp->Contact[0] = 0;
  162. }
  163. if (appInfoData.pszComments) {
  164. StringCopyByteCountW (instApp->Comments, appInfoData.pszComments, sizeof (instApp->Comments));
  165. } else {
  166. instApp->Comments[0] = 0;
  167. }
  168. if (appInfoData.pszImage) {
  169. StringCopyByteCountW (instApp->Image, appInfoData.pszImage, sizeof (instApp->Image));
  170. } else {
  171. instApp->Image[0] = 0;
  172. }
  173. if (appInfoData.pszReadmeUrl) {
  174. StringCopyByteCountW (instApp->ReadmeUrl, appInfoData.pszReadmeUrl, sizeof (instApp->ReadmeUrl));
  175. } else {
  176. instApp->ReadmeUrl[0] = 0;
  177. }
  178. if (appInfoData.pszUpdateInfoUrl) {
  179. StringCopyByteCountW (instApp->UpdateInfoUrl, appInfoData.pszUpdateInfoUrl, sizeof (instApp->UpdateInfoUrl));
  180. } else {
  181. instApp->UpdateInfoUrl[0] = 0;
  182. }
  183. instApp->Checksum = pComputeWstrChecksum (0, appInfoData.pszVersion);
  184. instApp->Checksum = pComputeWstrChecksum (instApp->Checksum, appInfoData.pszPublisher);
  185. instApp->Checksum = pComputeWstrChecksum (instApp->Checksum, appInfoData.pszProductID);
  186. instApp->Checksum = pComputeWstrChecksum (instApp->Checksum, appInfoData.pszLanguage);
  187. instApp->Checksum = pComputeWstrChecksum (instApp->Checksum, appInfoData.pszInstallLocation);
  188. instApp->Checksum = pComputeWstrChecksum (instApp->Checksum, appInfoData.pszInstallDate);
  189. if (Count) {
  190. *Count += 1;
  191. }
  192. }
  193. installedApp->Release();
  194. hr = enumApps->Next (&installedApp);
  195. }
  196. //
  197. // Done
  198. //
  199. hr = S_OK;
  200. }
  201. __finally {
  202. if (appManager) {
  203. appManager->Release();
  204. }
  205. if (enumApps) {
  206. enumApps->Release();
  207. }
  208. }
  209. return hr == S_OK ? (PINSTALLEDAPPW) (Buffer->Buf + orgEnd) : NULL;
  210. }