aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Msi/SummaryInformation.cs
blob: 26831731710fc54221feade52b2d77d131170a7d (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// 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.Msi
{
    using System;
    using System.Globalization;
    using System.Text;
    using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
    using WixToolset.Core.Native;

    /// <summary>
    /// Summary information for the MSI files.
    /// </summary>
    internal sealed class SummaryInformation : MsiHandle
    {
        /// <summary>
        /// Summary information properties for transforms.
        /// </summary>
        public enum Transform
        {
            /// <summary>PID_CODEPAGE = code page for the summary information stream</summary>
            CodePage = 1,

            /// <summary>PID_TITLE = typically just "Transform"</summary>
            Title = 2,

            /// <summary>PID_SUBJECT = original subject of target</summary>
            TargetSubject = 3,

            /// <summary>PID_AUTHOR = original manufacturer of target</summary>
            TargetManufacturer = 4,

            /// <summary>PID_KEYWORDS = keywords for the transform, typically including at least "Installer"</summary>
            Keywords = 5,

            /// <summary>PID_COMMENTS = describes what this package does</summary>
            Comments = 6,

            /// <summary>PID_TEMPLATE = target platform;language</summary>
            TargetPlatformAndLanguage = 7,

            /// <summary>PID_LASTAUTHOR = updated platform;language</summary>
            UpdatedPlatformAndLanguage = 8,

            /// <summary>PID_REVNUMBER = {productcode}version;{newproductcode}newversion;upgradecode</summary>
            ProductCodes = 9,

            /// <summary>PID_LASTPRINTED should be null for transforms</summary>
            Reserved11 = 11,

            ///.<summary>PID_CREATE_DTM = the timestamp when the transform was created</summary>
            CreationTime = 12,

            /// <summary>PID_PAGECOUNT = minimum installer version</summary>
            InstallerRequirement = 14,

            /// <summary>PID_CHARCOUNT = validation and error flags</summary>
            ValidationFlags = 16,

            /// <summary>PID_APPNAME = the application that created the transform</summary>
            CreatingApplication = 18,

            /// <summary>PID_SECURITY = whether read-only is enforced; should always be 4 for transforms</summary>
            Security = 19,
        }

        /// <summary>
        /// Summary information properties for patches.
        /// </summary>
        public enum Patch
        {
            /// <summary>PID_CODEPAGE = code page of the summary information stream</summary>
            CodePage = 1,

            /// <summary>PID_TITLE = a brief description of the package type</summary>
            Title = 2,

            /// <summary>PID_SUBJECT = package name</summary>
            PackageName = 3,

            /// <summary>PID_AUTHOR = manufacturer of the patch package</summary>
            Manufacturer = 4,

            /// <summary>PID_KEYWORDS = alternate sources for the patch package</summary>
            Sources = 5,

            /// <summary>PID_COMMENTS = general purpose of the patch package</summary>
            Comments = 6,

            /// <summary>PID_TEMPLATE = semicolon delimited list of ProductCodes</summary>
            ProductCodes = 7,

            /// <summary>PID_LASTAUTHOR = semicolon delimited list of transform names</summary>
            TransformNames = 8,

            /// <summary>PID_REVNUMBER = GUID patch code</summary>
            PatchCode = 9,

            /// <summary>PID_LASTPRINTED should be null for patches</summary>
            Reserved11 = 11,

            /// <summary>PID_PAGECOUNT should be null for patches</summary>
            Reserved14 = 14,

            /// <summary>PID_WORDCOUNT = minimum installer version</summary>
            InstallerRequirement = 15,

            /// <summary>PID_CHARCOUNT should be null for patches</summary>
            Reserved16 = 16,

            /// <summary>PID_SECURITY = read-only attribute of the patch package</summary>
            Security = 19,
        }

        /// <summary>
        /// Summary information values for the InstallerRequirement property.
        /// </summary>
        public enum InstallerRequirement
        {
            /// <summary>Any version of the installer will do</summary>
            Version10 = 1,

            /// <summary>At least 1.2</summary>
            Version12 = 2,

            /// <summary>At least 2.0</summary>
            Version20 = 3,

            /// <summary>At least 3.0</summary>
            Version30 = 4,

            /// <summary>At least 3.1</summary>
            Version31 = 5,
        }

        /// <summary>
        /// Instantiate a new SummaryInformation class from an open database.
        /// </summary>
        /// <param name="db">Database to retrieve summary information from.</param>
        public SummaryInformation(Database db)
        {
            if (null == db)
            {
                throw new ArgumentNullException("db");
            }

            uint handle = 0;
            int error = MsiInterop.MsiGetSummaryInformation(db.Handle, null, 0, ref handle);
            if (0 != error)
            {
                throw new MsiException(error);
            }
            this.Handle = handle;
        }

        /// <summary>
        /// Instantiate a new SummaryInformation class from a database file.
        /// </summary>
        /// <param name="databaseFile">The database file.</param>
        public SummaryInformation(string databaseFile)
        {
            if (null == databaseFile)
            {
                throw new ArgumentNullException("databaseFile");
            }

            uint handle = 0;
            int error = MsiInterop.MsiGetSummaryInformation(0, databaseFile, 0, ref handle);
            if (0 != error)
            {
                throw new MsiException(error);
            }
            this.Handle = handle;
        }

        /// <summary>
        /// Variant types in the summary information table.
        /// </summary>
        private enum VT : uint
        {
            /// <summary>Variant has not been assigned.</summary>
            EMPTY = 0,

            /// <summary>Null variant type.</summary>
            NULL = 1,

            /// <summary>16-bit integer variant type.</summary>
            I2 = 2,

            /// <summary>32-bit integer variant type.</summary>
            I4 = 3,

            /// <summary>String variant type.</summary>
            LPSTR = 30,

            /// <summary>Date time (FILETIME, converted to Variant time) variant type.</summary>
            FILETIME = 64,
        }

        /// <summary>
        /// Gets a summary information property.
        /// </summary>
        /// <param name="index">Index of the summary information property.</param>
        /// <returns>The summary information property.</returns>
        public string GetProperty(int index)
        {
            uint dataType;
            StringBuilder stringValue = new StringBuilder("");
            int bufSize = 0;
            int intValue;
            FILETIME timeValue;
            timeValue.dwHighDateTime = 0;
            timeValue.dwLowDateTime = 0;

            int error = MsiInterop.MsiSummaryInfoGetProperty(this.Handle, index, out dataType, out intValue, ref timeValue, stringValue, ref bufSize);
            if (234 == error)
            {
                stringValue.EnsureCapacity(++bufSize);
                error = MsiInterop.MsiSummaryInfoGetProperty(this.Handle, index, out dataType, out intValue, ref timeValue, stringValue, ref bufSize);
            }

            if (0 != error)
            {
                throw new MsiException(error);
            }

            switch ((VT)dataType)
            {
                case VT.EMPTY:
                    return String.Empty;
                case VT.LPSTR:
                    return stringValue.ToString();
                case VT.I2:
                case VT.I4:
                    return Convert.ToString(intValue, CultureInfo.InvariantCulture);
                case VT.FILETIME:
                    long longFileTime = (((long)timeValue.dwHighDateTime) << 32) | unchecked((uint)timeValue.dwLowDateTime);
                    DateTime dateTime = DateTime.FromFileTime(longFileTime);
                    return dateTime.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
                default:
                    throw new InvalidOperationException();
            }
        }
    }
}