blob: 3022ba763c8ca93ee79a66bfd44a7b8f7603bf41 (
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
|
// 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.ExtensibilityServices
{
using System;
using System.Diagnostics;
using System.IO;
using WixToolset.Core.Burn.Bundles;
using WixToolset.Core.Burn.Interfaces;
using WixToolset.Data.Symbols;
internal class PayloadHarvester : IPayloadHarvester
{
private static readonly Version EmptyVersion = new Version(0, 0, 0, 0);
/// <inheritdoc />
public bool HarvestStandardInformation(WixBundlePayloadSymbol payload)
{
var filePath = payload.SourceFile?.Path;
if (String.IsNullOrEmpty(filePath))
{
return false;
}
this.UpdatePayloadFileInformation(payload, filePath);
this.UpdatePayloadVersionInformation(payload, filePath);
return true;
}
private void UpdatePayloadFileInformation(WixBundlePayloadSymbol payload, string filePath)
{
var fileInfo = new FileInfo(filePath);
if (null != fileInfo)
{
payload.FileSize = fileInfo.Length;
payload.Hash = BundleHashAlgorithm.Hash(fileInfo);
}
else
{
payload.FileSize = 0;
}
}
private void UpdatePayloadVersionInformation(WixBundlePayloadSymbol payload, string filePath)
{
var versionInfo = FileVersionInfo.GetVersionInfo(filePath);
if (null != versionInfo)
{
var version = versionInfo.ProductVersion;
if (String.IsNullOrEmpty(version))
{
version = versionInfo.FileVersion;
}
if (String.IsNullOrEmpty(version))
{
// Fallback to fixed version info block for the file.
var fixedVersion = new Version(versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart);
if (PayloadHarvester.EmptyVersion != fixedVersion)
{
version = fixedVersion.ToString();
}
}
payload.Description = versionInfo.FileDescription;
payload.DisplayName = versionInfo.ProductName;
payload.Version = version;
}
}
}
}
|