-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersionString.cs
More file actions
55 lines (49 loc) · 1.64 KB
/
VersionString.cs
File metadata and controls
55 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Loader
{
class VersionString : IComparable<VersionString>
{
public int Major;
public int Minor;
public int Third;
public int Fourth;
private const string VersionPattern = @"(\d+)\.(\d+)\.(\d+)\.(\d+)";
public VersionString(string rawString)
{
var match = System.Text.RegularExpressions.Regex.Match(rawString.Trim(), VersionPattern);
//var match = System.Text.RegularExpressions.Regex.Match("1,2","(1)");
//TODO: handle exceptions
Major = int.Parse(match.Groups[1].Value);
Minor = int.Parse(match.Groups[2].Value);
Third = int.Parse(match.Groups[3].Value);
Fourth = int.Parse(match.Groups[4].Value);
}
public VersionString(int Major, int Minor, int Third, int Fourth)
{
this.Major = Major;
this.Minor = Minor;
this.Third = Third;
this.Fourth = Fourth;
}
public override string ToString()
{
return string.Format("{0}.{1}.{2}.{3}", Major, Minor, Third, Fourth);
}
public int CompareTo(VersionString other)
{
if (other.Major != Major) {
return Major.CompareTo(other.Major);
}
if (other.Minor != Minor) {
return Minor.CompareTo(other.Minor);
}
if (other.Third != Third) {
return Third.CompareTo(other.Third);
}
return Fourth.CompareTo(other.Fourth);
}
}
}