| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Core.WindowsInstaller |
| 4 | { |
| 5 | using System.Collections.Generic; |
| 6 | using WixToolset.Core.WindowsInstaller.Bind; |
| 7 | using WixToolset.Data.WindowsInstaller; |
| 8 | using WixToolset.Extensibility; |
| 9 | using WixToolset.Extensibility.Data; |
| 10 | using WixToolset.Extensibility.Services; |
| 11 | |
| 12 | internal class MspBackend : IBackend |
| 13 | { |
| 14 | public IBindResult Bind(IBindContext context) |
| 15 | { |
| 16 | var messaging = context.ServiceProvider.GetService<IMessaging>(); |
| 17 | |
| 18 | var backendHelper = context.ServiceProvider.GetService<IBackendHelper>(); |
| 19 | |
| 20 | var fileSystem = context.ServiceProvider.GetService<IFileSystem>(); |
| 21 | |
| 22 | var pathResolver = context.ServiceProvider.GetService<IPathResolver>(); |
| 23 | |
| 24 | var fileResolver = context.ServiceProvider.GetService<IFileResolver>(); |
| 25 | |
| 26 | var extensionManager = context.ServiceProvider.GetService<IExtensionManager>(); |
| 27 | |
| 28 | var resolveExtensions = extensionManager.GetServices<IResolverExtension>(); |
| 29 | |
| 30 | var backendExtensions = extensionManager.GetServices<IWindowsInstallerBackendBinderExtension>(); |
| 31 | |
| 32 | foreach (var extension in backendExtensions) |
| 33 | { |
| 34 | extension.PreBackendBind(context); |
| 35 | } |
| 36 | |
| 37 | // Create transforms named in patch transforms. |
| 38 | IEnumerable<PatchTransform> patchTransforms; |
| 39 | PatchFilterMap patchFilterMap; |
| 40 | { |
| 41 | var command = new CreatePatchTransformsCommand(messaging, backendHelper, fileSystem, pathResolver, fileResolver, resolveExtensions, backendExtensions, context.IntermediateRepresentation, context.IntermediateFolder, context.BindPaths); |
| 42 | command.Execute(); |
| 43 | |
| 44 | patchTransforms = command.PatchTransforms; |
| 45 | patchFilterMap = command.PatchFilterMap; |
| 46 | } |
| 47 | |
| 48 | // Reduce transforms. |
| 49 | { |
| 50 | var command = new ReduceTransformCommand(context.IntermediateRepresentation, patchTransforms, patchFilterMap); |
| 51 | command.Execute(); |
| 52 | } |
| 53 | |
| 54 | // Enhance the intermediate by attaching the created patch transforms. |
| 55 | IEnumerable<SubStorage> subStorages; |
| 56 | { |
| 57 | var command = new CreatePatchSubStoragesCommand(messaging, backendHelper, context.IntermediateRepresentation, patchTransforms); |
| 58 | subStorages = command.Execute(); |
| 59 | } |
| 60 | |
| 61 | // Create WindowsInstallerData with patch metdata and transforms as sub-storages |
| 62 | // and create MSP from that WindowsInstallerData. |
| 63 | IBindResult result = null; |
| 64 | try |
| 65 | { |
| 66 | var command = new BindDatabaseCommand(context, backendExtensions, subStorages); |
| 67 | result = command.Execute(); |
| 68 | |
| 69 | foreach (var extension in backendExtensions) |
| 70 | { |
| 71 | extension.PostBackendBind(result); |
| 72 | } |
| 73 | |
| 74 | return result; |
| 75 | } |
| 76 | catch |
| 77 | { |
| 78 | result?.Dispose(); |
| 79 | throw; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |