// 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.
namespace WixToolset
{
using System;
using System.Collections;
using WixToolset.Data.WindowsInstaller;
using WixToolset.Extensibility;
using Wix = WixToolset.Data.Serialize;
///
/// The base of the decompiler. Holds some variables used by the decompiler and extensions,
/// as well as some utility methods.
///
internal class DecompilerCore
{
private readonly Hashtable elements;
private Wix.UI uiElement;
///
/// Instantiate a new decompiler core.
///
/// The root element of the decompiled database.
/// The message handler.
internal DecompilerCore(Wix.IParentElement rootElement)
{
this.elements = new Hashtable();
this.RootElement = rootElement;
}
///
/// Gets the root element of the decompiled output.
///
/// The root element of the decompiled output.
public Wix.IParentElement RootElement { get; }
///
/// Gets the UI element.
///
/// The UI element.
public Wix.UI UIElement
{
get
{
if (null == this.uiElement)
{
this.uiElement = new Wix.UI();
this.RootElement.AddChild(this.uiElement);
}
return this.uiElement;
}
}
///
/// Verifies if a filename is a valid short filename.
///
/// Filename to verify.
/// true if wildcards are allowed in the filename.
/// True if the filename is a valid short filename
public virtual bool IsValidShortFilename(string filename, bool allowWildcards)
{
return false;
}
///
/// Convert an Int32 into a DateTime.
///
/// The Int32 value.
/// The DateTime.
public DateTime ConvertIntegerToDateTime(int value)
{
var date = value / 65536;
var time = value % 65536;
return new DateTime(1980 + (date / 512), (date % 512) / 32, date % 32, time / 2048, (time % 2048) / 32, (time % 32) * 2);
}
///
/// Gets the element corresponding to the row it came from.
///
/// The row corresponding to the element.
/// The indexed element.
public Wix.ISchemaElement GetIndexedElement(Row row)
{
return this.GetIndexedElement(row.TableDefinition.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter));
}
///
/// Gets the element corresponding to the primary key of the given table.
///
/// The table corresponding to the element.
/// The primary key corresponding to the element.
/// The indexed element.
public Wix.ISchemaElement GetIndexedElement(string table, params string[] primaryKey)
{
return (Wix.ISchemaElement)this.elements[String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey))];
}
///
/// Index an element by its corresponding row.
///
/// The row corresponding to the element.
/// The element to index.
public void IndexElement(Row row, Wix.ISchemaElement element)
{
this.elements.Add(String.Concat(row.TableDefinition.Name, ':', row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)), element);
}
}
}