Ensure extensions get the same decompiler helper.
Fixes https://github.com/wixtoolset/issues/issues/7548. THIS IS A BREAKING INTERFACE/EXTENSIBILITY CHANGE.
Bob Arnson committed
Jun 15, 2023 at 15:40 UTC
cef14c6055f85e470ff9ce7a33b53e80d1160ba6
4 files changed
+15
-23
src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs
+3
-3
@@ -36,13 +36,13 @@ namespace WixToolset.Extensibility
36
/// <summary>
37
/// See <see cref="IWindowsInstallerDecompilerExtension.PostDecompile(IWindowsInstallerDecompileResult)"/>
38
/// </summary>
39
- public virtual void PreDecompile(IWindowsInstallerDecompileContext context)
39
+ public virtual void PreDecompile(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper helper)
40
{
41
this.Context = context;
42
43
- this.Messaging = context.ServiceProvider.GetService<IMessaging>();
43
+ this.DecompilerHelper = helper;
44
45
- this.DecompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();
45
+ this.Messaging = context.ServiceProvider.GetService<IMessaging>();
46
}
47
48
/// <summary>
src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs
+3
-1
@@ -5,6 +5,7 @@ namespace WixToolset.Extensibility
5
using System.Collections.Generic;
6
using WixToolset.Data.WindowsInstaller;
7
using WixToolset.Extensibility.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
/// <summary>
11
/// Interface all windows installer decompiler extensions implement.
@@ -21,7 +22,8 @@ namespace WixToolset.Extensibility
22
/// Called before decompiling occurs.
23
/// </summary>
24
/// <param name="context">Decompile context.</param>
24
- void PreDecompile(IWindowsInstallerDecompileContext context);
25
+ /// <param name="helper">Decompile helper.</param>
26
+ void PreDecompile(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper helper);
27
28
/// <summary>
29
/// Called before decompiling occurs.
src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerDecompiler.cs
+7
-6
@@ -39,16 +39,18 @@ namespace WixToolset.Core.WindowsInstaller
39
context.SymbolDefinitionCreator = this.ServiceProvider.GetService<ISymbolDefinitionCreator>();
40
}
41
42
+ var decompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();
43
+
44
// Pre-decompile.
45
//
46
foreach (var extension in context.Extensions)
47
{
46
- extension.PreDecompile(context);
48
+ extension.PreDecompile(context, decompilerHelper);
49
}
50
51
// Decompile.
52
//
51
- var result = this.Execute(context);
53
+ var result = this.Execute(context, decompilerHelper);
54
55
if (result != null)
56
{
@@ -63,7 +65,7 @@ namespace WixToolset.Core.WindowsInstaller
65
return result;
66
}
67
66
- private IWindowsInstallerDecompileResult Execute(IWindowsInstallerDecompileContext context)
68
+ private IWindowsInstallerDecompileResult Execute(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper decompilerHelper)
69
{
70
// Delete the directory and its files to prevent cab extraction failure due to an existing file.
71
if (!String.IsNullOrEmpty(context.ExtractFolder) && Directory.Exists(context.ExtractFolder))
@@ -83,11 +85,11 @@ namespace WixToolset.Core.WindowsInstaller
85
}
86
else
87
{
86
- return this.DecompileDatabase(context, backendHelper, fileSystem, pathResolver);
88
+ return this.DecompileDatabase(context, decompilerHelper, backendHelper, fileSystem, pathResolver);
89
}
90
}
91
90
- private IWindowsInstallerDecompileResult DecompileDatabase(IWindowsInstallerDecompileContext context, IWindowsInstallerBackendHelper backendHelper, IFileSystem fileSystem, IPathResolver pathResolver)
92
+ private IWindowsInstallerDecompileResult DecompileDatabase(IWindowsInstallerDecompileContext context, IWindowsInstallerDecompilerHelper decompilerHelper, IWindowsInstallerBackendHelper backendHelper, IFileSystem fileSystem, IPathResolver pathResolver)
93
{
94
var extractFilesFolder = context.SuppressExtractCabinets || (String.IsNullOrEmpty(context.CabinetExtractFolder) && String.IsNullOrEmpty(context.ExtractFolder)) ? null :
95
String.IsNullOrEmpty(context.CabinetExtractFolder) ? Path.Combine(context.ExtractFolder, "File") : context.CabinetExtractFolder;
@@ -106,7 +108,6 @@ namespace WixToolset.Core.WindowsInstaller
108
var output = unbindCommand.Execute();
109
var extractedFilePaths = unbindCommand.ExportedFiles;
110
109
- var decompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();
111
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);
112
var document = decompiler.Decompile(output);
113
src/wix/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs
+2
-13
@@ -2,8 +2,6 @@
2
3
namespace WixToolset.Core.WindowsInstaller
4
{
5
- using System;
6
- using System.Collections.Generic;
5
using WixToolset.Core.WindowsInstaller.ExtensibilityServices;
6
using WixToolset.Extensibility.Data;
7
using WixToolset.Extensibility.Services;
@@ -30,20 +28,11 @@ namespace WixToolset.Core.WindowsInstaller
28
29
private static void AddServices(IWixToolsetCoreServiceProvider coreProvider)
30
{
33
- // Singletons.
34
- coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper(provider)));
35
- coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerDecompilerHelper>(singletons, new WindowsInstallerDecompilerHelper(provider)));
36
-
37
- // Transients.
31
coreProvider.AddService<IWindowsInstallerDecompiler>((provider, singletons) => new WindowsInstallerDecompiler(provider));
32
+ coreProvider.AddService<IWindowsInstallerDecompilerHelper>((provider, singletons) => new WindowsInstallerDecompilerHelper(provider));
33
coreProvider.AddService<IWindowsInstallerDecompileContext>((provider, singletons) => new WindowsInstallerDecompileContext(provider));
34
coreProvider.AddService<IWindowsInstallerDecompileResult>((provider, singletons) => new WindowsInstallerDecompileResult());
41
- }
42
-
43
- private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class
44
- {
45
- singletons.Add(typeof(T), service);
46
- return service;
35
+ coreProvider.AddService<IWindowsInstallerBackendHelper>((provider, singletons) => new WindowsInstallerBackendHelper(provider));
36
}
37
}
38
}