重写AppInfo中的版本号

croire 2 years ago
parent 48624ff505
commit c1f40298b8

@ -1,15 +1,53 @@
namespace DownKyi.Models
using System;
using System.Text.RegularExpressions;
namespace DownKyi.Models
{
public class AppInfo
{
public string Name { get; } = "哔哩下载姬";
public int VersionCode { get; } = 513;
public int VersionCode { get; }
public string VersionName { get; }
const int a = 1;
const int b = 5;
const int c = 6;
public AppInfo()
{
VersionCode = a * 10000 + b * 100 + c;
#if DEBUG
public string VersionName { get; } = "1.5.6 Debug";
VersionName = $"{a}.{b}.{c}-debug";
#else
public string VersionName { get; } = "1.5.6";
VersionName = $"{a}.{b}.{c}";
#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;
}
}
}

Loading…
Cancel
Save