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.

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