aboutsummaryrefslogtreecommitdiff
path: root/src/ext/NetFx/wixext/NetFxDecompiler.cs
blob: e30905d11c8e17ff0b632f0e395674e651a13bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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.Extensions
{
#if TODO_CONSIDER_DECOMPILER
    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.Globalization;
    using WixToolset.Data;
    using WixToolset.Extensibility;
    using NetFx = WixToolset.Extensions.Serialize.NetFx;
    using Wix = WixToolset.Data.Serialize;

    /// <summary>
    /// The decompiler for the WiX Toolset .NET Framework Extension.
    /// </summary>
    public sealed class NetFxDecompiler : DecompilerExtension
    {
        /// <summary>
        /// Creates a decompiler for NetFx Extension.
        /// </summary>
        public NetFxDecompiler()
        {
            this.TableDefinitions = NetFxExtensionData.GetExtensionTableDefinitions();
        }

        /// <summary>
        /// Get the extensions library to be removed.
        /// </summary>
        /// <param name="tableDefinitions">Table definitions for library.</param>
        /// <returns>Library to remove from decompiled output.</returns>
        public override Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions)
        {
            return NetFxExtensionData.GetExtensionLibrary(tableDefinitions);
        }

        /// <summary>
        /// Decompiles an extension table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        public override void DecompileTable(Table table)
        {
            switch (table.Name)
            {
                case "NetFxNativeImage":
                    this.DecompileNetFxNativeImageTable(table);
                    break;
                default:
                    base.DecompileTable(table);
                    break;
            }
        }

        /// <summary>
        /// Decompile the NetFxNativeImage table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileNetFxNativeImageTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                NetFx.NativeImage nativeImage = new NetFx.NativeImage();

                nativeImage.Id = (string)row[0];

                switch ((int)row[2])
                {
                    case 0:
                        nativeImage.Priority = NetFx.NativeImage.PriorityType.Item0;
                        break;
                    case 1:
                        nativeImage.Priority = NetFx.NativeImage.PriorityType.Item1;
                        break;
                    case 2:
                        nativeImage.Priority = NetFx.NativeImage.PriorityType.Item2;
                        break;
                    case 3:
                        nativeImage.Priority = NetFx.NativeImage.PriorityType.Item3;
                        break;
                }

                if (null != row[3])
                {
                    int attributes = (int)row[3];

                    if (0x1 == (attributes & 0x1))
                    {
                        nativeImage.Debug = NetFx.YesNoType.yes;
                    }

                    if (0x2 == (attributes & 0x2))
                    {
                        nativeImage.Dependencies = NetFx.YesNoType.no;
                    }

                    if (0x4 == (attributes & 0x4))
                    {
                        nativeImage.Profile = NetFx.YesNoType.yes;
                    }

                    if (0x8 == (attributes & 0x8) && 0x10 == (attributes & 0x10))
                    {
                        nativeImage.Platform = NetFx.NativeImage.PlatformType.all;
                    }
                    else if (0x8 == (attributes & 0x8))
                    {
                        nativeImage.Platform = NetFx.NativeImage.PlatformType.Item32bit;
                    }
                    else if (0x10 == (attributes & 0x10))
                    {
                        nativeImage.Platform = NetFx.NativeImage.PlatformType.Item64bit;
                    }
                }

                if (null != row[4])
                {
                    nativeImage.AssemblyApplication = (string)row[4];
                }

                if (null != row[5])
                {
                    nativeImage.AppBaseDirectory = (string)row[5];
                }

                Wix.File file = (Wix.File)this.Core.GetIndexedElement("File", (string)row[1]);
                if (null != file)
                {
                    file.AddChild(nativeImage);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "File_", (string)row[1], "File"));
                }
            }
        }
    }
#endif
}