You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
downkyi/DownKyi/Models/AppInfo.cs

54 lines
1.2 KiB

using System;
using System.Text.RegularExpressions;
namespace DownKyi.Models
{
public class AppInfo
{
public string Name { get; } = "哔哩下载姬";
public int VersionCode { get; }
public string VersionName { get; }
const int a = 1;
const int b = 5;
const int c = 7;
public AppInfo()
{
VersionCode = a * 10000 + b * 100 + c;
3 years ago
#if DEBUG
VersionName = $"{a}.{b}.{c}-debug";
3 years ago
#else
VersionName = $"{a}.{b}.{c}";
3 years ago
#endif
}
public static int VersionNameToCode(string versionName)
{
int code = 0;
var isMatch = Regex.IsMatch(versionName, @"^v?([1-9]\d|\d).([1-9]\d|\d).([1-9]\d|\d)$");
if (!isMatch)
{
return 0;
}
string pattern = @"([1-9]\d|\d)";
var m = Regex.Matches(versionName, pattern);
if (m.Count == 3)
{
int i = 2;
foreach (var item in m)
{
code += int.Parse(item.ToString()) * (int)Math.Pow(100, i);
i--;
}
}
return code;
}
3 years ago
}
}