2727#pragma warning disable
2828#endif
2929
30- namespace Bannerlord . ModuleManager ;
31-
32- using System ;
30+ namespace Bannerlord . ModuleManager
31+ {
32+ using System ;
3333
3434#if ! BANNERLORDBUTRMODULEMANAGER_PUBLIC
3535 internal
3636#else
37- public
37+ public
3838# endif
39- record ApplicationVersion : IComparable < ApplicationVersion >
40- {
41- public static ApplicationVersion Empty { get ; } = new ( ) ;
42-
43- public ApplicationVersionType ApplicationVersionType { get ; set ; }
44- public int Major { get ; set ; }
45- public int Minor { get ; set ; }
46- public int Revision { get ; set ; }
47- public int ChangeSet { get ; set ; }
48-
49- public ApplicationVersion ( ) { }
50- public ApplicationVersion ( ApplicationVersionType applicationVersionType , int major , int minor , int revision , int changeSet )
39+ record ApplicationVersion : IComparable < ApplicationVersion >
5140 {
52- ApplicationVersionType = applicationVersionType ;
53- Major = major ;
54- Minor = minor ;
55- Revision = revision ;
56- ChangeSet = changeSet ;
57- }
41+ public static ApplicationVersion Empty { get ; } = new ( ) ;
5842
59- public bool IsSame ( ApplicationVersion ? other ) =>
60- Major == other ? . Major && Minor == other . Minor && Revision == other . Revision ;
43+ public ApplicationVersionType ApplicationVersionType { get ; set ; }
44+ public int Major { get ; set ; }
45+ public int Minor { get ; set ; }
46+ public int Revision { get ; set ; }
47+ public int ChangeSet { get ; set ; }
6148
62- public bool IsSameWithChangeSet ( ApplicationVersion ? other ) =>
63- Major == other ? . Major && Minor == other . Minor && Revision == other . Revision && ChangeSet == other . ChangeSet ;
64-
65- public override string ToString ( )
66- {
67- // Most user mods skip this, so to be user-friendly we can omit it if it was not originally specified.
68- return ChangeSet == 0
69- ? $ "{ GetPrefix ( ApplicationVersionType ) } { Major } .{ Minor } .{ Revision } "
70- : $ "{ GetPrefix ( ApplicationVersionType ) } { Major } .{ Minor } .{ Revision } .{ ChangeSet } ";
71- }
72- public string ToStringWithoutChangeset ( ) => $ "{ GetPrefix ( ApplicationVersionType ) } { Major } .{ Minor } .{ Revision } ";
73-
74- public int CompareTo ( ApplicationVersion ? other ) => ApplicationVersionComparer . CompareStandard ( this , other ) ;
75-
76- public static bool operator < ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) < 0 ;
77- public static bool operator > ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) > 0 ;
78- public static bool operator <= ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) <= 0 ;
79- public static bool operator >= ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) >= 0 ;
49+ public ApplicationVersion ( ) { }
50+ public ApplicationVersion ( ApplicationVersionType applicationVersionType , int major , int minor , int revision , int changeSet )
51+ {
52+ ApplicationVersionType = applicationVersionType ;
53+ Major = major ;
54+ Minor = minor ;
55+ Revision = revision ;
56+ ChangeSet = changeSet ;
57+ }
8058
81- public static char GetPrefix ( ApplicationVersionType applicationVersionType ) => applicationVersionType switch
82- {
83- ApplicationVersionType . Alpha => 'a' ,
84- ApplicationVersionType . Beta => 'b' ,
85- ApplicationVersionType . EarlyAccess => 'e' ,
86- ApplicationVersionType . Release => 'v' ,
87- ApplicationVersionType . Development => 'd' ,
88- _ => 'i'
89- } ;
90-
91- public static ApplicationVersionType FromPrefix ( char applicationVersionType ) => applicationVersionType switch
92- {
93- 'a' => ApplicationVersionType . Alpha ,
94- 'b' => ApplicationVersionType . Beta ,
95- 'e' => ApplicationVersionType . EarlyAccess ,
96- 'v' => ApplicationVersionType . Release ,
97- 'd' => ApplicationVersionType . Development ,
98- _ => ApplicationVersionType . Invalid
99- } ;
59+ public bool IsSame ( ApplicationVersion ? other ) =>
60+ Major == other ? . Major && Minor == other . Minor && Revision == other . Revision ;
10061
101- public static bool TryParse ( string ? versionAsString , out ApplicationVersion version ) => TryParse ( versionAsString , out version , true ) ;
62+ public bool IsSameWithChangeSet ( ApplicationVersion ? other ) =>
63+ Major == other ? . Major && Minor == other . Minor && Revision == other . Revision && ChangeSet == other . ChangeSet ;
10264
103- public static bool TryParse ( string ? versionAsString , out ApplicationVersion version , bool asMin )
104- {
105- var major = asMin ? 0 : int . MaxValue ;
106- var minor = asMin ? 0 : int . MaxValue ;
107- var revision = asMin ? 0 : int . MaxValue ;
108- var changeSet = asMin ? 0 : int . MaxValue ;
109- var skipCheck = false ;
110- version = Empty ;
111- if ( versionAsString is null )
112- return false ;
113-
114- var array = versionAsString . Split ( '.' ) ;
115- if ( array . Length != 3 && array . Length != 4 && array [ 0 ] . Length == 0 )
116- return false ;
117-
118- var applicationVersionType = FromPrefix ( array [ 0 ] [ 0 ] ) ;
119- if ( ! skipCheck && ! int . TryParse ( array [ 0 ] . Substring ( 1 ) , out major ) )
120- {
121- if ( array [ 0 ] . Substring ( 1 ) != "*" ) return false ;
122- major = int . MinValue ;
123- minor = int . MinValue ;
124- revision = int . MinValue ;
125- changeSet = int . MinValue ;
126- skipCheck = true ;
127- }
128- if ( ! skipCheck && ! int . TryParse ( array [ 1 ] , out minor ) )
65+ public override string ToString ( )
12966 {
130- if ( array [ 1 ] != "*" ) return false ;
131- minor = asMin ? 0 : int . MaxValue ;
132- revision = asMin ? 0 : int . MaxValue ;
133- changeSet = asMin ? 0 : int . MaxValue ;
134- skipCheck = true ;
135- }
136- if ( ! skipCheck && ! int . TryParse ( array [ 2 ] , out revision ) )
137- {
138- if ( array [ 2 ] != "*" ) return false ;
139- revision = asMin ? 0 : int . MaxValue ;
140- changeSet = asMin ? 0 : int . MaxValue ;
141- skipCheck = true ;
67+ // Most user mods skip this, so to be user-friendly we can omit it if it was not originally specified.
68+ return ChangeSet == 0
69+ ? $ "{ GetPrefix ( ApplicationVersionType ) } { Major } .{ Minor } .{ Revision } "
70+ : $ "{ GetPrefix ( ApplicationVersionType ) } { Major } .{ Minor } .{ Revision } .{ ChangeSet } ";
14271 }
72+ public string ToStringWithoutChangeset ( ) => $ "{ GetPrefix ( ApplicationVersionType ) } { Major } .{ Minor } .{ Revision } ";
73+
74+ public int CompareTo ( ApplicationVersion ? other ) => ApplicationVersionComparer . CompareStandard ( this , other ) ;
75+
76+ public static bool operator < ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) < 0 ;
77+ public static bool operator > ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) > 0 ;
78+ public static bool operator <= ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) <= 0 ;
79+ public static bool operator >= ( ApplicationVersion left , ApplicationVersion right ) => left . CompareTo ( right ) >= 0 ;
14380
144- if ( ! skipCheck && array . Length == 4 && ! int . TryParse ( array [ 3 ] , out changeSet ) )
81+ public static char GetPrefix ( ApplicationVersionType applicationVersionType ) => applicationVersionType switch
14582 {
146- if ( array [ 3 ] != "*" ) return false ;
147- changeSet = asMin ? 0 : int . MaxValue ;
148- skipCheck = true ;
149- }
83+ ApplicationVersionType . Alpha => 'a' ,
84+ ApplicationVersionType . Beta => 'b' ,
85+ ApplicationVersionType . EarlyAccess => 'e' ,
86+ ApplicationVersionType . Release => 'v' ,
87+ ApplicationVersionType . Development => 'd' ,
88+ _ => 'i'
89+ } ;
15090
151- version = new ApplicationVersion
91+ public static ApplicationVersionType FromPrefix ( char applicationVersionType ) => applicationVersionType switch
15292 {
153- ApplicationVersionType = applicationVersionType ,
154- Major = major ,
155- Minor = minor ,
156- Revision = revision ,
157- ChangeSet = changeSet
93+ 'a' => ApplicationVersionType . Alpha ,
94+ 'b' => ApplicationVersionType . Beta ,
95+ 'e' => ApplicationVersionType . EarlyAccess ,
96+ 'v' => ApplicationVersionType . Release ,
97+ 'd' => ApplicationVersionType . Development ,
98+ _ => ApplicationVersionType . Invalid
15899 } ;
159100
160- return true ;
161- }
162- }
101+ public static bool TryParse ( string ? versionAsString , out ApplicationVersion version ) => TryParse ( versionAsString , out version , true ) ;
163102
103+ public static bool TryParse ( string ? versionAsString , out ApplicationVersion version , bool asMin )
104+ {
105+ var major = asMin ? 0 : int . MaxValue ;
106+ var minor = asMin ? 0 : int . MaxValue ;
107+ var revision = asMin ? 0 : int . MaxValue ;
108+ var changeSet = asMin ? 0 : int . MaxValue ;
109+ var skipCheck = false ;
110+ version = Empty ;
111+ if ( versionAsString is null )
112+ return false ;
113+
114+ var array = versionAsString . Split ( '.' ) ;
115+ if ( array . Length != 3 && array . Length != 4 && array [ 0 ] . Length == 0 )
116+ return false ;
117+
118+ var applicationVersionType = FromPrefix ( array [ 0 ] [ 0 ] ) ;
119+ if ( ! skipCheck && ! int . TryParse ( array [ 0 ] . Substring ( 1 ) , out major ) )
120+ {
121+ if ( array [ 0 ] . Substring ( 1 ) != "*" ) return false ;
122+ major = int . MinValue ;
123+ minor = int . MinValue ;
124+ revision = int . MinValue ;
125+ changeSet = int . MinValue ;
126+ skipCheck = true ;
127+ }
128+ if ( ! skipCheck && ! int . TryParse ( array [ 1 ] , out minor ) )
129+ {
130+ if ( array [ 1 ] != "*" ) return false ;
131+ minor = asMin ? 0 : int . MaxValue ;
132+ revision = asMin ? 0 : int . MaxValue ;
133+ changeSet = asMin ? 0 : int . MaxValue ;
134+ skipCheck = true ;
135+ }
136+ if ( ! skipCheck && ! int . TryParse ( array [ 2 ] , out revision ) )
137+ {
138+ if ( array [ 2 ] != "*" ) return false ;
139+ revision = asMin ? 0 : int . MaxValue ;
140+ changeSet = asMin ? 0 : int . MaxValue ;
141+ skipCheck = true ;
142+ }
143+
144+ if ( ! skipCheck && array . Length == 4 && ! int . TryParse ( array [ 3 ] , out changeSet ) )
145+ {
146+ if ( array [ 3 ] != "*" ) return false ;
147+ changeSet = asMin ? 0 : int . MaxValue ;
148+ skipCheck = true ;
149+ }
150+
151+ version = new ApplicationVersion
152+ {
153+ ApplicationVersionType = applicationVersionType ,
154+ Major = major ,
155+ Minor = minor ,
156+ Revision = revision ,
157+ ChangeSet = changeSet
158+ } ;
159+
160+ return true ;
161+ }
162+ }
164163#nullable restore
165164#if ! BANNERLORDBUTRMODULEMANAGER_ENABLE_WARNING
166165#pragma warning restore
167- #endif
166+ #endif
167+ }
0 commit comments