feat(autoupdate): remove trailing zeros, show prerelease tag

This commit is contained in:
2026-03-10 16:17:04 +01:00
parent a7aad1a5ef
commit f24d1321a8
4 changed files with 39 additions and 16 deletions

View File

@@ -22,18 +22,29 @@ namespace CarManagerV3.Manager
private static readonly int CacheDurationMinutes = 60;
private static bool cacheIncludesPrerelease = false;
private static readonly string debugVersion = null;//"1.2.0";
private static bool isLatestVersionPrerelease = false;
public static string GetCurrentVersion()
public static string GetCurrentVersion(bool cutTrailingZeros = false)
{
//DEBUG::
if(debugVersion != null)
if (debugVersion != null)
{
return debugVersion;
}
var asm = Assembly.GetEntryAssembly()!;
Version v = asm.GetName().Version ?? new Version(0, 0, 0, 0);
return v.ToString();
string VersionString = v.ToString();
if(cutTrailingZeros)
{
// Remove trailing .0 parts
while (VersionString.EndsWith(".0"))
{
VersionString = VersionString.Substring(0, VersionString.Length - 2);
}
return VersionString;
}
return VersionString;
}
private static bool IsCacheValid(bool includePreRelease = false)
@@ -72,6 +83,7 @@ namespace CarManagerV3.Manager
var content = response.Content.ReadAsStringAsync().Result;
dynamic release = Newtonsoft.Json.JsonConvert.DeserializeObject(content);
latestVersion = release.tag_name;
isLatestVersionPrerelease = false;
}
}
// If pre-release is requested, check for the latest pre-release version
@@ -91,6 +103,7 @@ namespace CarManagerV3.Manager
if (IsNewerVersion(preReleaseVersion, latestVersion))
{
latestVersion = preReleaseVersion;
isLatestVersionPrerelease = true;
}
}
}
@@ -137,11 +150,11 @@ namespace CarManagerV3.Manager
break;
}
}
if (downloadUrl != null)
{
// Download the installer to the users set Data dir, run it, and then exit the application.
string tempFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"CarManagerInstaller_{latestVersion}.msi");
using (var downloadClient = new System.Net.WebClient())
@@ -155,8 +168,8 @@ namespace CarManagerV3.Manager
UseShellExecute = true
};
System.Diagnostics.Process.Start(processStartInfo);
Application.Exit();
}
else
@@ -180,9 +193,9 @@ namespace CarManagerV3.Manager
return IsNewerVersion(latestVersion, currentVersion);
}
public static void openReleasePage(string version = null)
public static void OpenReleasePage(string version = null)
{
if(version == null)
if (version == null)
{
version = GetLatestVersion(true);
}
@@ -193,5 +206,11 @@ namespace CarManagerV3.Manager
UseShellExecute = true
});
}
public static bool IsLatestVersionPrerelease()
{
// Ensure we have the latest version info in cache
return isLatestVersionPrerelease;
}
}
}