diff options
Diffstat (limited to 'src/WixToolset.Mba.Core/VerUtilVersion.cs')
-rw-r--r-- | src/WixToolset.Mba.Core/VerUtilVersion.cs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/WixToolset.Mba.Core/VerUtilVersion.cs b/src/WixToolset.Mba.Core/VerUtilVersion.cs new file mode 100644 index 00000000..2b509a21 --- /dev/null +++ b/src/WixToolset.Mba.Core/VerUtilVersion.cs | |||
@@ -0,0 +1,63 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.Mba.Core | ||
4 | { | ||
5 | using System; | ||
6 | using System.Runtime.InteropServices; | ||
7 | |||
8 | public sealed class VerUtilVersion : IDisposable | ||
9 | { | ||
10 | internal VerUtilVersion(VerUtil.VersionHandle handle) | ||
11 | { | ||
12 | this.Handle = handle; | ||
13 | |||
14 | var pVersion = handle.DangerousGetHandle(); | ||
15 | var version = (VerUtil.VersionStruct)Marshal.PtrToStructure(pVersion, typeof(VerUtil.VersionStruct)); | ||
16 | this.Version = Marshal.PtrToStringUni(version.sczVersion); | ||
17 | this.Major = version.dwMajor; | ||
18 | this.Minor = version.dwMinor; | ||
19 | this.Patch = version.dwPatch; | ||
20 | this.Revision = version.dwRevision; | ||
21 | this.ReleaseLabels = new VerUtilVersionReleaseLabel[version.cReleaseLabels]; | ||
22 | this.Metadata = VerUtil.VersionStringFromOffset(version.sczVersion, version.cchMetadataOffset); | ||
23 | this.IsInvalid = version.fInvalid; | ||
24 | |||
25 | for (var i = 0; i < version.cReleaseLabels; ++i) | ||
26 | { | ||
27 | var offset = i * Marshal.SizeOf(typeof(VerUtil.VersionReleaseLabelStruct)); | ||
28 | var pReleaseLabel = new IntPtr(version.rgReleaseLabels.ToInt64() + offset); | ||
29 | this.ReleaseLabels[i] = new VerUtilVersionReleaseLabel(pReleaseLabel, version.sczVersion); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | public string Version { get; private set; } | ||
34 | public uint Major { get; private set; } | ||
35 | public uint Minor { get; private set; } | ||
36 | public uint Patch { get; private set; } | ||
37 | public uint Revision { get; private set; } | ||
38 | public VerUtilVersionReleaseLabel[] ReleaseLabels { get; private set; } | ||
39 | public string Metadata { get; private set; } | ||
40 | public bool IsInvalid { get; private set; } | ||
41 | |||
42 | public void Dispose() | ||
43 | { | ||
44 | if (this.Handle != null) | ||
45 | { | ||
46 | this.Handle.Dispose(); | ||
47 | this.Handle = null; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | private VerUtil.VersionHandle Handle { get; set; } | ||
52 | |||
53 | internal VerUtil.VersionHandle GetHandle() | ||
54 | { | ||
55 | if (this.Handle == null) | ||
56 | { | ||
57 | throw new ObjectDisposedException(this.Version); | ||
58 | } | ||
59 | |||
60 | return this.Handle; | ||
61 | } | ||
62 | } | ||
63 | } | ||