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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
// 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.Core.Native.Msi
{
using System;
using System.Globalization;
using System.Text;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
/// <summary>
/// Summary information for the MSI files.
/// </summary>
public sealed class SummaryInformation : MsiHandle
{
/// <summary>
/// Summary information properties for products.
/// </summary>
public enum Package
{
/// <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 = list of keywords used by file browser</summary>
Keywords = 5,
/// <summary>PID_COMMENTS = general purpose of the package</summary>
Comments = 6,
/// <summary>PID_TEMPLATE = supported platforms and languages</summary>
PlatformsAndLanguages = 7,
/// <summary>PID_LASTAUTHOR should be null for packages</summary>
Reserved8 = 8,
/// <summary>PID_REVNUMBER = GUID package code</summary>
PackageCode = 9,
/// <summary>PID_LASTPRINTED should be null for packages</summary>
Reserved11 = 11,
/// <summary>PID_CREATED datetime when package was created</summary>
Created = 12,
/// <summary>PID_SAVED datetime when package was last modified</summary>
LastModified = 13,
/// <summary>PID_PAGECOUNT minimum required Windows Installer</summary>
InstallerRequirement = 14,
/// <summary>PID_WORDCOUNT elevation privileges of package</summary>
FileAndElevatedFlags = 15,
/// <summary>PID_CHARCOUNT should be null for patches</summary>
Reserved16 = 16,
/// <summary>PID_APPLICATION tool used to create package</summary>
BuildTool = 18,
/// <summary>PID_SECURITY = read-only attribute of the package</summary>
Security = 19,
}
/// <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(nameof(db));
}
uint handle = 0;
var 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(nameof(databaseFile));
}
uint handle = 0;
var error = MsiInterop.MsiGetSummaryInformation(0, databaseFile, 0, ref handle);
if (0 != error)
{
throw new MsiException(error);
}
this.Handle = handle;
}
/// <summary>
/// Gets a summary information package property.
/// </summary>
/// <param name="property">The summary information package property.</param>
/// <returns>The summary information property.</returns>
public string GetProperty(Package property)
{
return this.GetProperty((int)property);
}
/// <summary>
/// Gets a summary information package property as a number.
/// </summary>
/// <param name="property">The summary information package property.</param>
/// <returns>The summary information property.</returns>
public long GetNumericProperty(Package property)
{
return this.GetNumericProperty((int)property);
}
/// <summary>
/// Gets a summary information patch property.
/// </summary>
/// <param name="property">The summary information patch property.</param>
/// <returns>The summary information property.</returns>
public string GetProperty(Patch property)
{
return this.GetProperty((int)property);
}
/// <summary>
/// Gets a summary information transform property.
/// </summary>
/// <param name="property">The summary information transform property.</param>
/// <returns>The summary information property.</returns>
public long GetNumericProperty(Transform property)
{
return this.GetNumericProperty((int)property);
}
/// <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)
{
this.GetSummaryInformationValue(index, out var dataType, out var intValue, out var stringValue, out var timeValue);
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:
var longFileTime = (((long)timeValue.dwHighDateTime) << 32) | unchecked((uint)timeValue.dwLowDateTime);
var dateTime = DateTime.FromFileTime(longFileTime);
return dateTime.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
default:
throw new InvalidOperationException();
}
}
/// <summary>
/// Gets a summary information property as a number.
/// </summary>
/// <param name="index">Index of the summary information property.</param>
/// <returns>The summary information property.</returns>
public long GetNumericProperty(int index)
{
this.GetSummaryInformationValue(index, out var dataType, out var intValue, out var stringValue, out var timeValue);
switch ((VT)dataType)
{
case VT.EMPTY:
return 0;
case VT.LPSTR:
return Int64.Parse(stringValue.ToString(), CultureInfo.InvariantCulture);
case VT.I2:
case VT.I4:
return intValue;
case VT.FILETIME:
return (((long)timeValue.dwHighDateTime) << 32) | unchecked((uint)timeValue.dwLowDateTime);
default:
throw new InvalidOperationException();
}
}
private void GetSummaryInformationValue(int index, out uint dataType, out int intValue, out StringBuilder stringValue, out FILETIME timeValue)
{
var bufSize = 64;
stringValue = new StringBuilder(bufSize);
timeValue.dwHighDateTime = 0;
timeValue.dwLowDateTime = 0;
var 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);
}
}
/// <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,
}
}
}
|