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
|
// 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.WindowsInstaller.Bind
{
using System;
using System.Globalization;
using System.Linq;
using WixToolset.Data;
using WixToolset.Data.Symbols;
using WixToolset.Extensibility.Services;
/// <summary>
/// Binds the summary information table of a database.
/// </summary>
internal class BindSummaryInfoCommand
{
public BindSummaryInfoCommand(IntermediateSection section, int? summaryInformationCodepage, string productLanguage, IBackendHelper backendHelper, IWixBranding branding)
{
this.Section = section;
this.SummaryInformationCodepage = summaryInformationCodepage;
this.ProductLanguage = productLanguage;
this.BackendHelper = backendHelper;
this.Branding = branding;
}
private IntermediateSection Section { get; }
private int? SummaryInformationCodepage { get; }
private string ProductLanguage { get; }
private IBackendHelper BackendHelper { get; }
private IWixBranding Branding { get; }
/// <summary>
/// Returns a flag indicating if files are compressed by default.
/// </summary>
public bool Compressed { get; private set; }
/// <summary>
/// Returns a flag indicating if uncompressed files use long filenames.
/// </summary>
public bool LongNames { get; private set; }
public int InstallerVersion { get; private set; }
public Platform Platform { get; private set; }
/// <summary>
/// Modularization guid, or null if the output is not a module.
/// </summary>
public string ModularizationSuffix { get; private set; }
public void Execute()
{
this.Compressed = false;
this.LongNames = false;
this.InstallerVersion = 0;
this.ModularizationSuffix = null;
SummaryInformationSymbol summaryInformationCodepageSymbol = null;
SummaryInformationSymbol platformAndLanguageSymbol = null;
var foundCreateDateTime = false;
var foundLastSaveDataTime = false;
var foundCreatingApplication = false;
var foundPackageCode = false;
var now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
foreach (var summaryInformationSymbol in this.Section.Symbols.OfType<SummaryInformationSymbol>())
{
switch (summaryInformationSymbol.PropertyId)
{
case SummaryInformationType.Codepage: // PID_CODEPAGE
summaryInformationCodepageSymbol = summaryInformationSymbol;
break;
case SummaryInformationType.PlatformAndLanguage:
platformAndLanguageSymbol = summaryInformationSymbol;
break;
case SummaryInformationType.PackageCode: // PID_REVNUMBER
foundPackageCode = true;
var packageCode = summaryInformationSymbol.Value;
if (SectionType.Module == this.Section.Type)
{
this.ModularizationSuffix = "." + packageCode.Substring(1, 36).Replace('-', '_');
}
break;
case SummaryInformationType.Created:
foundCreateDateTime = true;
break;
case SummaryInformationType.LastSaved:
foundLastSaveDataTime = true;
break;
case SummaryInformationType.WindowsInstallerVersion:
this.InstallerVersion = summaryInformationSymbol[SummaryInformationSymbolFields.Value].AsNumber();
break;
case SummaryInformationType.WordCount:
if (SectionType.Patch == this.Section.Type)
{
this.LongNames = true;
this.Compressed = true;
}
else
{
var attributes = summaryInformationSymbol[SummaryInformationSymbolFields.Value].AsNumber();
this.LongNames = (0 == (attributes & 1));
this.Compressed = (2 == (attributes & 2));
}
break;
case SummaryInformationType.CreatingApplication: // PID_APPNAME
foundCreatingApplication = true;
break;
}
}
// Ensure the codepage is set properly.
if (summaryInformationCodepageSymbol == null)
{
summaryInformationCodepageSymbol = this.Section.AddSymbol(new SummaryInformationSymbol(null)
{
PropertyId = SummaryInformationType.Codepage
});
}
var codepage = summaryInformationCodepageSymbol.Value;
if (String.IsNullOrEmpty(codepage))
{
codepage = this.SummaryInformationCodepage?.ToString(CultureInfo.InvariantCulture) ?? "1252";
}
summaryInformationCodepageSymbol.Value = this.BackendHelper.GetValidCodePage(codepage, onlyAnsi: true).ToString(CultureInfo.InvariantCulture);
// Ensure the language is set properly and figure out what platform we are targeting.
if (platformAndLanguageSymbol != null)
{
this.Platform = EnsureLanguageAndGetPlatformFromSummaryInformation(platformAndLanguageSymbol, this.ProductLanguage);
}
// Set the revision number (package/patch code) if it should be automatically generated.
if (!foundPackageCode)
{
this.Section.AddSymbol(new SummaryInformationSymbol(null)
{
PropertyId = SummaryInformationType.PackageCode,
Value = this.BackendHelper.CreateGuid(),
});
}
// add a summary information row for the create time/date property if its not already set
if (!foundCreateDateTime)
{
this.Section.AddSymbol(new SummaryInformationSymbol(null)
{
PropertyId = SummaryInformationType.Created,
Value = now,
});
}
// add a summary information row for the last save time/date property if its not already set
if (!foundLastSaveDataTime)
{
this.Section.AddSymbol(new SummaryInformationSymbol(null)
{
PropertyId = SummaryInformationType.LastSaved,
Value = now,
});
}
// add a summary information row for the creating application property if its not already set
if (!foundCreatingApplication)
{
this.Section.AddSymbol(new SummaryInformationSymbol(null)
{
PropertyId = SummaryInformationType.CreatingApplication,
Value = this.Branding.GetCreatingApplication(),
});
}
}
private static Platform EnsureLanguageAndGetPlatformFromSummaryInformation(SummaryInformationSymbol symbol, string language)
{
var value = symbol.Value;
var separatorIndex = value.IndexOf(';');
var platformValue = separatorIndex > 0 ? value.Substring(0, separatorIndex) : value;
// If the language was provided and there was language value after the separator
// (or the separator was absent) then use the provided language.
if (!String.IsNullOrEmpty(language) && (separatorIndex < 0 || separatorIndex + 1 == value.Length))
{
symbol.Value = platformValue + ';' + language;
}
switch (platformValue)
{
case "x64":
return Platform.X64;
case "Arm64":
return Platform.ARM64;
case "Intel":
default:
return Platform.X86;
}
}
}
}
|