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.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs | |
| 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.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs b/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs new file mode 100644 index 00000000..130f5ea8 --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.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 | |||
| 3 | namespace WixToolset.Core.WindowsInstaller.Unbind | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.ComponentModel; | ||
| 8 | using System.Xml.Linq; | ||
| 9 | using WixToolset.Core.Native; | ||
| 10 | using WixToolset.Data; | ||
| 11 | using WixToolset.Extensibility; | ||
| 12 | using WixToolset.Extensibility.Data; | ||
| 13 | using WixToolset.Extensibility.Services; | ||
| 14 | using WixToolset.Msi; | ||
| 15 | |||
| 16 | internal class DecompileMsiOrMsmCommand | ||
| 17 | { | ||
| 18 | public DecompileMsiOrMsmCommand(IDecompileContext context, IEnumerable<IWindowsInstallerBackendDecompilerExtension> backendExtensions) | ||
| 19 | { | ||
| 20 | this.Context = context; | ||
| 21 | this.Extensions = backendExtensions; | ||
| 22 | this.Messaging = context.ServiceProvider.GetService<IMessaging>(); | ||
| 23 | } | ||
| 24 | |||
| 25 | private IDecompileContext Context { get; } | ||
| 26 | |||
| 27 | private IEnumerable<IWindowsInstallerBackendDecompilerExtension> Extensions { get; } | ||
| 28 | |||
| 29 | private IMessaging Messaging { get; } | ||
| 30 | |||
| 31 | public DecompileResult Execute() | ||
| 32 | { | ||
| 33 | var result = new DecompileResult(); | ||
| 34 | |||
| 35 | try | ||
| 36 | { | ||
| 37 | using (var database = new Database(this.Context.DecompilePath, OpenDatabase.ReadOnly)) | ||
| 38 | { | ||
| 39 | var unbindCommand = new UnbindDatabaseCommand(this.Messaging, database, this.Context.DecompilePath, this.Context.DecompileType, this.Context.ExtractFolder, this.Context.IntermediateFolder, this.Context.IsAdminImage, false, skipSummaryInfo: false); | ||
| 40 | var output = unbindCommand.Execute(); | ||
| 41 | |||
| 42 | var decompiler = new Decompiler(this.Messaging, this.Extensions, this.Context.BaseSourcePath, this.Context.SuppressCustomTables, this.Context.SuppressDroppingEmptyTables, this.Context.SuppressUI, this.Context.TreatProductAsModule); | ||
| 43 | var wxs = decompiler.Decompile(output); | ||
| 44 | |||
| 45 | wxs.Save(this.Context.OutputPath, SaveOptions.OmitDuplicateNamespaces); | ||
| 46 | result.SourceDocumentPath = this.Context.OutputPath; | ||
| 47 | |||
| 48 | // extract the files from the cabinets | ||
| 49 | if (!String.IsNullOrEmpty(this.Context.ExtractFolder) && !this.Context.SuppressExtractCabinets) | ||
| 50 | { | ||
| 51 | var extractCommand = new ExtractCabinetsCommand(output, database, this.Context.DecompilePath, this.Context.ExtractFolder, this.Context.IntermediateFolder); | ||
| 52 | extractCommand.Execute(); | ||
| 53 | |||
| 54 | result.ExtractedFilePaths = extractCommand.ExtractedFiles; | ||
| 55 | } | ||
| 56 | else | ||
| 57 | { | ||
| 58 | result.ExtractedFilePaths = new string[0]; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | catch (Win32Exception e) | ||
| 63 | { | ||
| 64 | if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED | ||
| 65 | { | ||
| 66 | throw new WixException(ErrorMessages.OpenDatabaseFailed(this.Context.DecompilePath)); | ||
| 67 | } | ||
| 68 | |||
| 69 | throw; | ||
| 70 | } | ||
| 71 | |||
| 72 | return result; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
