aboutsummaryrefslogtreecommitdiff
path: root/src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2024-03-06 14:48:10 -0800
committerRob Mensching <rob@firegiant.com>2024-03-07 10:55:57 -0800
commit3d2d46f62fc01e2653d0251ad9703090574e7c41 (patch)
treeffdf7dce6c646f38b5e3ad8325c2ce78ca891a1a /src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs
parenta8504dc4eb1c2d09965b0858699ac737336ef3c1 (diff)
downloadwix-3d2d46f62fc01e2653d0251ad9703090574e7c41.tar.gz
wix-3d2d46f62fc01e2653d0251ad9703090574e7c41.tar.bz2
wix-3d2d46f62fc01e2653d0251ad9703090574e7c41.zip
Better .nupkg names
Diffstat (limited to 'src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs')
-rw-r--r--src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs
new file mode 100644
index 00000000..65b195a4
--- /dev/null
+++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/VerUtilVersion.cs
@@ -0,0 +1,129 @@
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.BootstrapperApplicationApi
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.Prefix = version.chPrefix;
21 this.Major = version.dwMajor;
22 this.Minor = version.dwMinor;
23 this.Patch = version.dwPatch;
24 this.Revision = version.dwRevision;
25 this.ReleaseLabels = new VerUtilVersionReleaseLabel[version.cReleaseLabels];
26 this.Metadata = VerUtil.VersionStringFromOffset(version.sczVersion, version.cchMetadataOffset);
27 this.IsInvalid = version.fInvalid;
28 this.HasMajor = version.fHasMajor;
29 this.HasMinor = version.fHasMinor;
30 this.HasPatch = version.fHasPatch;
31 this.HasRevision = version.fHasRevision;
32
33 for (var i = 0; i < version.cReleaseLabels; ++i)
34 {
35 var offset = i * Marshal.SizeOf(typeof(VerUtil.VersionReleaseLabelStruct));
36 var pReleaseLabel = new IntPtr(version.rgReleaseLabels.ToInt64() + offset);
37 this.ReleaseLabels[i] = new VerUtilVersionReleaseLabel(pReleaseLabel, version.sczVersion);
38 }
39 }
40
41 /// <summary>
42 /// String version, which would have stripped the leading 'v'.
43 /// </summary>
44 public string Version { get; private set; }
45
46 /// <summary>
47 /// Prefix character that was stripped from <c>Version</c>, or the null character if there was no prefix.
48 /// </summary>
49 public char Prefix { get; private set; }
50
51 /// <summary>
52 /// For version A.B.C.D, Major is A. It is 0 if not specified.
53 /// </summary>
54 public uint Major { get; private set; }
55
56 /// <summary>
57 /// For version A.B.C.D, Minor is B. It is 0 if not specified.
58 /// </summary>
59 public uint Minor { get; private set; }
60
61 /// <summary>
62 /// For version A.B.C.D, Patch is C. It is 0 if not specified.
63 /// </summary>
64 public uint Patch { get; private set; }
65
66 /// <summary>
67 /// For version A.B.C.D, Revision is D. It is 0 if not specified.
68 /// </summary>
69 public uint Revision { get; private set; }
70
71 /// <summary>
72 /// For version X.Y.Z-releaselabels+metadata, ReleaseLabels is the parsed information for releaselabels.
73 /// </summary>
74 public VerUtilVersionReleaseLabel[] ReleaseLabels { get; private set; }
75
76 /// <summary>
77 /// For version X.Y.Z-releaselabels+metadata, Metadata is the rest of the string after +.
78 /// For invalid versions, it is all of the string after the point where it was an invalid string.
79 /// </summary>
80 public string Metadata { get; private set; }
81
82 /// <summary>
83 /// Whether the version conformed to the spec.
84 /// </summary>
85 public bool IsInvalid { get; private set; }
86
87 /// <summary>
88 /// Whether the Major part was specified.
89 /// </summary>
90 public bool HasMajor { get; private set; }
91
92 /// <summary>
93 /// Whether the Minor part was specified.
94 /// </summary>
95 public bool HasMinor { get; private set; }
96
97 /// <summary>
98 /// Whether the Patch part was specified.
99 /// </summary>
100 public bool HasPatch { get; private set; }
101
102 /// <summary>
103 /// Whether the Revision part was specified.
104 /// </summary>
105 public bool HasRevision { get; private set; }
106
107 /// <inheritdoc/>
108 public void Dispose()
109 {
110 if (this.Handle != null)
111 {
112 this.Handle.Dispose();
113 this.Handle = null;
114 }
115 }
116
117 private VerUtil.VersionHandle Handle { get; set; }
118
119 internal VerUtil.VersionHandle GetHandle()
120 {
121 if (this.Handle == null)
122 {
123 throw new ObjectDisposedException(this.Version);
124 }
125
126 return this.Handle;
127 }
128 }
129}