@@ -658,7 +658,7 @@ public static string FindNearestVersion(string currentVersion, List<string> allA
658658 {
659659 string result = null ;
660660
661- // add current version to list
661+ // add current version to list, to sort it with others
662662 allAvailable . Add ( currentVersion ) ;
663663
664664 // sort list
@@ -675,60 +675,36 @@ public static string FindNearestVersion(string currentVersion, List<string> allA
675675 return result ;
676676 }
677677
678- // string to integer for sorting by version 2017.1.5f1 > 2017010501
678+ // returns version as integer, for easier sorting between versions: 2019.4.19f1 = 2019041901
679679 public static int VersionAsInt ( string version )
680680 {
681681 int result = 0 ;
682- if ( string . IsNullOrEmpty ( version ) ) return result ;
683682
684- // cleanup 32bit version name
683+ // cleanup 32bit version name, TODO is this needed anymore?
685684 string cleanVersion = version . Replace ( "(32-bit)" , "" ) ;
686685
687- // remove a,b,f,p
688- cleanVersion = cleanVersion . Replace ( "a" , "." ) ;
689- cleanVersion = cleanVersion . Replace ( "b" , "." ) ;
690- cleanVersion = cleanVersion . Replace ( "c1 " , "" ) ;
691- cleanVersion = cleanVersion . Replace ( "f" , "." ) ;
692- cleanVersion = cleanVersion . Replace ( "p" , "." ) ;
686+ // remove a (alpha),b (beta),f (final?),p (path),c (china final)
687+ cleanVersion = cleanVersion . Replace ( "a" , ".1. " ) ;
688+ cleanVersion = cleanVersion . Replace ( "b" , ".2. " ) ;
689+ cleanVersion = cleanVersion . Replace ( "c " , ".3. " ) ; // NOTE this was 'c1'
690+ cleanVersion = cleanVersion . Replace ( "f" , ".4. " ) ;
691+ cleanVersion = cleanVersion . Replace ( "p" , ".5. " ) ;
693692
694693 // split values
695694 string [ ] splitted = cleanVersion . Split ( '.' ) ;
696- if ( splitted != null && splitted . Length > 0 )
695+ if ( splitted . Length > 1 )
697696 {
698697 int multiplier = 1 ;
699698 for ( int i = 0 , length = splitted . Length ; i < length ; i ++ )
700699 {
701- int n = int . Parse ( splitted [ splitted . Length - 1 - i ] ) ;
700+ int n = int . Parse ( splitted [ length - 1 - i ] ) ;
702701 result += n * multiplier ;
703- multiplier *= 100 ;
702+ multiplier *= 10 ;
704703 }
705704 }
706705 return result ;
707706 }
708707
709- private static string FindNearestVersionFromSimilarVersions ( string version , IEnumerable < string > allAvailable )
710- {
711- Dictionary < string , string > stripped = new Dictionary < string , string > ( ) ;
712- var enumerable = allAvailable as string [ ] ?? allAvailable . ToArray ( ) ;
713-
714- foreach ( var t in enumerable )
715- {
716- stripped . Add ( new Regex ( "[a-zA-z]" ) . Replace ( t , "." ) , t ) ;
717- }
718-
719- var comparableVersion = new Regex ( "[a-zA-z]" ) . Replace ( version , "." ) ;
720- if ( ! stripped . ContainsKey ( comparableVersion ) )
721- {
722- stripped . Add ( comparableVersion , version ) ;
723- }
724-
725- var comparables = stripped . Keys . OrderBy ( x => x ) . ToList ( ) ;
726- var actualIndex = comparables . IndexOf ( comparableVersion ) ;
727-
728- if ( actualIndex < stripped . Count - 1 ) return stripped [ comparables [ actualIndex + 1 ] ] ;
729- return null ;
730- }
731-
732708 // https://stackoverflow.com/a/1619103/5452781
733709 public static KeyValuePair < TKey , TValue > GetEntry < TKey , TValue > ( this IDictionary < TKey , TValue > dictionary , TKey key )
734710 {
0 commit comments