@@ -64,7 +64,7 @@ public Version Version
6464 {
6565 get
6666 {
67- return GetVersionObject ( ) ;
67+ return VersionParser . Parse ( CheckWinGetVersion ( ) ) ;
6868 }
6969 }
7070
@@ -388,6 +388,12 @@ protected bool CheckWinGetVersion(Version minVersion, Version? maxVersion = null
388388 return false ;
389389 }
390390
391+ /// <summary>
392+ /// Checks the winget version and returns it as a <see cref="System.String"/>.
393+ /// </summary>
394+ /// <returns>
395+ /// A <see cref="System.String"/> containing the winget version.
396+ /// </returns>
391397 private string CheckWinGetVersion ( )
392398 {
393399 try
@@ -398,14 +404,15 @@ private string CheckWinGetVersion()
398404 for ( int i = 0 ; i < result . Output . Length ; i ++ )
399405 {
400406#if NETCOREAPP3_1_OR_GREATER
401- if ( result . Output [ i ] . StartsWith ( 'v' ) )
407+ if ( result . Output [ i ] . StartsWith ( 'v' ) && result . Output [ i ] . Length >= 2 )
402408 {
403- return result . Output [ i ] . Trim ( ) ;
409+ // Return output without the 'v' at the start.
410+ return result . Output [ i ] . Trim ( ) [ 1 .. ] ;
404411 }
405412#elif NETSTANDARD2_0
406- if ( result . Output [ i ] . StartsWith ( "v" ) )
413+ if ( result . Output [ i ] . StartsWith ( "v" ) && result . Output [ i ] . Length >= 2 )
407414 {
408- return result . Output [ i ] . Trim ( ) ;
415+ return result . Output [ i ] . Trim ( ) . Substring ( 1 ) ;
409416 }
410417#endif
411418 }
@@ -417,28 +424,5 @@ private string CheckWinGetVersion()
417424
418425 return string . Empty ;
419426 }
420-
421- private Version GetVersionObject ( )
422- {
423- string versionString = CheckWinGetVersion ( ) ;
424-
425- #if NETCOREAPP3_1_OR_GREATER
426- //Remove the first letter from the version string.
427- if ( versionString . StartsWith ( 'v' ) )
428- {
429- versionString = versionString [ 1 .. ] . Trim ( ) ;
430-
431- }
432- #elif NETSTANDARD2_0
433- //Remove the first letter from the version string.
434- if ( versionString . StartsWith ( "v" ) )
435- {
436- versionString = versionString . Substring ( 1 ) . Trim ( ) ;
437-
438- }
439- #endif
440-
441- return VersionParser . Parse ( versionString ) ;
442- }
443427 }
444428}
0 commit comments