This commit is contained in:
@ -34,18 +34,7 @@ namespace Elwig {
|
||||
public static readonly string TempPath = Path.Combine(Path.GetTempPath(), "Elwig");
|
||||
|
||||
public static Config Config { get; private set; } = new(ConfigPath);
|
||||
public static int VersionMajor { get; private set; }
|
||||
public static int VersionMinor { get; private set; }
|
||||
public static int VersionPatch { get; private set; }
|
||||
public static string Version {
|
||||
get => $"{VersionMajor}.{VersionMinor}.{VersionPatch}";
|
||||
private set {
|
||||
var p = value.Split(".").Select(p => int.Parse(p.Trim())).ToArray();
|
||||
VersionMajor = p.ElementAtOrDefault(0);
|
||||
VersionMinor = p.ElementAtOrDefault(1);
|
||||
VersionPatch = p.ElementAtOrDefault(2);
|
||||
}
|
||||
}
|
||||
public static Version Version { get; private set; } = new();
|
||||
|
||||
public static int BranchNum { get; private set; }
|
||||
public static string ZwstId { get; private set; }
|
||||
@ -110,7 +99,7 @@ namespace Elwig {
|
||||
}
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs evt) {
|
||||
Version = typeof(App).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0] ?? "0.0.0";
|
||||
Version = new Version(typeof(App).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0] ?? "0.0.0");
|
||||
|
||||
try {
|
||||
await AppDbUpdater.CheckDb();
|
||||
@ -231,7 +220,7 @@ namespace Elwig {
|
||||
public static async Task CheckForUpdates(bool showAlert = false) {
|
||||
if (Config.UpdateUrl == null) return;
|
||||
var latest = await Utils.GetLatestInstallerUrl(Config.UpdateUrl);
|
||||
if (latest != null && new Version(latest.Value.Version) > new Version(Version)) {
|
||||
if (latest != null && new Version(latest.Value.Version) > Version) {
|
||||
await MainDispatcher.BeginInvoke(() => {
|
||||
var d = new UpdateDialog(latest.Value.Version, latest.Value.Url, latest.Value.Size);
|
||||
if (d.ShowDialog() == true) {
|
||||
|
@ -13,7 +13,7 @@ namespace Elwig.Helpers {
|
||||
|
||||
private static int VersionOffset = 0;
|
||||
|
||||
public static async Task<string> CheckDb() {
|
||||
public static async Task<Version> CheckDb() {
|
||||
using var cnx = AppDbContext.Connect();
|
||||
|
||||
var applId = (long?)await AppDbContext.ExecuteScalar(cnx, "PRAGMA application_id") ?? 0;
|
||||
@ -28,18 +28,14 @@ namespace Elwig.Helpers {
|
||||
await UpdateDbSchema(cnx, (int)(schemaVers / 100), RequiredSchemaVersion);
|
||||
|
||||
var userVers = (long?)await AppDbContext.ExecuteScalar(cnx, "PRAGMA user_version") ?? 0;
|
||||
var major = userVers >> 24;
|
||||
var minor = (userVers >> 16) & 0xFF;
|
||||
var patch = userVers & 0xFFFF;
|
||||
var v = new Version((int)(userVers >> 24), (int)((userVers >> 16) & 0xFF), (int)(userVers & 0xFFFF));
|
||||
|
||||
if (App.VersionMajor > major ||
|
||||
(App.VersionMajor == major && App.VersionMinor > minor) ||
|
||||
(App.VersionMajor == major && App.VersionMinor == minor && App.VersionPatch > patch)) {
|
||||
long vers = (App.VersionMajor << 24) | (App.VersionMinor << 16) | App.VersionPatch;
|
||||
if (App.Version > v) {
|
||||
long vers = (App.Version.Major << 24) | (App.Version.Minor << 16) | App.Version.Build;
|
||||
await AppDbContext.ExecuteBatch(cnx, $"PRAGMA user_version = {vers}");
|
||||
}
|
||||
|
||||
return $"{major}.{minor}.{patch}";
|
||||
return v;
|
||||
}
|
||||
|
||||
private static async Task UpdateDbSchema(SqliteConnection cnx, int fromVersion, int toVersion) {
|
||||
|
Reference in New Issue
Block a user