mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-07-13 05:50:33 +02:00
Removed SemVer class and use Version class instead
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,6 @@
|
||||
<Compile Include="Data\Networks.cs" />
|
||||
<Compile Include="Data\Padding.cs" />
|
||||
<Compile Include="Data\ResumeState.cs" />
|
||||
<Compile Include="Data\SemVer.cs" />
|
||||
<Compile Include="Data\SubtitleTrack.cs" />
|
||||
<Compile Include="Forms\BatchForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Flowframes.Forms
|
||||
{
|
||||
public partial class UpdaterForm : Form
|
||||
{
|
||||
SemVer installed;
|
||||
SemVer latestPat;
|
||||
SemVer latestFree;
|
||||
Version installed;
|
||||
Version latestPat;
|
||||
Version latestFree;
|
||||
|
||||
public UpdaterForm()
|
||||
{
|
||||
@@ -30,27 +30,27 @@ namespace Flowframes.Forms
|
||||
await Task.Delay(100);
|
||||
latestLabel.Text = $"{latestPat} (Patreon/Beta) - {latestFree} (Free/Stable)";
|
||||
|
||||
if (Updater.VersionMatches(installed, latestFree))
|
||||
if (Updater.CompareVersions(installed, latestFree) == Updater.VersionCompareResult.Equal)
|
||||
{
|
||||
statusLabel.Text = "Latest Free Version Is Installed.";
|
||||
|
||||
if (Updater.IsVersionNewer(installed, latestPat))
|
||||
if (Updater.CompareVersions(installed, latestPat) == Updater.VersionCompareResult.Newer)
|
||||
statusLabel.Text += "\nBeta Update Available On Patreon.";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Updater.VersionMatches(installed, latestPat))
|
||||
if (Updater.CompareVersions(installed, latestPat) == Updater.VersionCompareResult.Equal)
|
||||
{
|
||||
statusLabel.Text = "Latest Patreon/Beta Version Is Installed.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (Updater.IsVersionNewer(installed, latestPat))
|
||||
if (Updater.CompareVersions(installed, latestPat) == Updater.VersionCompareResult.Newer)
|
||||
{
|
||||
statusLabel.Text = "Update available on Patreon!";
|
||||
|
||||
if (Updater.IsVersionNewer(installed, latestFree))
|
||||
if (Updater.CompareVersions(installed, latestFree) == Updater.VersionCompareResult.Newer)
|
||||
statusLabel.Text = $"Beta Updates Available On Patreon and Itch.io.";
|
||||
|
||||
return;
|
||||
|
||||
@@ -14,56 +14,49 @@ namespace Flowframes.OS
|
||||
{
|
||||
class Updater
|
||||
{
|
||||
public enum VersionCompareResult { Older, Newer, Equal };
|
||||
public static string latestVerUrl = "https://dl.nmkd.de/flowframes/exe/ver.ini";
|
||||
|
||||
public static SemVer GetInstalledVer()
|
||||
public static Version GetInstalledVer()
|
||||
{
|
||||
try
|
||||
{
|
||||
string verStr = IOUtils.ReadLines(Paths.GetVerPath())[0];
|
||||
return new SemVer(verStr);
|
||||
return new Version(verStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log("Error getting installed version: " + e.Message);
|
||||
return new SemVer(0, 0, 0);
|
||||
return new Version(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsVersionNewer (SemVer currentVersion, SemVer newVersion)
|
||||
public static VersionCompareResult CompareVersions (Version currentVersion, Version newVersion)
|
||||
{
|
||||
Logger.Log($"Checking if {newVersion} > {currentVersion}", true);
|
||||
|
||||
Version currVer = new Version(currentVersion.major, currentVersion.minor, currentVersion.patch);
|
||||
Version newVer = new Version(newVersion.major, newVersion.minor, newVersion.patch);
|
||||
int result = newVer.CompareTo(currVer);
|
||||
int result = newVersion.CompareTo(currentVersion);
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
Logger.Log($"{newVer} is newer than {currentVersion}.", true);
|
||||
return true;
|
||||
Logger.Log($"{newVersion} is newer than {currentVersion}.", true);
|
||||
return VersionCompareResult.Newer;
|
||||
}
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
Logger.Log($"{newVer} is older than {currentVersion}.", true);
|
||||
return false;
|
||||
Logger.Log($"{newVersion} is older than {currentVersion}.", true);
|
||||
return VersionCompareResult.Older;
|
||||
}
|
||||
|
||||
Logger.Log($"{newVer} is equal to {currentVersion}.", true);
|
||||
return false;
|
||||
Logger.Log($"{newVersion} is equal to {currentVersion}.", true);
|
||||
return VersionCompareResult.Equal;
|
||||
}
|
||||
|
||||
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 (bool patreon)
|
||||
public static Version GetLatestVer (bool patreon)
|
||||
{
|
||||
var client = new WebClient();
|
||||
int line = patreon ? 0 : 2;
|
||||
return new SemVer(client.DownloadString(latestVerUrl).SplitIntoLines()[line]);
|
||||
return new Version(client.DownloadString(latestVerUrl).SplitIntoLines()[line]);
|
||||
}
|
||||
|
||||
public static string GetLatestVerLink(bool patreon)
|
||||
@@ -132,16 +125,11 @@ namespace Flowframes.OS
|
||||
|
||||
public static async Task AsyncUpdateCheck ()
|
||||
{
|
||||
SemVer installed = GetInstalledVer();
|
||||
SemVer latestPat = GetLatestVer(true);
|
||||
SemVer latestFree = GetLatestVer(false);
|
||||
Version installed = GetInstalledVer();
|
||||
Version latestPat = GetLatestVer(true);
|
||||
Version latestFree = GetLatestVer(false);
|
||||
|
||||
Logger.Log($"You are running Flowframes {installed}. The latest Patreon version is {latestPat}, the latest free version is {latestFree}.");
|
||||
|
||||
// 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 ({installed}).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user