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
|
// 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.Dtf.Resources
{
using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
internal class FixedFileVersionInfo
{
public FixedFileVersionInfo()
{
// Set reasonable defaults
this.signature = 0xFEEF04BD;
this.structVersion = 0x00010000; // v1.0
this.FileVersion = new Version(0, 0, 0, 0);
this.ProductVersion = new Version(0, 0, 0, 0);
this.FileFlagsMask = VersionBuildTypes.Debug | VersionBuildTypes.Prerelease;
this.FileFlags = VersionBuildTypes.None;
this.FileOS = VersionFileOS.NT_WINDOWS32;
this.FileType = VersionFileType.Application;
this.FileSubtype = VersionFileSubtype.Unknown;
this.Timestamp = DateTime.MinValue;
}
private uint signature;
private uint structVersion;
public Version FileVersion
{
get
{
return this.fileVersion;
}
set
{
if (value == null)
{
throw new InvalidOperationException();
}
this.fileVersion = value;
}
}
private Version fileVersion;
public Version ProductVersion
{
get
{
return this.productVersion;
}
set
{
if (value == null)
{
throw new InvalidOperationException();
}
this.productVersion = value;
}
}
private Version productVersion;
public VersionBuildTypes FileFlagsMask
{
get { return this.fileFlagsMask; }
set { this.fileFlagsMask = value; }
}
private VersionBuildTypes fileFlagsMask;
public VersionBuildTypes FileFlags
{
get { return this.fileFlags; }
set { this.fileFlags = value; }
}
private VersionBuildTypes fileFlags;
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public VersionFileOS FileOS
{
get { return this.fileOS; }
set { this.fileOS = value; }
}
private VersionFileOS fileOS;
public VersionFileType FileType
{
get { return this.fileType; }
set { this.fileType = value; }
}
private VersionFileType fileType;
public VersionFileSubtype FileSubtype
{
get { return this.fileSubtype; }
set { this.fileSubtype = value; }
}
private VersionFileSubtype fileSubtype;
public DateTime Timestamp
{
get { return this.timestamp; }
set { this.timestamp = value; }
}
private DateTime timestamp;
public void Read(BinaryReader reader)
{
this.signature = reader.ReadUInt32();
this.structVersion = reader.ReadUInt32();
this.fileVersion = UInt64ToVersion(reader.ReadUInt64());
this.productVersion = UInt64ToVersion(reader.ReadUInt64());
this.fileFlagsMask = (VersionBuildTypes) reader.ReadInt32();
this.fileFlags = (VersionBuildTypes) reader.ReadInt32();
this.fileOS = (VersionFileOS) reader.ReadInt32();
this.fileType = (VersionFileType) reader.ReadInt32();
this.fileSubtype = (VersionFileSubtype) reader.ReadInt32();
this.timestamp = UInt64ToDateTime(reader.ReadUInt64());
}
public void Write(BinaryWriter writer)
{
writer.Write(this.signature);
writer.Write(this.structVersion);
writer.Write(VersionToUInt64(this.fileVersion));
writer.Write(VersionToUInt64(this.productVersion));
writer.Write((int) this.fileFlagsMask);
writer.Write((int) this.fileFlags);
writer.Write((int) this.fileOS);
writer.Write((int) this.fileType);
writer.Write((int) this.fileSubtype);
writer.Write(DateTimeToUInt64(this.timestamp));
}
public static explicit operator FixedFileVersionInfo(byte[] bytesValue)
{
FixedFileVersionInfo ffviValue = new FixedFileVersionInfo();
using (BinaryReader reader = new BinaryReader(new MemoryStream(bytesValue, false)))
{
ffviValue.Read(reader);
}
return ffviValue;
}
public static explicit operator byte[](FixedFileVersionInfo ffviValue)
{
const int FFVI_LENGTH = 52;
byte[] bytesValue = new byte[FFVI_LENGTH];
using (BinaryWriter writer = new BinaryWriter(new MemoryStream(bytesValue, true)))
{
ffviValue.Write(writer);
}
return bytesValue;
}
private static Version UInt64ToVersion(ulong version)
{
return new Version((int) ((version >> 16) & 0xFFFF), (int) (version & 0xFFFF), (int) (version >> 48), (int) ((version >> 32) & 0xFFFF));
}
private static ulong VersionToUInt64(Version version)
{
return (((ulong) (ushort) version.Major) << 16) | ((ulong) (ushort) version.Minor)
| (((ulong) (ushort) version.Build) << 48) | (((ulong) (ushort) version.Revision) << 32);
}
private static DateTime UInt64ToDateTime(ulong dateTime)
{
return (dateTime == 0 ? DateTime.MinValue : DateTime.FromFileTime((long) dateTime));
}
private static ulong DateTimeToUInt64(DateTime dateTime)
{
return (dateTime == DateTime.MinValue ? 0 : (ulong) dateTime.ToFileTime());
}
}
}
|