Skip to content

Commit 674db12

Browse files
committed
Added the functionality to get a version class object containing the winget version information
1 parent 395876d commit 674db12

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/WGet.NET/Components/WinGetInfo.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ public string WinGetVersion
5151
}
5252
}
5353

54+
/// <summary>
55+
/// Gets the version number of the winget installation.
56+
/// </summary>
57+
/// <returns>
58+
/// A <see cref="System.Version"/> object.
59+
/// </returns>
60+
public Version WinGetVersionObject
61+
{
62+
get
63+
{
64+
return GetVersionObject();
65+
}
66+
}
67+
5468
/// <summary>
5569
/// Initializes a new instance of the <see cref="WGetNET.WinGetInfo"/> class.
5670
/// </summary>
@@ -227,5 +241,35 @@ private string CheckWinGetVersion()
227241

228242
return string.Empty;
229243
}
244+
245+
private Version GetVersionObject()
246+
{
247+
string versionString = CheckWinGetVersion();
248+
249+
//Remove the first letter from the version string.
250+
if (versionString.StartsWith('v'))
251+
{
252+
versionString = versionString[1..];
253+
}
254+
255+
//Remove text from the end of the version string.
256+
for (int i = 0; i < versionString.Length; i++)
257+
{
258+
if (versionString[i] == '-')
259+
{
260+
versionString = versionString[0..i];
261+
break;
262+
}
263+
}
264+
265+
Version? versionObject;
266+
267+
if (!Version.TryParse(versionString, out versionObject) || versionObject == null)
268+
{
269+
versionObject = Version.Parse("0.0.0");
270+
}
271+
272+
return versionObject;
273+
}
230274
}
231275
}

src/WGet.NET/XmlDocumentation/WGet.NET.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WGetTest/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ private void Run()
2727
Console.WriteLine("Winget Installed: " + info.WinGetInstalled +
2828
"\nWinget Version: " + info.WinGetVersion + "\n");
2929

30+
Version winGetVersionObject = connector.WinGetVersionObject;
31+
3032
//---Tests-----------------------------------------------------------------------------
3133
List<WinGetPackage> test = connector.SearchPackage("visualstudio");
3234
Console.WriteLine(test[3].PackageName);

0 commit comments

Comments
 (0)