1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Reflection ;
5- using System . Text ;
6- using System . Text . RegularExpressions ;
7- using log4net ;
8-
9- namespace MissionPlanner . Utilities
10- {
11- public class VersionDetection
12- {
13- private static readonly ILog log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
14-
15- public static Version GetVersion ( string input )
1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Reflection ;
5+ using System . Text ;
6+ using System . Text . RegularExpressions ;
7+ using log4net ;
8+
9+ namespace MissionPlanner . Utilities
10+ {
11+ public class VersionDetection
12+ {
13+ private static readonly ILog log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
14+
15+ public static Version GetVersion ( string input )
1616 {
17- Regex versionregex = new Regex ( @"([0-9]+)\.([0-9]+)(\.([0-9]+)|-rc([0-9]+)|([a-z]{2,20})|([a-z]))*" ) ;
18-
19- // string ans = mat1.Groups[1].Value.ToString() + mat1.Groups[2].Value.ToString() + mat1.Groups[4].Value.ToString() + mat1.Groups[5].Value.ToString() + mat1.Groups[6].Value.ToString();
20-
21- var match = versionregex . Match ( input ) ;
22-
23- log . Info ( input ) ;
24-
25- if ( match . Success )
26- {
27- // start with major.monor
28- string verstring = match . Groups [ 1 ] . Value . ToString ( ) + "." + match . Groups [ 2 ] . Value . ToString ( ) ;
29-
30- if ( ! String . IsNullOrEmpty ( match . Groups [ 4 ] . Value ) )
31- {
32- verstring += "." + match . Groups [ 4 ] . Value . ToString ( ) ;
33- }
34- if ( ! String . IsNullOrEmpty ( match . Groups [ 5 ] . Value ) )
35- {
36- // -rc
37- verstring += "." + match . Groups [ 5 ] . Value . ToString ( ) ;
38- }
39- if ( ! String . IsNullOrEmpty ( match . Groups [ 6 ] . Value ) )
40- {
41- // dev
42- verstring += ".255" ;
43- }
44- if ( ! String . IsNullOrEmpty ( match . Groups [ 7 ] . Value ) )
45- {
46- // convert a to 1, b to 2, etc, it will break at j
47- verstring += "." + ( char ) ( ( match . Groups [ 6 ] . Value . ToString ( ) . ToLower ( ) [ 0 ] ) - 0x30 ) ;
48- }
49-
50- Version version = new Version ( verstring ) ;
51-
52- log . Info ( version . ToString ( ) ) ;
53-
54- return version ;
55- }
56-
57- throw new Exception ( "Bad Version" ) ;
58- }
59- }
17+ Regex versionregex = new Regex ( @"([0-9]+)\.([0-9]+)(\.([0-9]+)|-rc([0-9]+)|([a-z]{2,20})|([a-z]))*" ) ;
18+
19+ // string ans = mat1.Groups[1].Value.ToString() + mat1.Groups[2].Value.ToString() + mat1.Groups[4].Value.ToString() + mat1.Groups[5].Value.ToString() + mat1.Groups[6].Value.ToString();
20+
21+ var match = versionregex . Match ( input ) ;
22+
23+ log . Info ( input ) ;
24+
25+ if ( match . Success )
26+ {
27+ // start with major.monor
28+ string verstring = match . Groups [ 1 ] . Value . ToString ( ) + "." + match . Groups [ 2 ] . Value . ToString ( ) ;
29+
30+ if ( ! String . IsNullOrEmpty ( match . Groups [ 4 ] . Value ) )
31+ {
32+ verstring += "." + match . Groups [ 4 ] . Value . ToString ( ) ;
33+ }
34+ if ( ! String . IsNullOrEmpty ( match . Groups [ 5 ] . Value ) )
35+ {
36+ // -rc
37+ verstring += "." + match . Groups [ 5 ] . Value . ToString ( ) ;
38+ }
39+ if ( ! String . IsNullOrEmpty ( match . Groups [ 6 ] . Value ) )
40+ {
41+ // dev
42+ verstring += ".255" ;
43+ }
44+ if ( ! String . IsNullOrEmpty ( match . Groups [ 7 ] . Value ) )
45+ {
46+ // convert a to 1, b to 2, etc, it will break at j
47+ verstring += "." + ( char ) ( ( match . Groups [ 6 ] . Value . ToString ( ) . ToLower ( ) [ 0 ] ) - 0x30 ) ;
48+ }
49+
50+ Version version = new Version ( verstring ) ;
51+
52+ log . Info ( version . ToString ( ) ) ;
53+
54+ return version ;
55+ }
56+
57+ throw new Exception ( "Bad Version" ) ;
58+ }
59+ }
6060}
0 commit comments