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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
// 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.Burn.Bundles
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using WixToolset.Data;
using WixToolset.Extensibility;
using Dtf = WixToolset.Dtf.WindowsInstaller;
using WixToolset.Extensibility.Services;
using WixToolset.Data.Symbols;
using WixToolset.Data.WindowsInstaller;
using WixToolset.Extensibility.Data;
/// <summary>
/// Initializes package state from the MSI contents.
/// </summary>
internal class ProcessMsiPackageCommand
{
private const string PropertySqlFormat = "SELECT `Value` FROM `Property` WHERE `Property` = '{0}'";
public ProcessMsiPackageCommand(IWixToolsetServiceProvider serviceProvider, IEnumerable<IBurnBackendExtension> backendExtensions, IntermediateSection section, PackageFacade facade, Dictionary<string, WixBundlePayloadSymbol> payloadSymbols)
{
this.Messaging = serviceProvider.GetService<IMessaging>();
this.BackendHelper = serviceProvider.GetService<IBackendHelper>();
this.PathResolver = serviceProvider.GetService<IPathResolver>();
this.BackendExtensions = backendExtensions;
this.AuthoredPayloads = payloadSymbols;
this.Section = section;
this.Facade = facade;
}
private IMessaging Messaging { get; }
private IBackendHelper BackendHelper { get; }
private IPathResolver PathResolver { get; }
private IEnumerable<IBurnBackendExtension> BackendExtensions { get; }
private Dictionary<string, WixBundlePayloadSymbol> AuthoredPayloads { get; }
private PackageFacade Facade { get; }
private IntermediateSection Section { get; }
/// <summary>
/// Processes the MSI packages to add properties and payloads from the MSI packages.
/// </summary>
public void Execute()
{
var packagePayload = this.AuthoredPayloads[this.Facade.PackageSymbol.PayloadRef];
var msiPackage = (WixBundleMsiPackageSymbol)this.Facade.SpecificPackageSymbol;
var sourcePath = packagePayload.SourceFile.Path;
var longNamesInImage = false;
var compressed = false;
try
{
// Read data out of the msi database...
using (var sumInfo = new Dtf.SummaryInfo(sourcePath, false))
{
// 1 is the Word Count summary information stream bit that means
// the MSI uses short file names when set. We care about long file
// names so check when the bit is not set.
longNamesInImage = 0 == (sumInfo.WordCount & 1);
// 2 is the Word Count summary information stream bit that means
// files are compressed in the MSI by default when the bit is set.
compressed = 2 == (sumInfo.WordCount & 2);
// 8 is the Word Count summary information stream bit that means
// "Elevated privileges are not required to install this package."
// in MSI 4.5 and below, if this bit is 0, elevation is required.
var perMachine = (0 == (sumInfo.WordCount & 8));
var x64 = sumInfo.Template.Contains("x64");
this.Facade.PackageSymbol.PerMachine = perMachine ? YesNoDefaultType.Yes : YesNoDefaultType.No;
this.Facade.PackageSymbol.Win64 = x64;
}
using (var db = new Dtf.Database(sourcePath))
{
msiPackage.ProductCode = ProcessMsiPackageCommand.GetProperty(db, "ProductCode");
msiPackage.UpgradeCode = ProcessMsiPackageCommand.GetProperty(db, "UpgradeCode");
msiPackage.Manufacturer = ProcessMsiPackageCommand.GetProperty(db, "Manufacturer");
msiPackage.ProductLanguage = Convert.ToInt32(ProcessMsiPackageCommand.GetProperty(db, "ProductLanguage"), CultureInfo.InvariantCulture);
msiPackage.ProductVersion = ProcessMsiPackageCommand.GetProperty(db, "ProductVersion");
if (!Common.IsValidModuleOrBundleVersion(msiPackage.ProductVersion))
{
// not a proper .NET version (e.g., five fields); can we get a valid four-part version number?
string version = null;
string[] versionParts = msiPackage.ProductVersion.Split('.');
var count = versionParts.Length;
if (0 < count)
{
version = versionParts[0];
for (var i = 1; i < 4 && i < count; ++i)
{
version = String.Concat(version, ".", versionParts[i]);
}
}
if (!String.IsNullOrEmpty(version) && Common.IsValidModuleOrBundleVersion(version))
{
this.Messaging.Write(WarningMessages.VersionTruncated(this.Facade.PackageSymbol.SourceLineNumbers, msiPackage.ProductVersion, sourcePath, version));
msiPackage.ProductVersion = version;
}
else
{
this.Messaging.Write(ErrorMessages.InvalidProductVersion(this.Facade.PackageSymbol.SourceLineNumbers, msiPackage.ProductVersion, sourcePath));
}
}
if (String.IsNullOrEmpty(this.Facade.PackageSymbol.CacheId))
{
this.Facade.PackageSymbol.CacheId = String.Format("{0}v{1}", msiPackage.ProductCode, msiPackage.ProductVersion);
}
if (String.IsNullOrEmpty(this.Facade.PackageSymbol.DisplayName))
{
this.Facade.PackageSymbol.DisplayName = ProcessMsiPackageCommand.GetProperty(db, "ProductName");
}
if (String.IsNullOrEmpty(this.Facade.PackageSymbol.Description))
{
this.Facade.PackageSymbol.Description = ProcessMsiPackageCommand.GetProperty(db, "ARPCOMMENTS");
}
if (String.IsNullOrEmpty(this.Facade.PackageSymbol.Version))
{
this.Facade.PackageSymbol.Version = msiPackage.ProductVersion;
}
var payloadNames = this.GetPayloadTargetNames(packagePayload.Id.Id);
var msiPropertyNames = this.GetMsiPropertyNames(packagePayload.Id.Id);
this.SetPerMachineAppropriately(db, msiPackage, sourcePath);
// Ensure the MSI package is appropriately marked visible or not.
this.SetPackageVisibility(db, msiPackage, msiPropertyNames);
// Unless the MSI or setup code overrides the default, set MSIFASTINSTALL for best performance.
if (!msiPropertyNames.Contains("MSIFASTINSTALL") && !ProcessMsiPackageCommand.HasProperty(db, "MSIFASTINSTALL"))
{
this.AddMsiProperty(msiPackage, "MSIFASTINSTALL", "7");
}
this.CreateRelatedPackages(db);
// If feature selection is enabled, represent the Feature table in the manifest.
if ((msiPackage.Attributes & WixBundleMsiPackageAttributes.EnableFeatureSelection) == WixBundleMsiPackageAttributes.EnableFeatureSelection)
{
this.CreateMsiFeatures(db);
}
// Add all external cabinets as package payloads.
this.ImportExternalCabinetAsPayloads(db, packagePayload, payloadNames);
// Add all external files as package payloads and calculate the total install size as the rollup of
// File table's sizes.
this.Facade.PackageSymbol.InstallSize = this.ImportExternalFileAsPayloadsAndReturnInstallSize(db, packagePayload, longNamesInImage, compressed, payloadNames);
// Add all dependency providers from the MSI.
this.ImportDependencyProviders(msiPackage, db);
}
}
catch (Dtf.InstallerException e)
{
this.Messaging.Write(ErrorMessages.UnableToReadPackageInformation(this.Facade.PackageSymbol.SourceLineNumbers, sourcePath, e.Message));
}
}
private ISet<string> GetPayloadTargetNames(string packageId)
{
var payloadNames = this.Section.Symbols.OfType<WixBundlePayloadSymbol>()
.Where(p => p.PackageRef == packageId)
.Select(p => p.Name);
return new HashSet<string>(payloadNames, StringComparer.OrdinalIgnoreCase);
}
private ISet<string> GetMsiPropertyNames(string packageId)
{
var properties = this.Section.Symbols.OfType<WixBundleMsiPropertySymbol>()
.Where(p => p.Id.Id == packageId)
.Select(p => p.Name);
return new HashSet<string>(properties, StringComparer.Ordinal);
}
private void SetPerMachineAppropriately(Dtf.Database db, WixBundleMsiPackageSymbol msiPackage, string sourcePath)
{
if (msiPackage.ForcePerMachine)
{
if (YesNoDefaultType.No == this.Facade.PackageSymbol.PerMachine)
{
this.Messaging.Write(WarningMessages.PerUserButForcingPerMachine(this.Facade.PackageSymbol.SourceLineNumbers, sourcePath));
this.Facade.PackageSymbol.PerMachine = YesNoDefaultType.Yes; // ensure that we think the package is per-machine.
}
// Force ALLUSERS=1 via the MSI command-line.
this.AddMsiProperty(msiPackage, "ALLUSERS", "1");
}
else
{
var allusers = ProcessMsiPackageCommand.GetProperty(db, "ALLUSERS");
if (String.IsNullOrEmpty(allusers))
{
// Not forced per-machine and no ALLUSERS property, flip back to per-user.
if (YesNoDefaultType.Yes == this.Facade.PackageSymbol.PerMachine)
{
this.Messaging.Write(WarningMessages.ImplicitlyPerUser(this.Facade.PackageSymbol.SourceLineNumbers, sourcePath));
this.Facade.PackageSymbol.PerMachine = YesNoDefaultType.No;
}
}
else if (allusers.Equals("1", StringComparison.Ordinal))
{
if (YesNoDefaultType.No == this.Facade.PackageSymbol.PerMachine)
{
this.Messaging.Write(ErrorMessages.PerUserButAllUsersEquals1(this.Facade.PackageSymbol.SourceLineNumbers, sourcePath));
}
}
else if (allusers.Equals("2", StringComparison.Ordinal))
{
this.Messaging.Write(WarningMessages.DiscouragedAllUsersValue(this.Facade.PackageSymbol.SourceLineNumbers, sourcePath, (YesNoDefaultType.Yes == this.Facade.PackageSymbol.PerMachine) ? "machine" : "user"));
}
else
{
this.Messaging.Write(ErrorMessages.UnsupportedAllUsersValue(this.Facade.PackageSymbol.SourceLineNumbers, sourcePath, allusers));
}
}
}
private void SetPackageVisibility(Dtf.Database db, WixBundleMsiPackageSymbol msiPackage, ISet<string> msiPropertyNames)
{
var alreadyVisible = !ProcessMsiPackageCommand.HasProperty(db, "ARPSYSTEMCOMPONENT");
var visible = (this.Facade.PackageSymbol.Attributes & WixBundlePackageAttributes.Visible) == WixBundlePackageAttributes.Visible;
// If not already set to the correct visibility.
if (alreadyVisible != visible)
{
// If the authoring specifically added "ARPSYSTEMCOMPONENT", don't do it again.
if (!msiPropertyNames.Contains("ARPSYSTEMCOMPONENT"))
{
this.AddMsiProperty(msiPackage, "ARPSYSTEMCOMPONENT", visible ? String.Empty : "1");
}
}
}
private void CreateRelatedPackages(Dtf.Database db)
{
// Represent the Upgrade table as related packages.
if (db.Tables.Contains("Upgrade"))
{
using (var view = db.OpenView("SELECT `UpgradeCode`, `VersionMin`, `VersionMax`, `Language`, `Attributes` FROM `Upgrade`"))
{
view.Execute();
while (true)
{
using (var record = view.Fetch())
{
if (null == record)
{
break;
}
var recordAttributes = record.GetInteger(5);
var attributes = WixBundleRelatedPackageAttributes.None;
attributes |= (recordAttributes & WindowsInstallerConstants.MsidbUpgradeAttributesOnlyDetect) == WindowsInstallerConstants.MsidbUpgradeAttributesOnlyDetect ? WixBundleRelatedPackageAttributes.OnlyDetect : 0;
attributes |= (recordAttributes & WindowsInstallerConstants.MsidbUpgradeAttributesVersionMinInclusive) == WindowsInstallerConstants.MsidbUpgradeAttributesVersionMinInclusive ? WixBundleRelatedPackageAttributes.MinInclusive : 0;
attributes |= (recordAttributes & WindowsInstallerConstants.MsidbUpgradeAttributesVersionMaxInclusive) == WindowsInstallerConstants.MsidbUpgradeAttributesVersionMaxInclusive ? WixBundleRelatedPackageAttributes.MaxInclusive : 0;
attributes |= (recordAttributes & WindowsInstallerConstants.MsidbUpgradeAttributesLanguagesExclusive) == WindowsInstallerConstants.MsidbUpgradeAttributesLanguagesExclusive ? WixBundleRelatedPackageAttributes.LangInclusive : 0;
this.Section.AddSymbol(new WixBundleRelatedPackageSymbol(this.Facade.PackageSymbol.SourceLineNumbers)
{
PackageRef = this.Facade.PackageId,
RelatedId = record.GetString(1),
MinVersion = record.GetString(2),
MaxVersion = record.GetString(3),
Languages = record.GetString(4),
Attributes = attributes,
});
}
}
}
}
}
private void CreateMsiFeatures(Dtf.Database db)
{
if (db.Tables.Contains("Feature"))
{
using (var featureView = db.OpenView("SELECT `Component_` FROM `FeatureComponents` WHERE `Feature_` = ?"))
using (var componentView = db.OpenView("SELECT `FileSize` FROM `File` WHERE `Component_` = ?"))
{
using (var featureRecord = new Dtf.Record(1))
using (var componentRecord = new Dtf.Record(1))
{
using (var allFeaturesView = db.OpenView("SELECT * FROM `Feature`"))
{
allFeaturesView.Execute();
while (true)
{
using (var allFeaturesResultRecord = allFeaturesView.Fetch())
{
if (null == allFeaturesResultRecord)
{
break;
}
var featureName = allFeaturesResultRecord.GetString(1);
// Calculate the Feature size.
featureRecord.SetString(1, featureName);
featureView.Execute(featureRecord);
// Loop over all the components for the feature to calculate the size of the feature.
long size = 0;
while (true)
{
using (var componentResultRecord = featureView.Fetch())
{
if (null == componentResultRecord)
{
break;
}
var component = componentResultRecord.GetString(1);
componentRecord.SetString(1, component);
componentView.Execute(componentRecord);
while (true)
{
using (var fileResultRecord = componentView.Fetch())
{
if (null == fileResultRecord)
{
break;
}
var fileSize = fileResultRecord.GetString(1);
size += Convert.ToInt32(fileSize, CultureInfo.InvariantCulture.NumberFormat);
}
}
}
}
this.Section.AddSymbol(new WixBundleMsiFeatureSymbol(this.Facade.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Private, this.Facade.PackageId, featureName))
{
PackageRef = this.Facade.PackageId,
Name = featureName,
Parent = allFeaturesResultRecord.GetString(2),
Title = allFeaturesResultRecord.GetString(3),
Description = allFeaturesResultRecord.GetString(4),
Display = allFeaturesResultRecord.GetInteger(5),
Level = allFeaturesResultRecord.GetInteger(6),
Directory = allFeaturesResultRecord.GetString(7),
Attributes = allFeaturesResultRecord.GetInteger(8),
Size = size
});
}
}
}
}
}
}
}
private void ImportExternalCabinetAsPayloads(Dtf.Database db, WixBundlePayloadSymbol packagePayload, ISet<string> payloadNames)
{
if (db.Tables.Contains("Media"))
{
foreach (var cabinet in db.ExecuteStringQuery("SELECT `Cabinet` FROM `Media`"))
{
if (!String.IsNullOrEmpty(cabinet) && !cabinet.StartsWith("#", StringComparison.Ordinal))
{
// If we didn't find the Payload as an existing child of the package, we need to
// add it. We expect the file to exist on-disk in the same relative location as
// the MSI expects to find it...
var cabinetName = Path.Combine(Path.GetDirectoryName(packagePayload.Name), cabinet);
if (!payloadNames.Contains(cabinetName))
{
var generatedId = Common.GenerateIdentifier("cab", packagePayload.Id.Id, cabinet);
var payloadSourceFile = this.ResolveRelatedFile(packagePayload.SourceFile.Path, packagePayload.UnresolvedSourceFile, cabinet, "Cabinet", this.Facade.PackageSymbol.SourceLineNumbers, BindStage.Normal);
this.Section.AddSymbol(new WixBundlePayloadSymbol(this.Facade.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Private, generatedId))
{
Name = cabinetName,
SourceFile = new IntermediateFieldPathValue { Path = payloadSourceFile },
Compressed = packagePayload.Compressed,
UnresolvedSourceFile = cabinetName,
PackageRef = packagePayload.PackageRef,
ContainerRef = packagePayload.ContainerRef,
ContentFile = true,
EnableSignatureValidation = packagePayload.EnableSignatureValidation,
Packaging = packagePayload.Packaging,
ParentPackagePayloadRef = packagePayload.Id.Id,
});
}
}
}
}
}
private long ImportExternalFileAsPayloadsAndReturnInstallSize(Dtf.Database db, WixBundlePayloadSymbol packagePayload, bool longNamesInImage, bool compressed, ISet<string> payloadNames)
{
long size = 0;
if (db.Tables.Contains("Component") && db.Tables.Contains("Directory") && db.Tables.Contains("File"))
{
var directories = new Dictionary<string, IResolvedDirectory>();
// Load up the directory hash table so we will be able to resolve source paths
// for files in the MSI database.
using (var view = db.OpenView("SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`"))
{
view.Execute();
while (true)
{
using (var record = view.Fetch())
{
if (null == record)
{
break;
}
var sourceName = Common.GetName(record.GetString(3), true, longNamesInImage);
var resolvedDirectory = this.BackendHelper.CreateResolvedDirectory(record.GetString(2), sourceName);
directories.Add(record.GetString(1), resolvedDirectory);
}
}
}
// Resolve the source paths to external files and add each file size to the total
// install size of the package.
using (var view = db.OpenView("SELECT `Directory_`, `File`, `FileName`, `File`.`Attributes`, `FileSize` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_`"))
{
view.Execute();
while (true)
{
using (var record = view.Fetch())
{
if (null == record)
{
break;
}
// If the file is explicitly uncompressed or the MSI is uncompressed and the file is not
// explicitly marked compressed then this is an external file.
var compressionBit = record.GetInteger(4);
if (WindowsInstallerConstants.MsidbFileAttributesNoncompressed == (compressionBit & WindowsInstallerConstants.MsidbFileAttributesNoncompressed) ||
(!compressed && 0 == (compressionBit & WindowsInstallerConstants.MsidbFileAttributesCompressed)))
{
string fileSourcePath = this.PathResolver.GetFileSourcePath(directories, record.GetString(1), record.GetString(3), compressed, longNamesInImage);
var name = Path.Combine(Path.GetDirectoryName(packagePayload.Name), fileSourcePath);
if (!payloadNames.Contains(name))
{
var generatedId = Common.GenerateIdentifier("f", packagePayload.Id.Id, record.GetString(2));
var payloadSourceFile = this.ResolveRelatedFile(packagePayload.SourceFile.Path, packagePayload.UnresolvedSourceFile, fileSourcePath, "File", this.Facade.PackageSymbol.SourceLineNumbers, BindStage.Normal);
this.Section.AddSymbol(new WixBundlePayloadSymbol(this.Facade.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Private, generatedId))
{
Name = name,
SourceFile = new IntermediateFieldPathValue { Path = payloadSourceFile },
Compressed = packagePayload.Compressed,
UnresolvedSourceFile = name,
PackageRef = packagePayload.PackageRef,
ContainerRef = packagePayload.ContainerRef,
ContentFile = true,
EnableSignatureValidation = packagePayload.EnableSignatureValidation,
Packaging = packagePayload.Packaging,
ParentPackagePayloadRef = packagePayload.Id.Id,
});
}
}
size += record.GetInteger(5);
}
}
}
}
return size;
}
private void AddMsiProperty(WixBundleMsiPackageSymbol msiPackage, string name, string value)
{
this.Section.AddSymbol(new WixBundleMsiPropertySymbol(msiPackage.SourceLineNumbers, new Identifier(AccessModifier.Private, msiPackage.Id.Id, name))
{
PackageRef = msiPackage.Id.Id,
Name = name,
Value = value,
});
}
private void ImportDependencyProviders(WixBundleMsiPackageSymbol msiPackage, Dtf.Database db)
{
if (db.Tables.Contains("WixDependencyProvider"))
{
var query = "SELECT `ProviderKey`, `Version`, `DisplayName`, `Attributes` FROM `WixDependencyProvider`";
using (var view = db.OpenView(query))
{
view.Execute();
while (true)
{
using (var record = view.Fetch())
{
if (null == record)
{
break;
}
// Import the provider key and attributes.
this.Section.AddSymbol(new ProvidesDependencySymbol(msiPackage.SourceLineNumbers)
{
PackageRef = msiPackage.Id.Id,
Key = record.GetString(1),
Version = record.GetString(2) ?? msiPackage.ProductVersion,
DisplayName = record.GetString(3) ?? this.Facade.PackageSymbol.DisplayName,
Attributes = record.GetInteger(4),
Imported = true
});
}
}
}
}
}
private string ResolveRelatedFile(string resolvedSource, string unresolvedSource, string relatedSource, string type, SourceLineNumber sourceLineNumbers, BindStage stage)
{
var checkedPaths = new List<string>();
foreach (var extension in this.BackendExtensions)
{
var resolved = extension.ResolveRelatedFile(unresolvedSource, relatedSource, type, sourceLineNumbers, stage);
if (resolved?.CheckedPaths != null)
{
checkedPaths.AddRange(resolved.CheckedPaths);
}
if (!String.IsNullOrEmpty(resolved?.Path))
{
return resolved?.Path;
}
}
var resolvedPath = Path.Combine(Path.GetDirectoryName(resolvedSource), relatedSource);
if (!File.Exists(resolvedPath))
{
checkedPaths.Add(resolvedPath);
this.Messaging.Write(ErrorMessages.FileNotFound(sourceLineNumbers, resolvedPath, type, checkedPaths));
}
return resolvedPath;
}
/// <summary>
/// Queries a Windows Installer database for a Property value.
/// </summary>
/// <param name="db">Database to query.</param>
/// <param name="property">Property to examine.</param>
/// <returns>String value for result or null if query doesn't match a single result.</returns>
private static string GetProperty(Dtf.Database db, string property)
{
try
{
return db.ExecuteScalar(PropertyQuery(property)).ToString();
}
catch (Dtf.InstallerException)
{
}
return null;
}
/// <summary>
/// Queries a Windows Installer database to determine if one or more rows exist in the Property table.
/// </summary>
/// <param name="db">Database to query.</param>
/// <param name="property">Property to examine.</param>
/// <returns>True if query matches at least one result.</returns>
private static bool HasProperty(Dtf.Database db, string property)
{
try
{
return 0 < db.ExecuteQuery(PropertyQuery(property)).Count;
}
catch (Dtf.InstallerException)
{
}
return false;
}
private static string PropertyQuery(string property)
{
// quick sanity check that we'll be creating a valid query...
// TODO: Are there any other special characters we should be looking for?
Debug.Assert(!property.Contains("'"));
return String.Format(CultureInfo.InvariantCulture, ProcessMsiPackageCommand.PropertySqlFormat, property);
}
}
}
|