-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- update to .net 9
- Loading branch information
Showing
12 changed files
with
279 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Cursor_Installer_Creator.Data; | ||
|
||
public sealed class Version | ||
{ | ||
public int Major { get; set; } = -1; | ||
public int Minor { get; set; } = -1; | ||
public int Patch { get; set; } = -1; | ||
public bool IsPrerelease { get; set; } | ||
|
||
public Version() { } | ||
|
||
public Version(int major, int minor, int patch, bool isPrerelease = false) | ||
{ | ||
Major = major; | ||
Minor = minor; | ||
Patch = patch; | ||
IsPrerelease = isPrerelease; | ||
} | ||
|
||
public Version(string? version) | ||
{ | ||
if (string.IsNullOrWhiteSpace(version)) | ||
return; | ||
|
||
version = version.ToLower(); | ||
version = version.TrimStart('v'); | ||
|
||
var parts = version.Split('-'); | ||
IsPrerelease = parts.Length > 1; | ||
|
||
var versionParts = parts[0].Split('.').Select(int.Parse).ToArray(); | ||
Major = versionParts[0]; | ||
Minor = versionParts[1]; | ||
Patch = versionParts[2]; | ||
} | ||
|
||
public override string ToString() => IsPrerelease ? $"{Major}.{Minor}.{Patch}-alpha" : $"{Major}.{Minor}.{Patch}"; | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
if (obj is Version otherVersion) | ||
{ | ||
return Major == otherVersion.Major | ||
&& Minor == otherVersion.Minor | ||
&& Patch == otherVersion.Patch | ||
&& IsPrerelease == otherVersion.IsPrerelease; | ||
} | ||
return base.Equals(obj); | ||
} | ||
|
||
public override int GetHashCode() => HashCode.Combine(Major, Minor, Patch, IsPrerelease); | ||
|
||
public static bool operator >(Version v1, Version v2) | ||
{ | ||
if (v1.Major != v2.Major) | ||
return v1.Major > v2.Major; | ||
if (v1.Minor != v2.Minor) | ||
return v1.Minor > v2.Minor; | ||
if (v1.Patch != v2.Patch) | ||
return v1.Patch > v2.Patch; | ||
return !v1.IsPrerelease && v2.IsPrerelease; | ||
} | ||
|
||
public static bool operator <(Version v1, Version v2) | ||
{ | ||
return !(v1 > v2) && !v1.Equals(v2); | ||
} | ||
|
||
public static bool operator >=(Version v1, Version v2) | ||
{ | ||
return v1 > v2 || v1.Equals(v2); | ||
} | ||
|
||
public static bool operator <=(Version v1, Version v2) | ||
{ | ||
return v1 < v2 || v1.Equals(v2); | ||
} | ||
|
||
public static Version operator +(Version v1, Version v2) | ||
{ | ||
return new Version( | ||
v1.Major + v2.Major, | ||
v1.Minor + v2.Minor, | ||
v1.Patch + v2.Patch, | ||
v1.IsPrerelease || v2.IsPrerelease | ||
); | ||
} | ||
|
||
public static Version operator -(Version v1, Version v2) | ||
{ | ||
return new Version( | ||
Math.Max(v1.Major - v2.Major, 0), | ||
Math.Max(v1.Minor - v2.Minor, 0), | ||
Math.Max(v1.Patch - v2.Patch, 0), | ||
v1.IsPrerelease | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Cursor_Installer_Creator.Data; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace Cursor_Installer_Creator.Utils; | ||
|
||
public sealed class GitHubUpdater | ||
{ | ||
public const string RepoOwner = "Der-Floh"; | ||
public const string RepoName = "Cursor-Installer-Creator"; | ||
|
||
public static Version CurrentVersion { get; } = new Version(2, 1, 0); | ||
public static string RepoUrl => $"https://github.com/{RepoOwner}/{RepoName}"; | ||
public static string LatestReleaseUrl => $"https://github.com/{RepoOwner}/{RepoName}/releases/latest"; | ||
|
||
private static readonly HttpClient _client = new HttpClient(); | ||
|
||
public static async Task<bool> HasUpdateAsync() | ||
{ | ||
try | ||
{ | ||
// GitHub API endpoint for the latest release | ||
var url = $"https://api.github.com/repos/{RepoOwner}/{RepoName}/releases/latest"; | ||
_client.DefaultRequestHeaders.UserAgent.ParseAdd(RepoName.Replace('-', '_')); | ||
|
||
// Fetch latest release | ||
var response = await _client.GetAsync(url); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
// Deserialize response | ||
var jsonString = await response.Content.ReadAsStringAsync(); | ||
var jsonDocument = JsonDocument.Parse(jsonString); | ||
var latestVersionString = jsonDocument.RootElement.GetProperty("tag_name").GetString(); | ||
var latestVersion = new Version(latestVersionString); | ||
|
||
// Compare versions | ||
return latestVersion > CurrentVersion; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.