Switched to pseudo-semantic versioning, new updater code for manual downloading of udpates

This commit is contained in:
N00MKRAD
2020-12-08 20:41:50 +01:00
parent 79fd8b82dd
commit f968db6180
7 changed files with 117 additions and 27 deletions

32
Code/Data/SemVer.cs Normal file
View File

@@ -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}";
}
}
}

View File

@@ -171,6 +171,7 @@
<Compile Include="Data\BatchEntry.cs" />
<Compile Include="Data\Networks.cs" />
<Compile Include="Data\Padding.cs" />
<Compile Include="Data\SemVer.cs" />
<Compile Include="Forms\BatchForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -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)

View File

@@ -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);
}
}
}

View File

@@ -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");

View File

@@ -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}).");
}
}
}

View File

@@ -12,7 +12,7 @@ namespace Flowframes
{
static class Program
{
public const int version = 18;
//public const int version = 18;
public static Form1 mainForm;