File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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>
Original file line number Diff line number Diff 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- "\n Winget Version: " + winget . VersionString + "\n " ) ;
30+ "\n Winget Version: " + winget . VersionString +
31+ "\n Is Preview: " + winget . IsPreview + "\n " ) ;
3132
3233 Version winGetVersionObject = connector . Version ;
3334
Original file line number Diff line number Diff 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- "\n Winget Version: " + winget . VersionString + "\n " ) ;
30+ "\n Winget Version: " + winget . VersionString +
31+ "\n Is Preview: " + winget . IsPreview + "\n " ) ;
3132
3233 Version winGetVersionObject = connector . Version ;
3334
You can’t perform that action at this time.
0 commit comments