aboutsummaryrefslogtreecommitdiff
path: root/src/api/burn/WixToolset.Mba.Core/VerUtilVersion.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/burn/WixToolset.Mba.Core/VerUtilVersion.cs')
-rw-r--r--src/api/burn/WixToolset.Mba.Core/VerUtilVersion.cs99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/api/burn/WixToolset.Mba.Core/VerUtilVersion.cs b/src/api/burn/WixToolset.Mba.Core/VerUtilVersion.cs
new file mode 100644
index 00000000..7408c26f
--- /dev/null
+++ b/src/api/burn/WixToolset.Mba.Core/VerUtilVersion.cs
@@ -0,0 +1,99 @@
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
3namespace WixToolset.Mba.Core
4{
5 using System;
6 using System.Runtime.InteropServices;
7
8 /// <summary>
9 /// An enhanced implementation of SemVer 2.0.
10 /// </summary>
11 public sealed class VerUtilVersion : IDisposable
12 {
13 internal VerUtilVersion(VerUtil.VersionHandle handle)
14 {
15 this.Handle = handle;
16
17 var pVersion = handle.DangerousGetHandle();
18 var version = (VerUtil.VersionStruct)Marshal.PtrToStructure(pVersion, typeof(VerUtil.VersionStruct));
19 this.Version = Marshal.PtrToStringUni(version.sczVersion);
20 this.Major = version.dwMajor;
21 this.Minor = version.dwMinor;
22 this.Patch = version.dwPatch;
23 this.Revision = version.dwRevision;
24 this.ReleaseLabels = new VerUtilVersionReleaseLabel[version.cReleaseLabels];
25 this.Metadata = VerUtil.VersionStringFromOffset(version.sczVersion, version.cchMetadataOffset);
26 this.IsInvalid = version.fInvalid;
27
28 for (var i = 0; i < version.cReleaseLabels; ++i)
29 {
30 var offset = i * Marshal.SizeOf(typeof(VerUtil.VersionReleaseLabelStruct));
31 var pReleaseLabel = new IntPtr(version.rgReleaseLabels.ToInt64() + offset);
32 this.ReleaseLabels[i] = new VerUtilVersionReleaseLabel(pReleaseLabel, version.sczVersion);
33 }
34 }
35
36 /// <summary>
37 /// String version, which would have stripped the leading 'v'.
38 /// </summary>
39 public string Version { get; private set; }
40
41 /// <summary>
42 /// For version A.B.C.D, Major is A. It is 0 if not specified.
43 /// </summary>
44 public uint Major { get; private set; }
45
46 /// <summary>
47 /// For version A.B.C.D, Minor is B. It is 0 if not specified.
48 /// </summary>
49 public uint Minor { get; private set; }
50
51 /// <summary>
52 /// For version A.B.C.D, Patch is C. It is 0 if not specified.
53 /// </summary>
54 public uint Patch { get; private set; }
55
56 /// <summary>
57 /// For version A.B.C.D, Revision is D. It is 0 if not specified.
58 /// </summary>
59 public uint Revision { get; private set; }
60
61 /// <summary>
62 /// For version X.Y.Z-releaselabels+metadata, ReleaseLabels is the parsed information for releaselabels.
63 /// </summary>
64 public VerUtilVersionReleaseLabel[] ReleaseLabels { get; private set; }
65
66 /// <summary>
67 /// For version X.Y.Z-releaselabels+metadata, Metadata is the rest of the string after +.
68 /// For invalid versions, it is all of the string after the point where it was an invalid string.
69 /// </summary>
70 public string Metadata { get; private set; }
71
72 /// <summary>
73 /// Whether the version conformed to the spec.
74 /// </summary>
75 public bool IsInvalid { get; private set; }
76
77 /// <inheritdoc/>
78 public void Dispose()
79 {
80 if (this.Handle != null)
81 {
82 this.Handle.Dispose();
83 this.Handle = null;
84 }
85 }
86
87 private VerUtil.VersionHandle Handle { get; set; }
88
89 internal VerUtil.VersionHandle GetHandle()
90 {
91 if (this.Handle == null)
92 {
93 throw new ObjectDisposedException(this.Version);
94 }
95
96 return this.Handle;
97 }
98 }
99}