forked from antonpup/Aurora
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change semantic version parse to tag version parse in updater detection
- Loading branch information
1 parent
7f36e31
commit b04ca7f
Showing
2 changed files
with
107 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Text.RegularExpressions; | ||
using Version = SemanticVersioning.Version; | ||
|
||
namespace Aurora_Updater; | ||
|
||
// https://regex101.com/r/jQ255t/1 | ||
public static partial class VersionParser | ||
{ | ||
public static Version ParseVersion(string versionString) | ||
{ | ||
var regex = SemanticVersionRegex(); | ||
var match = regex.Match(versionString); | ||
|
||
var groupCollection = match.Groups; | ||
|
||
int.TryParse(groupCollection[1].Value, out var major); | ||
int.TryParse(groupCollection[2].Value, out var minor); | ||
int.TryParse(groupCollection[3].Value, out var patch); | ||
|
||
var suffix = groupCollection[4].Success ? groupCollection[4].Value : null; | ||
if (string.IsNullOrWhiteSpace(suffix)) | ||
{ | ||
suffix = null; | ||
} | ||
|
||
return new Version(major, minor, patch, suffix); | ||
} | ||
|
||
[GeneratedRegex(@"v?(\d+)\.?(\d+)?\.?(\d+)?-?(.*)?")] | ||
private static partial Regex SemanticVersionRegex(); | ||
} |