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.

283 lines
7.2 KiB

  1. //depot/private/lab01_fusion/base/win32/fusion/dll/whistler/sxsasmcache.cpp#4 - edit change 16520 (text)
  2. /*++
  3. Copyright (c) 2000 Microsoft Corporation
  4. Module Name:
  5. sxsasmcache.cpp
  6. Abstract:
  7. CAssemblyCache implementation for installation
  8. Author:
  9. Xiaoyu Wu (xiaoyuw) April 2000
  10. Revision History:
  11. xiaoyuw 10/26/2000 revise during Bate2 code review period
  12. xiaoyuw 12/21/2000 using new API
  13. --*/
  14. #include "stdinc.h"
  15. #include "fusionbuffer.h"
  16. #include "sxsp.h"
  17. #include "sxsasmitem.h"
  18. #include "sxsasmcache.h"
  19. #include "sxsasmname.h"
  20. #include "fusiontrace.h"
  21. STDAPI
  22. CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
  23. {
  24. HRESULT hr = NOERROR;
  25. FN_TRACE_HR(hr);
  26. CAssemblyCache * pAsmCache = NULL;
  27. if (ppAsmCache != NULL)
  28. *ppAsmCache = NULL;
  29. PARAMETER_CHECK(ppAsmCache != NULL);
  30. IFALLOCFAILED_EXIT(pAsmCache = new CAssemblyCache);
  31. pAsmCache->AddRef(); // void
  32. *ppAsmCache = pAsmCache;
  33. hr = NOERROR;
  34. Exit:
  35. return hr;
  36. }
  37. // Fusion -> Sxs
  38. BOOL
  39. SxspTranslateReferenceFrom(
  40. IN LPCFUSION_INSTALL_REFERENCE pFusionReference,
  41. OUT SXS_INSTALL_REFERENCEW &SxsReference
  42. )
  43. {
  44. FN_PROLOG_WIN32
  45. PARAMETER_CHECK(pFusionReference != NULL);
  46. PARAMETER_CHECK(pFusionReference->cbSize <= SxsReference.cbSize);
  47. if (RTL_CONTAINS_FIELD(pFusionReference, pFusionReference->cbSize, guidScheme) &&
  48. RTL_CONTAINS_FIELD(&SxsReference, SxsReference.cbSize, guidScheme))
  49. SxsReference.guidScheme = pFusionReference->guidScheme;
  50. if (RTL_CONTAINS_FIELD(pFusionReference, pFusionReference->cbSize, szIdentifier) &&
  51. RTL_CONTAINS_FIELD(&SxsReference, SxsReference.cbSize, lpIdentifier))
  52. SxsReference.lpIdentifier = pFusionReference->szIdentifier;
  53. if (RTL_CONTAINS_FIELD(pFusionReference, pFusionReference->cbSize, szNonCannonicalData) &&
  54. RTL_CONTAINS_FIELD(&SxsReference, SxsReference.cbSize, lpNonCanonicalData))
  55. SxsReference.lpNonCanonicalData = pFusionReference->szNonCannonicalData;
  56. FN_EPILOG
  57. }
  58. // Sxs -> Fusion
  59. BOOL
  60. SxspTranslateReferenceFrom(
  61. IN PCSXS_INSTALL_REFERENCEW pSxsReference,
  62. OUT FUSION_INSTALL_REFERENCE &FusionReference
  63. )
  64. {
  65. FN_PROLOG_WIN32
  66. //
  67. // Pointer must be non-null, and the SXS structure must be either
  68. // the same size or smaller than the equivalent Fusion structure.
  69. //
  70. PARAMETER_CHECK(pSxsReference);
  71. //
  72. // Assume size has been set by caller.
  73. //
  74. PARAMETER_CHECK(pSxsReference->cbSize <= FusionReference.cbSize);
  75. if (RTL_CONTAINS_FIELD(&FusionReference, FusionReference.cbSize, guidScheme) &&
  76. RTL_CONTAINS_FIELD(pSxsReference, pSxsReference->cbSize, guidScheme))
  77. FusionReference.guidScheme = pSxsReference->guidScheme;
  78. if (RTL_CONTAINS_FIELD(&FusionReference, FusionReference.cbSize, szIdentifier) &&
  79. RTL_CONTAINS_FIELD(pSxsReference, pSxsReference->cbSize, lpIdentifier))
  80. FusionReference.szIdentifier = pSxsReference->lpIdentifier;
  81. if (RTL_CONTAINS_FIELD(&FusionReference, FusionReference.cbSize, szNonCannonicalData) &&
  82. RTL_CONTAINS_FIELD(pSxsReference, pSxsReference->cbSize, lpNonCanonicalData))
  83. FusionReference.szNonCannonicalData = pSxsReference->lpNonCanonicalData;
  84. FN_EPILOG
  85. }
  86. STDMETHODIMP
  87. CAssemblyCache::UninstallAssembly(
  88. /* [in] */ DWORD dwFlags,
  89. /* [in] */ LPCWSTR pszAssemblyName,
  90. /* [in] */ LPCFUSION_INSTALL_REFERENCE pRefData,
  91. /* [out, optional] */ ULONG *pulDisposition)
  92. {
  93. HRESULT hr=S_OK;
  94. FN_TRACE_HR(hr);
  95. SXS_UNINSTALLW Uninstall;
  96. SXS_INSTALL_REFERENCEW Reference = { sizeof(Reference) };
  97. DWORD dwDisposition;
  98. if (pulDisposition != NULL)
  99. *pulDisposition = 0;
  100. PARAMETER_CHECK((pszAssemblyName!= NULL) && (dwFlags ==0));
  101. ZeroMemory(&Uninstall, sizeof(Uninstall));
  102. Uninstall.cbSize = sizeof(Uninstall);
  103. Uninstall.lpAssemblyIdentity = pszAssemblyName;
  104. if (pRefData != NULL)
  105. {
  106. IFW32FALSE_EXIT(::SxspTranslateReferenceFrom(pRefData, Reference));
  107. Uninstall.lpInstallReference = &Reference;
  108. Uninstall.dwFlags |= SXS_UNINSTALL_FLAG_REFERENCE_VALID;
  109. }
  110. IFW32FALSE_EXIT(::SxsUninstallW(&Uninstall, &dwDisposition));
  111. if (pulDisposition != NULL)
  112. *pulDisposition = static_cast<DWORD>(dwDisposition);
  113. FN_EPILOG
  114. }
  115. STDMETHODIMP CAssemblyCache::QueryAssemblyInfo(
  116. /* [in] */ DWORD dwFlags,
  117. /* [in] */ LPCWSTR pwzTextualAssembly,
  118. /* [in, out] */ ASSEMBLY_INFO *pAsmInfo)
  119. {
  120. HRESULT hr = NOERROR;
  121. FN_TRACE_HR(hr);
  122. PARAMETER_CHECK(((dwFlags == 0) && (pwzTextualAssembly !=NULL)));
  123. IFW32FALSE_EXIT(::SxsQueryAssemblyInfo(dwFlags, pwzTextualAssembly, pAsmInfo));
  124. hr = NOERROR;
  125. Exit:
  126. return hr;
  127. }
  128. STDMETHODIMP
  129. CAssemblyCache::CreateAssemblyCacheItem(
  130. /* [in] */ DWORD dwFlags,
  131. /* [in] */ PVOID pvReserved,
  132. /* [out] */ IAssemblyCacheItem **ppAsmItem,
  133. /* [in, optional] */ LPCWSTR pszAssemblyName) // uncanonicalized, comma separted name=value pairs.
  134. {
  135. HRESULT hr = NOERROR;
  136. FN_TRACE_HR(hr);
  137. CSmartRef<CAssemblyCacheItem> pAsmItem;
  138. if (ppAsmItem != NULL)
  139. *ppAsmItem = NULL;
  140. PARAMETER_CHECK((ppAsmItem != NULL) && (dwFlags == 0) && (pvReserved == NULL));
  141. IFALLOCFAILED_EXIT(pAsmItem = new CAssemblyCacheItem);
  142. IFCOMFAILED_EXIT(pAsmItem->Initialize());
  143. *ppAsmItem = pAsmItem.Disown(); // void
  144. hr = NOERROR;
  145. Exit:
  146. return hr;
  147. }
  148. STDMETHODIMP
  149. CAssemblyCache::InstallAssembly(
  150. /* [in] */ DWORD dwFlags,
  151. /* [in] */ LPCWSTR pszManifestPath,
  152. /* [in] */ LPCFUSION_INSTALL_REFERENCE pRefData)
  153. {
  154. HRESULT hr = NOERROR;
  155. FN_TRACE_HR(hr);
  156. SXS_INSTALLW Install = { sizeof(SXS_INSTALLW) };
  157. SXS_INSTALL_REFERENCEW Reference = { sizeof(Reference) };
  158. PARAMETER_CHECK((pszManifestPath != NULL) && (dwFlags == 0));
  159. Install.lpManifestPath = pszManifestPath;
  160. if ( pRefData == NULL )
  161. {
  162. Install.dwFlags = SXS_INSTALL_FLAG_INSTALLED_BY_DARWIN;
  163. }
  164. else
  165. {
  166. //
  167. // Otherwise, the pvReserved is really a "reference"
  168. //
  169. Install.dwFlags |= SXS_INSTALL_FLAG_REFERENCE_VALID;
  170. IFW32FALSE_EXIT(::SxspTranslateReferenceFrom(pRefData, Reference));
  171. Install.lpReference = &Reference;
  172. }
  173. IFW32FALSE_EXIT(::SxsInstallW(&Install));
  174. FN_EPILOG
  175. }
  176. STDMETHODIMP
  177. CAssemblyCache::CreateAssemblyScavenger(
  178. IAssemblyScavenger **ppAsmScavenger )
  179. {
  180. #if 0
  181. HRESULT hr = NOERROR;
  182. FN_TRACE_HR(hr);
  183. PARAMETER_CHECK(ppAsmScavenger != NULL);
  184. *ppAsmScavenger = NULL;
  185. Exit:
  186. #endif
  187. return E_NOTIMPL;
  188. }
  189. //
  190. // IUnknown boilerplate...
  191. //
  192. STDMETHODIMP
  193. CAssemblyCache::QueryInterface(REFIID riid, void** ppvObj)
  194. {
  195. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IAssemblyCache))
  196. {
  197. *ppvObj = static_cast<IAssemblyCache*> (this);
  198. AddRef();
  199. return S_OK;
  200. }
  201. else
  202. {
  203. *ppvObj = NULL;
  204. return E_NOINTERFACE;
  205. }
  206. }
  207. STDMETHODIMP_(ULONG)
  208. CAssemblyCache::AddRef()
  209. {
  210. return SxspInterlockedIncrement(&m_cRef);
  211. }
  212. STDMETHODIMP_(ULONG)
  213. CAssemblyCache::Release()
  214. {
  215. ULONG lRet = SxspInterlockedDecrement(&m_cRef);
  216. if (!lRet)
  217. FUSION_DELETE_SINGLETON(this);
  218. return lRet;
  219. }