Skip to content

Commit 3f2110c

Browse files
committed
Added a property to check if winget is a preview version or not
1 parent ee58534 commit 3f2110c

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

src/WGet.NET/Components/WinGet.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class WinGet
3434
private DateTime _wingetExeModificationDate;
3535
private string _versionString;
3636
private Version _version;
37+
private bool _isPreview;
3738

3839
private readonly bool _administratorPrivileges;
3940

@@ -61,6 +62,27 @@ public bool IsInstalled
6162
}
6263
}
6364

65+
/// <summary>
66+
/// Gets if the version of winget is a preview version.
67+
/// </summary>
68+
/// <returns>
69+
/// <see langword="true"/> if the winget version is a preview version or <see langword="false"/> if not.
70+
/// </returns>
71+
public bool IsPreview
72+
{
73+
get
74+
{
75+
// Check if winget got modefied or removed while the application is running.
76+
if (_wingetExeModificationDate != GetLastModificationData())
77+
{
78+
// Re-query installation if a change was detected.
79+
QueryInstallation();
80+
}
81+
82+
return _isPreview;
83+
}
84+
}
85+
6486
/// <summary>
6587
/// Gets the version number of the winget installation.
6688
/// </summary>
@@ -919,6 +941,8 @@ private bool QueryInstallation()
919941

920942
_version = VersionParser.Parse(_versionString);
921943

944+
_isPreview = VersionParser.CheckPreviewStatus(_versionString);
945+
922946
return isInstalled;
923947
}
924948

src/WGet.NET/Parser/VersionParser.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ namespace WGetNET.Parser
1212
/// </summary>
1313
internal static class VersionParser
1414
{
15+
/// <summary>
16+
/// Checks is the version <see cref="string"/> is a preview version.
17+
/// </summary>
18+
/// <param name="input">The <see cref="string"/> to check.</param>
19+
/// <returns>
20+
/// <see langword="true"/> if the winget version is a preview version or <see langword="false"/> if not.
21+
/// </returns>
22+
public static bool CheckPreviewStatus(string input)
23+
{
24+
if (string.IsNullOrWhiteSpace(input) || input.Length < 7)
25+
{
26+
// Return if the string is null, empty or to short for a preview version
27+
return false;
28+
}
29+
30+
if (input.EndsWith("PREVIEW", StringComparison.OrdinalIgnoreCase))
31+
{
32+
return true;
33+
}
34+
35+
return false;
36+
}
37+
1538
/// <summary>
1639
/// Parses a <see cref="string"/> to a <see cref="Version"/> instance as best as possible.
1740
/// </summary>

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

Lines changed: 17 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ private void Run()
2727
WinGetSourceManager sourceManager = new WinGetSourceManager();
2828
WinGet winget = new WinGet();
2929
Console.WriteLine("Winget Installed: " + winget.IsInstalled +
30-
"\nWinget Version: " + winget.VersionString + "\n");
30+
"\nWinget Version: " + winget.VersionString +
31+
"\nIs Preview: " + winget.IsPreview + "\n");
3132

3233
Version winGetVersionObject = connector.Version;
3334

src/WGetTestLegacySupport/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ private void Run()
2727
WinGetSourceManager sourceManager = new WinGetSourceManager();
2828
WinGet winget = new WinGet();
2929
Console.WriteLine("Winget Installed: " + winget.IsInstalled +
30-
"\nWinget Version: " + winget.VersionString + "\n");
30+
"\nWinget Version: " + winget.VersionString +
31+
"\nIs Preview: " + winget.IsPreview + "\n");
3132

3233
Version winGetVersionObject = connector.Version;
3334

0 commit comments

Comments
 (0)