From f968db618083ca463f59070b5a995a9e6cd47ad4 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Tue, 8 Dec 2020 20:41:50 +0100 Subject: [PATCH] Switched to pseudo-semantic versioning, new updater code for manual downloading of udpates --- Code/Data/SemVer.cs | 32 ++++++++++++++++ Code/Flowframes.csproj | 1 + Code/Form1.cs | 4 +- Code/Forms/UpdaterForm.cs | 19 +++++---- Code/IO/Paths.cs | 5 +++ Code/OS/Updater.cs | 81 ++++++++++++++++++++++++++++++++------- Code/Program.cs | 2 +- 7 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 Code/Data/SemVer.cs diff --git a/Code/Data/SemVer.cs b/Code/Data/SemVer.cs new file mode 100644 index 0000000..d12a22e --- /dev/null +++ b/Code/Data/SemVer.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace Flowframes.Data +{ + public struct SemVer + { + public int major; + public int minor; + public int patch; + + public SemVer(int majorNum, int minorNum, int patchNum) + { + major = majorNum; + minor = minorNum; + patch = patchNum; + } + + public SemVer(string versionStr) + { + string[] nums = versionStr.Trim().Split('.'); + major = nums[0].GetInt(); + minor = nums[1].GetInt(); + patch = nums[2].GetInt(); + } + + public override string ToString () + { + return $"{major}.{minor}.{patch}"; + } + } +} diff --git a/Code/Flowframes.csproj b/Code/Flowframes.csproj index 8d0118a..42c15e7 100644 --- a/Code/Flowframes.csproj +++ b/Code/Flowframes.csproj @@ -171,6 +171,7 @@ + Form diff --git a/Code/Form1.cs b/Code/Form1.cs index 9b838b3..300510a 100644 --- a/Code/Form1.cs +++ b/Code/Form1.cs @@ -30,7 +30,7 @@ namespace Flowframes private void Form1_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; - Text = $"Flowframes v{Program.version}"; + Text = $"Flowframes {Updater.GetInstalledVer()}"; // Main Tab UIUtils.InitCombox(interpFactorCombox, 0); @@ -228,7 +228,7 @@ namespace Flowframes { UpdateOutputFPS(); if (Interpolate.interpFactor > 2 && !GetAi().supportsAnyExp && Config.GetInt("autoEncMode") > 0) - Logger.Log($"Warning: This AI will run multiple times for {Interpolate.interpFactor}x. Auto-Encode will only work on the last run."); + Logger.Log($"Warning: {GetAi().aiName.Replace("_", "-")} doesn't natively support 4x/8x and will run multiple times for {Interpolate.interpFactor}x. Auto-Encode will only work on the last run."); } public void SetWorking(bool state) diff --git a/Code/Forms/UpdaterForm.cs b/Code/Forms/UpdaterForm.cs index 3bbdc81..a813a21 100644 --- a/Code/Forms/UpdaterForm.cs +++ b/Code/Forms/UpdaterForm.cs @@ -1,6 +1,8 @@ -using Flowframes.OS; +using Flowframes.Data; +using Flowframes.OS; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading.Tasks; using System.Windows.Forms; @@ -8,8 +10,8 @@ namespace Flowframes.Forms { public partial class UpdaterForm : Form { - int installed; - int latest; + SemVer installed; + SemVer latest; public UpdaterForm() { @@ -32,7 +34,7 @@ namespace Flowframes.Forms } else { - if(installed < latest) + if(Updater.IsVersionNewer(installed, latest)) { updateBtn.Text = "Update To Latest Version!"; statusLabel.Text = "Update Available!"; @@ -57,12 +59,9 @@ namespace Flowframes.Forms private async void updateBtn_Click(object sender, EventArgs e) { - await Task.Run(() => DoUpdate()); - } - - async void DoUpdate () - { - await Updater.UpdateTo(latest, this); + string link = Updater.GetLatestVerLink(); + if(!string.IsNullOrWhiteSpace(link)) + Process.Start(link); } } } diff --git a/Code/IO/Paths.cs b/Code/IO/Paths.cs index 1212c93..764efa3 100644 --- a/Code/IO/Paths.cs +++ b/Code/IO/Paths.cs @@ -19,6 +19,11 @@ namespace Flowframes.IO } + public static string GetVerPath() + { + return Path.Combine(GetDataPath(), "ver.ini"); + } + public static string GetDataPath () { string path = Path.Combine(IOUtils.GetExeDir(), "FlowframesData"); diff --git a/Code/OS/Updater.cs b/Code/OS/Updater.cs index 52405cd..f34f23a 100644 --- a/Code/OS/Updater.cs +++ b/Code/OS/Updater.cs @@ -1,4 +1,5 @@ -using Flowframes.Forms; +using Flowframes.Data; +using Flowframes.Forms; using Flowframes.IO; using System; using System.Collections.Generic; @@ -13,22 +14,76 @@ namespace Flowframes.OS { class Updater { - public static string latestVerUrl = "https://dl.nmkd.de/flowframes/exe/latest.txt"; + public static string latestVerUrl = "https://dl.nmkd.de/flowframes/exe/latest.ini"; - public static int GetInstalledVer() + public static SemVer GetInstalledVer() { - return Program.version; + try + { + string verStr = IOUtils.ReadLines(Paths.GetVerPath())[0]; + return new SemVer(verStr); + } + catch (Exception e) + { + Logger.Log("Error getting installed version: " + e.Message); + return new SemVer(0, 0, 0); + } } - public static int GetLatestVer () + public static bool IsVersionNewer (SemVer currentVer, SemVer newVer) + { + if (newVer.major > currentVer.major) + { + return true; + } + else + { + if(newVer.minor > currentVer.minor) + { + return true; + } + else + { + if (newVer.patch > currentVer.patch) + { + return true; + } + else + { + return false; + } + } + } + } + + public static bool VersionMatches (SemVer v1, SemVer v2) + { + return v1.major == v2.major && v1.minor == v2.minor && v1.patch == v2.patch; + } + + public static SemVer GetLatestVer () { var client = new WebClient(); - return client.DownloadString(latestVerUrl).GetInt(); + return new SemVer(client.DownloadString(latestVerUrl).SplitIntoLines()[0]); + } + + public static string GetLatestVerLink() + { + var client = new WebClient(); + try + { + return client.DownloadString(latestVerUrl).SplitIntoLines()[1].Trim(); + } + catch + { + Logger.Log("Failed to get latest version link from latest.ini!", true); + return ""; + } } public static async Task UpdateTo (int version, UpdaterForm form = null) { - Logger.Log("Updating to v" + version, true); + Logger.Log("Updating to " + version, true); string savePath = Path.Combine(IOUtils.GetExeDir(), $"FlowframesV{version}"); try { @@ -77,15 +132,13 @@ namespace Flowframes.OS public static async Task AsyncUpdateCheck () { - var client = new WebClient(); - var latestVer = await client.DownloadStringTaskAsync(latestVerUrl); - int latest = latestVer.GetInt(); - int installed = GetInstalledVer(); + SemVer latest = GetLatestVer(); + SemVer installed = GetInstalledVer(); - if (installed < latest) - Logger.Log("An update for Flowframes is available! Download it using the Updater."); + if (IsVersionNewer(installed, latest)) + Logger.Log($"An update for Flowframes ({latest}) is available! Download it from the Updater."); else - Logger.Log("Flowframes is up to date."); + Logger.Log($"Flowframes is up to date ({installed})."); } } } diff --git a/Code/Program.cs b/Code/Program.cs index c05e04e..e1fcbda 100644 --- a/Code/Program.cs +++ b/Code/Program.cs @@ -12,7 +12,7 @@ namespace Flowframes { static class Program { - public const int version = 18; + //public const int version = 18; public static Form1 mainForm;