diff options
author | Rob Mensching <rob@firegiant.com> | 2018-10-24 21:06:51 -0700 |
---|---|---|
committer | Rob Mensching <rob@robmensching.com> | 2018-10-24 21:17:34 -0700 |
commit | 822d917960cbd35f506598af4baa6a20ad4b447e (patch) | |
tree | 0d4cf39e25f5fe213bbeac2fb546d2aa86b172db /src/WixToolset.Core | |
parent | 7a2859709034f7f4f048a0757779a6e2fee6df5b (diff) | |
download | wix-822d917960cbd35f506598af4baa6a20ad4b447e.tar.gz wix-822d917960cbd35f506598af4baa6a20ad4b447e.tar.bz2 wix-822d917960cbd35f506598af4baa6a20ad4b447e.zip |
Re-introduce "decompile" to backend
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r-- | src/WixToolset.Core/CommandLine/DecompileCommand.cs | 212 | ||||
-rw-r--r-- | src/WixToolset.Core/DecompileContext.cs | 20 | ||||
-rw-r--r-- | src/WixToolset.Core/Decompiler.cs | 12 | ||||
-rw-r--r-- | src/WixToolset.Core/IDecompiler.cs | 4 | ||||
-rw-r--r-- | src/WixToolset.Core/OptimizeCA.cs | 4 |
5 files changed, 241 insertions, 11 deletions
diff --git a/src/WixToolset.Core/CommandLine/DecompileCommand.cs b/src/WixToolset.Core/CommandLine/DecompileCommand.cs new file mode 100644 index 00000000..87cead80 --- /dev/null +++ b/src/WixToolset.Core/CommandLine/DecompileCommand.cs | |||
@@ -0,0 +1,212 @@ | |||
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.CommandLine | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using WixToolset.Data; | ||
9 | using WixToolset.Extensibility; | ||
10 | using WixToolset.Extensibility.Data; | ||
11 | using WixToolset.Extensibility.Services; | ||
12 | |||
13 | internal class DecompileCommand : ICommandLineCommand | ||
14 | { | ||
15 | private readonly CommandLine commandLine; | ||
16 | |||
17 | public DecompileCommand(IServiceProvider serviceProvider) | ||
18 | { | ||
19 | this.ServiceProvider = serviceProvider; | ||
20 | this.Messaging = serviceProvider.GetService<IMessaging>(); | ||
21 | this.commandLine = new CommandLine(this.Messaging); | ||
22 | } | ||
23 | |||
24 | public bool ShowLogo => this.commandLine.ShowLogo; | ||
25 | |||
26 | public bool StopParsing => this.commandLine.ShowHelp; | ||
27 | |||
28 | private IServiceProvider ServiceProvider { get; } | ||
29 | |||
30 | public IMessaging Messaging { get; } | ||
31 | |||
32 | private IEnumerable<SourceFile> SourceFiles { get; } | ||
33 | |||
34 | private string OutputPath { get; } | ||
35 | |||
36 | public int Execute() | ||
37 | { | ||
38 | if (this.commandLine.ShowHelp) | ||
39 | { | ||
40 | Console.WriteLine("TODO: Show decompile command help"); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | var context = this.ServiceProvider.GetService<IDecompileContext>(); | ||
45 | context.Extensions = this.ServiceProvider.GetService<IExtensionManager>().Create<IDecompilerExtension>(); | ||
46 | context.DecompilePath = this.commandLine.DecompileFilePath; | ||
47 | context.DecompileType = this.commandLine.CalculateDecompileType(); | ||
48 | context.IntermediateFolder = this.commandLine.CalculateIntermedateFolder(); | ||
49 | context.OutputPath = this.commandLine.CalculateOutputPath(); | ||
50 | |||
51 | try | ||
52 | { | ||
53 | var decompiler = this.ServiceProvider.GetService<IDecompiler>(); | ||
54 | var result = decompiler.Decompile(context); | ||
55 | } | ||
56 | catch (WixException e) | ||
57 | { | ||
58 | this.Messaging.Write(e.Error); | ||
59 | } | ||
60 | |||
61 | if (this.Messaging.EncounteredError) | ||
62 | { | ||
63 | return 1; | ||
64 | } | ||
65 | |||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | public bool TryParseArgument(ICommandLineParser parser, string argument) | ||
70 | { | ||
71 | return this.commandLine.TryParseArgument(argument, parser); | ||
72 | } | ||
73 | |||
74 | private class CommandLine | ||
75 | { | ||
76 | public CommandLine(IMessaging messaging) | ||
77 | { | ||
78 | this.Messaging = messaging; | ||
79 | } | ||
80 | |||
81 | private IMessaging Messaging { get; } | ||
82 | |||
83 | public string DecompileFilePath { get; private set; } | ||
84 | |||
85 | public string DecompileType { get; private set; } | ||
86 | |||
87 | public Platform Platform { get; private set; } | ||
88 | |||
89 | public bool ShowLogo { get; private set; } | ||
90 | |||
91 | public bool ShowHelp { get; private set; } | ||
92 | |||
93 | public string IntermediateFolder { get; private set; } | ||
94 | |||
95 | public string OutputFile { get; private set; } | ||
96 | |||
97 | public bool TryParseArgument(string arg, ICommandLineParser parser) | ||
98 | { | ||
99 | if (parser.IsSwitch(arg)) | ||
100 | { | ||
101 | var parameter = arg.Substring(1); | ||
102 | switch (parameter.ToLowerInvariant()) | ||
103 | { | ||
104 | case "?": | ||
105 | case "h": | ||
106 | case "help": | ||
107 | this.ShowHelp = true; | ||
108 | return true; | ||
109 | |||
110 | case "intermediatefolder": | ||
111 | this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg); | ||
112 | return true; | ||
113 | |||
114 | case "o": | ||
115 | case "out": | ||
116 | this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg); | ||
117 | return true; | ||
118 | |||
119 | case "nologo": | ||
120 | this.ShowLogo = false; | ||
121 | return true; | ||
122 | |||
123 | case "v": | ||
124 | case "verbose": | ||
125 | this.Messaging.ShowVerboseMessages = true; | ||
126 | return true; | ||
127 | |||
128 | case "sw": | ||
129 | case "suppresswarning": | ||
130 | var warning = parser.GetNextArgumentOrError(arg); | ||
131 | if (!String.IsNullOrEmpty(warning)) | ||
132 | { | ||
133 | var warningNumber = Convert.ToInt32(warning); | ||
134 | this.Messaging.SuppressWarningMessage(warningNumber); | ||
135 | } | ||
136 | return true; | ||
137 | } | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | if (String.IsNullOrEmpty(this.DecompileFilePath)) | ||
142 | { | ||
143 | this.DecompileFilePath = parser.GetArgumentAsFilePathOrError(arg, "decompile file"); | ||
144 | return true; | ||
145 | } | ||
146 | else if (String.IsNullOrEmpty(this.OutputFile)) | ||
147 | { | ||
148 | this.OutputFile = parser.GetArgumentAsFilePathOrError(arg, "output file"); | ||
149 | return true; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | return false; | ||
154 | } | ||
155 | |||
156 | public OutputType CalculateDecompileType() | ||
157 | { | ||
158 | if (String.IsNullOrEmpty(this.DecompileType)) | ||
159 | { | ||
160 | this.DecompileType = Path.GetExtension(this.DecompileFilePath); | ||
161 | } | ||
162 | |||
163 | switch (this.DecompileType.ToLowerInvariant()) | ||
164 | { | ||
165 | case "bundle": | ||
166 | case ".exe": | ||
167 | return OutputType.Bundle; | ||
168 | |||
169 | case "library": | ||
170 | case ".wixlib": | ||
171 | return OutputType.Library; | ||
172 | |||
173 | case "module": | ||
174 | case ".msm": | ||
175 | return OutputType.Module; | ||
176 | |||
177 | case "patch": | ||
178 | case ".msp": | ||
179 | return OutputType.Patch; | ||
180 | |||
181 | case ".pcp": | ||
182 | return OutputType.PatchCreation; | ||
183 | |||
184 | case "product": | ||
185 | case "package": | ||
186 | case ".msi": | ||
187 | return OutputType.Product; | ||
188 | |||
189 | case "transform": | ||
190 | case ".mst": | ||
191 | return OutputType.Transform; | ||
192 | |||
193 | case "intermediatepostlink": | ||
194 | case ".wixipl": | ||
195 | return OutputType.IntermediatePostLink; | ||
196 | } | ||
197 | |||
198 | return OutputType.Unknown; | ||
199 | } | ||
200 | |||
201 | public string CalculateIntermedateFolder() | ||
202 | { | ||
203 | return String.IsNullOrEmpty(this.IntermediateFolder) ? Path.GetTempPath() : this.IntermediateFolder; | ||
204 | } | ||
205 | |||
206 | public string CalculateOutputPath() | ||
207 | { | ||
208 | return String.IsNullOrEmpty(this.OutputFile) ? Path.ChangeExtension(this.DecompileFilePath, ".wxs") : this.OutputFile; | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | } | ||
diff --git a/src/WixToolset.Core/DecompileContext.cs b/src/WixToolset.Core/DecompileContext.cs index a9f0640a..b697c3cf 100644 --- a/src/WixToolset.Core/DecompileContext.cs +++ b/src/WixToolset.Core/DecompileContext.cs | |||
@@ -1,4 +1,4 @@ | |||
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. | 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 | 2 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core |
4 | { | 4 | { |
@@ -17,12 +17,30 @@ namespace WixToolset.Core | |||
17 | 17 | ||
18 | public IServiceProvider ServiceProvider { get; } | 18 | public IServiceProvider ServiceProvider { get; } |
19 | 19 | ||
20 | public string DecompilePath { get; set; } | ||
21 | |||
20 | public OutputType DecompileType { get; set; } | 22 | public OutputType DecompileType { get; set; } |
21 | 23 | ||
22 | public IEnumerable<IDecompilerExtension> Extensions { get; set; } | 24 | public IEnumerable<IDecompilerExtension> Extensions { get; set; } |
23 | 25 | ||
26 | public string ExtractFolder { get; set; } | ||
27 | |||
28 | public string BaseSourcePath { get; set; } | ||
29 | |||
24 | public string IntermediateFolder { get; set; } | 30 | public string IntermediateFolder { get; set; } |
25 | 31 | ||
32 | public bool IsAdminImage { get; set; } | ||
33 | |||
26 | public string OutputPath { get; set; } | 34 | public string OutputPath { get; set; } |
35 | |||
36 | public bool SuppressCustomTables { get; set; } | ||
37 | |||
38 | public bool SuppressDroppingEmptyTables { get; set; } | ||
39 | |||
40 | public bool SuppressExtractCabinets { get; set; } | ||
41 | |||
42 | public bool SuppressUI { get; set; } | ||
43 | |||
44 | public bool TreatProductAsModule { get; set; } | ||
27 | } | 45 | } |
28 | } | 46 | } |
diff --git a/src/WixToolset.Core/Decompiler.cs b/src/WixToolset.Core/Decompiler.cs index 45cfbea0..685722a8 100644 --- a/src/WixToolset.Core/Decompiler.cs +++ b/src/WixToolset.Core/Decompiler.cs | |||
@@ -19,7 +19,7 @@ namespace WixToolset.Core | |||
19 | 19 | ||
20 | public IServiceProvider ServiceProvider { get; } | 20 | public IServiceProvider ServiceProvider { get; } |
21 | 21 | ||
22 | public BindResult Decompile(IDecompileContext context) | 22 | public DecompileResult Decompile(IDecompileContext context) |
23 | { | 23 | { |
24 | // Pre-decompile. | 24 | // Pre-decompile. |
25 | // | 25 | // |
@@ -30,22 +30,22 @@ namespace WixToolset.Core | |||
30 | 30 | ||
31 | // Decompile. | 31 | // Decompile. |
32 | // | 32 | // |
33 | var bindResult = this.BackendDecompile(context); | 33 | var result = this.BackendDecompile(context); |
34 | 34 | ||
35 | if (bindResult != null) | 35 | if (result != null) |
36 | { | 36 | { |
37 | // Post-decompile. | 37 | // Post-decompile. |
38 | // | 38 | // |
39 | foreach (var extension in context.Extensions) | 39 | foreach (var extension in context.Extensions) |
40 | { | 40 | { |
41 | extension.PostDecompile(bindResult); | 41 | extension.PostDecompile(result); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | return bindResult; | 45 | return result; |
46 | } | 46 | } |
47 | 47 | ||
48 | private BindResult BackendDecompile(IDecompileContext context) | 48 | private DecompileResult BackendDecompile(IDecompileContext context) |
49 | { | 49 | { |
50 | var extensionManager = context.ServiceProvider.GetService<IExtensionManager>(); | 50 | var extensionManager = context.ServiceProvider.GetService<IExtensionManager>(); |
51 | 51 | ||
diff --git a/src/WixToolset.Core/IDecompiler.cs b/src/WixToolset.Core/IDecompiler.cs index b9bb7ed8..82b02943 100644 --- a/src/WixToolset.Core/IDecompiler.cs +++ b/src/WixToolset.Core/IDecompiler.cs | |||
@@ -1,4 +1,4 @@ | |||
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. | 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 | 2 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core |
4 | { | 4 | { |
@@ -6,6 +6,6 @@ namespace WixToolset.Core | |||
6 | 6 | ||
7 | public interface IDecompiler | 7 | public interface IDecompiler |
8 | { | 8 | { |
9 | BindResult Decompile(IDecompileContext context); | 9 | DecompileResult Decompile(IDecompileContext context); |
10 | } | 10 | } |
11 | } | 11 | } |
diff --git a/src/WixToolset.Core/OptimizeCA.cs b/src/WixToolset.Core/OptimizeCA.cs index ba17604d..0d7b5e1a 100644 --- a/src/WixToolset.Core/OptimizeCA.cs +++ b/src/WixToolset.Core/OptimizeCA.cs | |||
@@ -1,4 +1,4 @@ | |||
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. | 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 | 2 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core |
4 | { | 4 | { |
@@ -8,7 +8,7 @@ namespace WixToolset.Core | |||
8 | /// Values for the OptimizeCA MsiPatchMetdata property, which indicates whether custom actions can be skipped when applying the patch. | 8 | /// Values for the OptimizeCA MsiPatchMetdata property, which indicates whether custom actions can be skipped when applying the patch. |
9 | /// </summary> | 9 | /// </summary> |
10 | [Flags] | 10 | [Flags] |
11 | internal enum OptimizeCA | 11 | public enum OptimizeCA // TODO: review where to place this data so it can not be exposed by WixToolset.Core |
12 | { | 12 | { |
13 | /// <summary> | 13 | /// <summary> |
14 | /// No custom actions are skipped. | 14 | /// No custom actions are skipped. |