@@ -25,30 +25,54 @@ internal partial class Runtime
25
25
private sealed class RuntimeVersion : IComparable < RuntimeVersion >
26
26
{
27
27
private readonly string dir ;
28
- public Version Version { get ; }
28
+ private Version Version { get ; }
29
+ private Version ? PreviewVersion { get ; } = null ;
30
+ private bool IsPreview => PreviewVersion is not null ;
31
+ public string FullPath
32
+ {
33
+ get
34
+ {
35
+ var preview = IsPreview ? $ "-preview.{ PreviewVersion } " : "" ;
36
+ var version = Version + preview ;
37
+ return Path . Combine ( dir , version ) ;
38
+ }
39
+ }
29
40
30
- public string FullPath => Path . Combine ( dir , Version . ToString ( ) ) ;
41
+ private static Version MakeVersion ( string version )
42
+ {
43
+ var versionParts = version . Split ( '.' ) ;
44
+ return new Version ( int . Parse ( versionParts [ 0 ] ) , int . Parse ( versionParts [ 1 ] ) , int . Parse ( versionParts [ 2 ] ) ) ;
45
+ }
31
46
32
- // TODO: Also improve to account for preview versions.
33
- public RuntimeVersion ( string version , string dir )
47
+ public RuntimeVersion ( string dir , string version , string previewVersion )
34
48
{
35
- var parts = version . Split ( '.' ) ;
36
- Version = new Version ( int . Parse ( parts [ 0 ] ) , int . Parse ( parts [ 1 ] ) , int . Parse ( parts [ 2 ] ) ) ;
37
49
this . dir = dir ;
50
+ Version = MakeVersion ( version ) ;
51
+ if ( ! string . IsNullOrEmpty ( previewVersion ) )
52
+ {
53
+ PreviewVersion = MakeVersion ( previewVersion ) ;
54
+ }
38
55
}
39
56
40
- public int CompareTo ( RuntimeVersion ? other ) => Version . CompareTo ( other ? . Version ) ;
57
+ public int CompareTo ( RuntimeVersion ? other )
58
+ {
59
+ var c = Version . CompareTo ( other ? . Version ) ;
60
+ if ( c == 0 && IsPreview )
61
+ {
62
+ return other ! . IsPreview ? PreviewVersion ! . CompareTo ( other ! . PreviewVersion ) : - 1 ;
63
+ }
64
+ return c ;
65
+ }
41
66
42
67
public override bool Equals ( object ? obj ) =>
43
68
obj is not null && obj is RuntimeVersion other && other . FullPath == FullPath ;
44
69
45
- public override int GetHashCode ( ) => Version . GetHashCode ( ) ;
70
+ public override int GetHashCode ( ) => FullPath . GetHashCode ( ) ;
46
71
47
72
public override string ToString ( ) => FullPath ;
48
73
}
49
74
50
-
51
- [ GeneratedRegex ( @"^(\S+)\s(\d+\.\d+\.\d+)\s\[(\S+)\]$" ) ]
75
+ [ GeneratedRegex ( @"^(\S+)\s(\d+\.\d+\.\d+)(-preview\.(\d+\.\d+\.\d+))?\s\[(\S+)\]$" ) ]
52
76
private static partial Regex RuntimeRegex ( ) ;
53
77
54
78
/// <summary>
@@ -66,7 +90,7 @@ private static Dictionary<string, RuntimeVersion> ParseRuntimes(IList<string> li
66
90
var match = RuntimeRegex ( ) . Match ( r ) ;
67
91
if ( match . Success )
68
92
{
69
- runtimes . AddOrUpdate ( match . Groups [ 1 ] . Value , new RuntimeVersion ( match . Groups [ 2 ] . Value , match . Groups [ 3 ] . Value ) ) ;
93
+ runtimes . AddOrUpdate ( match . Groups [ 1 ] . Value , new RuntimeVersion ( match . Groups [ 5 ] . Value , match . Groups [ 2 ] . Value , match . Groups [ 4 ] . Value ) ) ;
70
94
}
71
95
} ) ;
72
96
0 commit comments