aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Unbinder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Unbinder.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Unbinder.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Unbinder.cs b/src/WixToolset.Core.WindowsInstaller/Unbinder.cs
new file mode 100644
index 00000000..d2d27d45
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Unbinder.cs
@@ -0,0 +1,88 @@
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.Collections;
6 using System.IO;
7 using WixToolset.Data;
8 using WixToolset.Extensibility;
9 using System.Collections.Generic;
10
11 /// <summary>
12 /// Unbinder core of the WiX toolset.
13 /// </summary>
14 public sealed class Unbinder
15 {
16 public IEnumerable<IBackendFactory> BackendFactories { get; }
17
18 /// <summary>
19 /// Gets or sets whether the input msi is an admin image.
20 /// </summary>
21 /// <value>Set to true if the input msi is part of an admin image.</value>
22 public bool IsAdminImage { get; set; }
23
24 /// <summary>
25 /// Gets or sets the option to suppress demodularizing values.
26 /// </summary>
27 /// <value>The option to suppress demodularizing values.</value>
28 public bool SuppressDemodularization { get; set; }
29
30 /// <summary>
31 /// Gets or sets the option to suppress extracting cabinets.
32 /// </summary>
33 /// <value>The option to suppress extracting cabinets.</value>
34 public bool SuppressExtractCabinets { get; set; }
35
36 /// <summary>
37 /// Gets or sets the temporary path for the Binder. If left null, the binder
38 /// will use %TEMP% environment variable.
39 /// </summary>
40 /// <value>Path to temp files.</value>
41 public string TempFilesLocation => Path.GetTempPath();
42
43 /// <summary>
44 /// Unbind a Windows Installer file.
45 /// </summary>
46 /// <param name="file">The Windows Installer file.</param>
47 /// <param name="outputType">The type of output to create.</param>
48 /// <param name="exportBasePath">The path where files should be exported.</param>
49 /// <returns>The output representing the database.</returns>
50 public Intermediate Unbind(string file, OutputType outputType, string exportBasePath)
51 {
52 if (!File.Exists(file))
53 {
54 if (OutputType.Transform == outputType)
55 {
56 throw new WixException(WixErrors.FileNotFound(null, file, "Transform"));
57 }
58 else
59 {
60 throw new WixException(WixErrors.FileNotFound(null, file, "Database"));
61 }
62 }
63
64 // if we don't have the temporary files object yet, get one
65 Directory.CreateDirectory(this.TempFilesLocation); // ensure the base path is there
66
67 var context = new UnbindContext();
68 context.InputFilePath = file;
69 context.ExportBasePath = exportBasePath;
70 context.IntermediateFolder = this.TempFilesLocation;
71 context.IsAdminImage = this.IsAdminImage;
72 context.SuppressDemodularization = this.SuppressDemodularization;
73 context.SuppressExtractCabinets = this.SuppressExtractCabinets;
74
75 foreach (var factory in this.BackendFactories)
76 {
77 if (factory.TryCreateBackend(outputType.ToString(), file, null, out var backend))
78 {
79 return backend.Unbind(context);
80 }
81 }
82
83 // TODO: Display message that could not find a unbinder for output type?
84
85 return null;
86 }
87 }
88}