aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Decompiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Decompiler.cs')
-rw-r--r--src/WixToolset.Core/Decompiler.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Decompiler.cs b/src/WixToolset.Core/Decompiler.cs
new file mode 100644
index 00000000..5f14dfca
--- /dev/null
+++ b/src/WixToolset.Core/Decompiler.cs
@@ -0,0 +1,75 @@
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
3namespace WixToolset.Core
4{
5 using System;
6 using WixToolset.Data;
7 using WixToolset.Extensibility;
8 using WixToolset.Extensibility.Data;
9 using WixToolset.Extensibility.Services;
10
11 /// <summary>
12 /// Decompiler of the WiX toolset.
13 /// </summary>
14 internal class Decompiler : IDecompiler
15 {
16 internal Decompiler(IServiceProvider serviceProvider)
17 {
18 this.ServiceProvider = serviceProvider;
19 }
20
21 public OutputType DecompileType { get; set; }
22
23 public string IntermediateFolder { get; set; }
24
25 public string OutputPath { get; set; }
26
27 public IServiceProvider ServiceProvider { get; }
28
29 public BindResult Decompile(IDecompileContext context)
30 {
31 // Pre-decompile.
32 //
33 foreach (var extension in context.Extensions)
34 {
35 extension.PreDecompile(context);
36 }
37
38 // Decompile.
39 //
40 var bindResult = this.BackendDecompile(context);
41
42 if (bindResult != null)
43 {
44 // Post-decompile.
45 //
46 foreach (var extension in context.Extensions)
47 {
48 extension.PostDecompile(bindResult);
49 }
50 }
51
52 return bindResult;
53 }
54
55 private BindResult BackendDecompile(IDecompileContext context)
56 {
57 var extensionManager = context.ServiceProvider.GetService<IExtensionManager>();
58
59 var backendFactories = extensionManager.Create<IBackendFactory>();
60
61 foreach (var factory in backendFactories)
62 {
63 if (factory.TryCreateBackend(context.DecompileType.ToString(), context.OutputPath, out var backend))
64 {
65 var result = backend.Decompile(context);
66 return result;
67 }
68 }
69
70 // TODO: messaging that a backend could not be found to decompile the decompile type?
71
72 return null;
73 }
74 }
75}