Skip to content

Commit

Permalink
Ensure extensions get the same decompiler helper.
Browse files Browse the repository at this point in the history
Fixes wixtoolset/issues#7548.

THIS IS A BREAKING INTERFACE/EXTENSIBILITY CHANGE.
  • Loading branch information
barnson committed Jul 13, 2023
1 parent 164c29a commit 7658b0d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
Expand Up @@ -36,13 +36,13 @@ public abstract class BaseWindowsInstallerDecompilerExtension : IWindowsInstalle
/// <summary>
/// See <see cref="IWindowsInstallerDecompilerExtension.PostDecompile(IWindowsInstallerDecompileResult)"/>
/// </summary>
public virtual void PreDecompile(IWindowsInstallerDecompileContext context)
public virtual void PreDecompile(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper helper)
{
this.Context = context;

this.Messaging = context.ServiceProvider.GetService<IMessaging>();
this.DecompilerHelper = helper;

this.DecompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();
this.Messaging = context.ServiceProvider.GetService<IMessaging>();
}

/// <summary>
Expand Down
Expand Up @@ -5,6 +5,7 @@ namespace WixToolset.Extensibility
using System.Collections.Generic;
using WixToolset.Data.WindowsInstaller;
using WixToolset.Extensibility.Data;
using WixToolset.Extensibility.Services;

/// <summary>
/// Interface all windows installer decompiler extensions implement.
Expand All @@ -21,7 +22,8 @@ public interface IWindowsInstallerDecompilerExtension
/// Called before decompiling occurs.
/// </summary>
/// <param name="context">Decompile context.</param>
void PreDecompile(IWindowsInstallerDecompileContext context);
/// <param name="helper">Decompile helper.</param>
void PreDecompile(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper helper);

/// <summary>
/// Called before decompiling occurs.
Expand Down
Expand Up @@ -39,16 +39,18 @@ public IWindowsInstallerDecompileResult Decompile(IWindowsInstallerDecompileCont
context.SymbolDefinitionCreator = this.ServiceProvider.GetService<ISymbolDefinitionCreator>();
}

var decompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();

// 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)
{
Expand All @@ -63,7 +65,7 @@ public IWindowsInstallerDecompileResult Decompile(IWindowsInstallerDecompileCont
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))
Expand All @@ -83,11 +85,11 @@ private IWindowsInstallerDecompileResult Execute(IWindowsInstallerDecompileConte
}
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;
Expand All @@ -106,7 +108,6 @@ private IWindowsInstallerDecompileResult DecompileDatabase(IWindowsInstallerDeco
var output = unbindCommand.Execute();
var extractedFilePaths = unbindCommand.ExportedFiles;

var decompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();
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);

Expand Down
Expand Up @@ -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;
Expand All @@ -30,20 +28,11 @@ public static IWixToolsetCoreServiceProvider AddWindowsInstallerBackend(this IWi

private static void AddServices(IWixToolsetCoreServiceProvider coreProvider)
{
// Singletons.
coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper(provider)));
coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerDecompilerHelper>(singletons, new WindowsInstallerDecompilerHelper(provider)));

// Transients.
coreProvider.AddService<IWindowsInstallerDecompiler>((provider, singletons) => new WindowsInstallerDecompiler(provider));
coreProvider.AddService<IWindowsInstallerDecompilerHelper>((provider, singletons) => new WindowsInstallerDecompilerHelper(provider));
coreProvider.AddService<IWindowsInstallerDecompileContext>((provider, singletons) => new WindowsInstallerDecompileContext(provider));
coreProvider.AddService<IWindowsInstallerDecompileResult>((provider, singletons) => new WindowsInstallerDecompileResult());
}

private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class
{
singletons.Add(typeof(T), service);
return service;
coreProvider.AddService<IWindowsInstallerBackendHelper>((provider, singletons) => new WindowsInstallerBackendHelper(provider));
}
}
}

0 comments on commit 7658b0d

Please sign in to comment.