From cef14c6055f85e470ff9ce7a33b53e80d1160ba6 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Thu, 15 Jun 2023 15:40:37 -0400 Subject: Ensure extensions get the same decompiler helper. Fixes https://github.com/wixtoolset/issues/issues/7548. THIS IS A BREAKING INTERFACE/EXTENSIBILITY CHANGE. --- .../BaseWindowsInstallerDecompilerExtension.cs | 6 +++--- .../IWindowsInstallerDecompilerExtension.cs | 4 +++- .../WindowsInstallerDecompiler.cs | 13 +++++++------ .../WixToolsetCoreServiceProviderExtensions.cs | 15 ++------------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs index 8072cd88..69124490 100644 --- a/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs +++ b/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs @@ -36,13 +36,13 @@ namespace WixToolset.Extensibility /// /// See /// - public virtual void PreDecompile(IWindowsInstallerDecompileContext context) + public virtual void PreDecompile(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper helper) { this.Context = context; - this.Messaging = context.ServiceProvider.GetService(); + this.DecompilerHelper = helper; - this.DecompilerHelper = context.ServiceProvider.GetService(); + this.Messaging = context.ServiceProvider.GetService(); } /// diff --git a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs index f7d54799..cbeda116 100644 --- a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs +++ b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs @@ -5,6 +5,7 @@ namespace WixToolset.Extensibility using System.Collections.Generic; using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; /// /// Interface all windows installer decompiler extensions implement. @@ -21,7 +22,8 @@ namespace WixToolset.Extensibility /// Called before decompiling occurs. /// /// Decompile context. - void PreDecompile(IWindowsInstallerDecompileContext context); + /// Decompile helper. + void PreDecompile(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper helper); /// /// Called before decompiling occurs. diff --git a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerDecompiler.cs b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerDecompiler.cs index fb560d1c..267fe495 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerDecompiler.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerDecompiler.cs @@ -39,16 +39,18 @@ namespace WixToolset.Core.WindowsInstaller context.SymbolDefinitionCreator = this.ServiceProvider.GetService(); } + var decompilerHelper = context.ServiceProvider.GetService(); + // Pre-decompile. // foreach (var extension in context.Extensions) { - extension.PreDecompile(context); + extension.PreDecompile(context, decompilerHelper); } // Decompile. // - var result = this.Execute(context); + var result = this.Execute(context, decompilerHelper); if (result != null) { @@ -63,7 +65,7 @@ namespace WixToolset.Core.WindowsInstaller return result; } - private IWindowsInstallerDecompileResult Execute(IWindowsInstallerDecompileContext context) + private IWindowsInstallerDecompileResult Execute(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper decompilerHelper) { // Delete the directory and its files to prevent cab extraction failure due to an existing file. if (!String.IsNullOrEmpty(context.ExtractFolder) && Directory.Exists(context.ExtractFolder)) @@ -83,11 +85,11 @@ namespace WixToolset.Core.WindowsInstaller } else { - return this.DecompileDatabase(context, backendHelper, fileSystem, pathResolver); + return this.DecompileDatabase(context, decompilerHelper, backendHelper, fileSystem, pathResolver); } } - private IWindowsInstallerDecompileResult DecompileDatabase(IWindowsInstallerDecompileContext context, IWindowsInstallerBackendHelper backendHelper, IFileSystem fileSystem, IPathResolver pathResolver) + private IWindowsInstallerDecompileResult DecompileDatabase(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper decompilerHelper, IWindowsInstallerBackendHelper backendHelper, IFileSystem fileSystem, IPathResolver pathResolver) { var extractFilesFolder = context.SuppressExtractCabinets || (String.IsNullOrEmpty(context.CabinetExtractFolder) && String.IsNullOrEmpty(context.ExtractFolder)) ? null : String.IsNullOrEmpty(context.CabinetExtractFolder) ? Path.Combine(context.ExtractFolder, "File") : context.CabinetExtractFolder; @@ -106,7 +108,6 @@ namespace WixToolset.Core.WindowsInstaller var output = unbindCommand.Execute(); var extractedFilePaths = unbindCommand.ExportedFiles; - var decompilerHelper = context.ServiceProvider.GetService(); var decompiler = new Decompiler(this.Messaging, backendHelper, decompilerHelper, context.Extensions, context.ExtensionData, context.SymbolDefinitionCreator, context.BaseSourcePath, context.SuppressCustomTables, context.SuppressDroppingEmptyTables, context.SuppressRelativeActionSequencing, context.SuppressUI, context.TreatProductAsModule); var document = decompiler.Decompile(output); diff --git a/src/wix/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs b/src/wix/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs index c085af9b..ea049598 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs @@ -2,8 +2,6 @@ namespace WixToolset.Core.WindowsInstaller { - using System; - using System.Collections.Generic; using WixToolset.Core.WindowsInstaller.ExtensibilityServices; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -30,20 +28,11 @@ namespace WixToolset.Core.WindowsInstaller private static void AddServices(IWixToolsetCoreServiceProvider coreProvider) { - // Singletons. - coreProvider.AddService((provider, singletons) => AddSingleton(singletons, new WindowsInstallerBackendHelper(provider))); - coreProvider.AddService((provider, singletons) => AddSingleton(singletons, new WindowsInstallerDecompilerHelper(provider))); - - // Transients. coreProvider.AddService((provider, singletons) => new WindowsInstallerDecompiler(provider)); + coreProvider.AddService((provider, singletons) => new WindowsInstallerDecompilerHelper(provider)); coreProvider.AddService((provider, singletons) => new WindowsInstallerDecompileContext(provider)); coreProvider.AddService((provider, singletons) => new WindowsInstallerDecompileResult()); - } - - private static T AddSingleton(Dictionary singletons, T service) where T : class - { - singletons.Add(typeof(T), service); - return service; + coreProvider.AddService((provider, singletons) => new WindowsInstallerBackendHelper(provider)); } } } -- cgit v1.2.3-55-g6feb