File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ private void Run()
2727 Console . WriteLine ( "Winget Installed: " + info . WinGetInstalled +
2828 "\n Winget 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 ) ;
You can’t perform that action at this time.
0 commit comments