aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/DecompilerCore.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/DecompilerCore.cs')
-rw-r--r--src/WixToolset.Core/DecompilerCore.cs152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/WixToolset.Core/DecompilerCore.cs b/src/WixToolset.Core/DecompilerCore.cs
new file mode 100644
index 00000000..203f2bc4
--- /dev/null
+++ b/src/WixToolset.Core/DecompilerCore.cs
@@ -0,0 +1,152 @@
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
4{
5 using System;
6 using System.Collections;
7 using WixToolset.Data;
8 using WixToolset.Extensibility;
9 using Wix = WixToolset.Data.Serialize;
10
11 /// <summary>
12 /// The base of the decompiler. Holds some variables used by the decompiler and extensions,
13 /// as well as some utility methods.
14 /// </summary>
15 internal class DecompilerCore : IDecompilerCore
16 {
17 private Hashtable elements;
18 private Wix.IParentElement rootElement;
19 private bool showPedanticMessages;
20 private Wix.UI uiElement;
21
22 /// <summary>
23 /// Instantiate a new decompiler core.
24 /// </summary>
25 /// <param name="rootElement">The root element of the decompiled database.</param>
26 /// <param name="messageHandler">The message handler.</param>
27 internal DecompilerCore(Wix.IParentElement rootElement)
28 {
29 this.elements = new Hashtable();
30 this.rootElement = rootElement;
31 }
32
33 /// <summary>
34 /// Gets whether the decompiler core encountered an error while processing.
35 /// </summary>
36 /// <value>Flag if core encountered an error during processing.</value>
37 public bool EncounteredError
38 {
39 get { return Messaging.Instance.EncounteredError; }
40 }
41
42 /// <summary>
43 /// Gets the root element of the decompiled output.
44 /// </summary>
45 /// <value>The root element of the decompiled output.</value>
46 public Wix.IParentElement RootElement
47 {
48 get { return this.rootElement; }
49 }
50
51 /// <summary>
52 /// Gets or sets the option to show pedantic messages.
53 /// </summary>
54 /// <value>The option to show pedantic messages.</value>
55 public bool ShowPedanticMessages
56 {
57 get { return this.showPedanticMessages; }
58 set { this.showPedanticMessages = value; }
59 }
60
61 /// <summary>
62 /// Gets the UI element.
63 /// </summary>
64 /// <value>The UI element.</value>
65 public Wix.UI UIElement
66 {
67 get
68 {
69 if (null == this.uiElement)
70 {
71 this.uiElement = new Wix.UI();
72 this.rootElement.AddChild(this.uiElement);
73 }
74
75 return this.uiElement;
76 }
77 }
78
79 /// <summary>
80 /// Verifies if a filename is a valid short filename.
81 /// </summary>
82 /// <param name="filename">Filename to verify.</param>
83 /// <param name="allowWildcards">true if wildcards are allowed in the filename.</param>
84 /// <returns>True if the filename is a valid short filename</returns>
85 public virtual bool IsValidShortFilename(string filename, bool allowWildcards)
86 {
87 return false;
88 }
89
90 /// <summary>
91 /// Convert an Int32 into a DateTime.
92 /// </summary>
93 /// <param name="value">The Int32 value.</param>
94 /// <returns>The DateTime.</returns>
95 public DateTime ConvertIntegerToDateTime(int value)
96 {
97 int date = value / 65536;
98 int time = value % 65536;
99
100 return new DateTime(1980 + (date / 512), (date % 512) / 32, date % 32, time / 2048, (time % 2048) / 32, (time % 32) * 2);
101 }
102
103 /// <summary>
104 /// Gets the element corresponding to the row it came from.
105 /// </summary>
106 /// <param name="row">The row corresponding to the element.</param>
107 /// <returns>The indexed element.</returns>
108 public Wix.ISchemaElement GetIndexedElement(Row row)
109 {
110 return this.GetIndexedElement(row.TableDefinition.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter));
111 }
112
113 /// <summary>
114 /// Gets the element corresponding to the primary key of the given table.
115 /// </summary>
116 /// <param name="table">The table corresponding to the element.</param>
117 /// <param name="primaryKey">The primary key corresponding to the element.</param>
118 /// <returns>The indexed element.</returns>
119 public Wix.ISchemaElement GetIndexedElement(string table, params string[] primaryKey)
120 {
121 return (Wix.ISchemaElement)this.elements[String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey))];
122 }
123
124 /// <summary>
125 /// Index an element by its corresponding row.
126 /// </summary>
127 /// <param name="row">The row corresponding to the element.</param>
128 /// <param name="element">The element to index.</param>
129 public void IndexElement(Row row, Wix.ISchemaElement element)
130 {
131 this.elements.Add(String.Concat(row.TableDefinition.Name, ':', row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)), element);
132 }
133
134 /// <summary>
135 /// Indicates the decompiler encountered and unexpected table to decompile.
136 /// </summary>
137 /// <param name="table">Unknown decompiled table.</param>
138 public void UnexpectedTable(Table table)
139 {
140 this.OnMessage(WixErrors.TableDecompilationUnimplemented(table.Name));
141 }
142
143 /// <summary>
144 /// Sends a message to the message delegate if there is one.
145 /// </summary>
146 /// <param name="mea">Message event arguments.</param>
147 public void OnMessage(MessageEventArgs e)
148 {
149 Messaging.Instance.OnMessage(e);
150 }
151 }
152}