Restore release version check #7

Merged
sim0n00ps merged 3 commits from whimsical-c4lic0/OF-DL:restore-version-check into master 2025-05-06 21:48:48 +00:00
4 changed files with 112 additions and 13 deletions

View File

@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace OF_DL.Entities;
public class LatestReleaseAPIResponse
{
[JsonProperty(PropertyName = "tag_name")]
public string TagName { get; set; } = "";
}

View File

@ -0,0 +1,52 @@
using Newtonsoft.Json;
using OF_DL.Entities;
using Serilog;
namespace OF_DL.Helpers;
public static class VersionHelper
{
public static string? GetLatestReleaseTag()
{
Log.Debug("Calling GetLatestReleaseTag");
try
{
HttpClient client = new();
HttpRequestMessage request = new(HttpMethod.Get, "https://git.ofdl.tools/api/v1/repos/sim0n00ps/OF-DL/releases/latest");
using var response = client.Send(request);
if (!response.IsSuccessStatusCode)
{
Log.Debug("GetLatestReleaseTag did not return a Success Status Code");
return null;
}
var body = response.Content.ReadAsStringAsync().Result;
Log.Debug("GetLatestReleaseTag API Response: ");
Log.Debug(body);
var versionCheckResponse = JsonConvert.DeserializeObject<LatestReleaseAPIResponse>(body);
if (versionCheckResponse == null || versionCheckResponse.TagName == "")
{
Log.Debug("GetLatestReleaseTag did not return a valid tag name");
return null;
}
return versionCheckResponse.TagName;
}
catch (Exception ex)
{
Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
Log.Error("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
if (ex.InnerException != null)
{
Console.WriteLine("\nInner Exception:");
Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
}
}
return null;
}
}

View File

@ -19,7 +19,6 @@
<PackageReference Include="HtmlAgilityPack" Version="1.12.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="protobuf-net" Version="3.2.46" />
<PackageReference Include="PuppeteerSharp" Version="20.1.3" />
<PackageReference Include="Serilog" Version="4.2.0" />

View File

@ -9,7 +9,6 @@ using OF_DL.Entities.Streams;
using OF_DL.Enumerations;
using OF_DL.Enumurations;
using OF_DL.Helpers;
using Octokit;
using Serilog;
using Serilog.Core;
using Serilog.Events;
@ -281,7 +280,7 @@ public class Program
DownloadDateSelection = Enum.Parse<DownloadDateSelection>(hoconConfig.GetString("Download.DownloadDateSelection"), true),
CustomDate = !string.IsNullOrWhiteSpace(hoconConfig.GetString("Download.CustomDate")) ? DateTime.Parse(hoconConfig.GetString("Download.CustomDate")) : null,
ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"),
DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution")),
DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution", "source")),
// File Settings
PaidPostFileNameFormat = hoconConfig.GetString("File.PaidPostFileNameFormat"),
@ -515,14 +514,54 @@ public class Program
}
}
#if !DEBUG
try
{
// Only run the version check if not in DEBUG mode
#if !DEBUG
Version localVersion = Assembly.GetEntryAssembly()?.GetName().Version; //Only tested with numeric values.
String? latestReleaseTag = VersionHelper.GetLatestReleaseTag();
if (latestReleaseTag == null)
{
AnsiConsole.Markup("[yellow]Failed to verify that OF-DL is up-to-date.\n[/]");
Log.Error("Failed to get the latest release tag.");
}
else
{
Version latestGiteaRelease = new Version(latestReleaseTag.Replace("OFDLV", ""));
// Compare the Versions
int versionComparison = localVersion.CompareTo(latestGiteaRelease);
if (versionComparison < 0)
{
// The version on GitHub is more up to date than this local release.
AnsiConsole.Markup("[red]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]");
AnsiConsole.Markup("[red]Please update to the current release, " + $"{latestGiteaRelease.Major}.{latestGiteaRelease.Minor}.{latestGiteaRelease.Build}: [link]https://git.ofdl.tools/sim0n00ps/OF-DL/releases[/]\n[/]");
Log.Debug("Detected outdated client running version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}");
Log.Debug("Latest release version " + $"{latestGiteaRelease.Major}.{latestGiteaRelease.Minor}.{latestGiteaRelease.Build}");
}
else
{
// This local version is greater than the release version on GitHub.
AnsiConsole.Markup("[green]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]");
AnsiConsole.Markup("[green]Latest Release version: " + $"{latestGiteaRelease.Major}.{latestGiteaRelease.Minor}.{latestGiteaRelease.Build}\n[/]");
Log.Debug("Detected client running version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}");
Log.Debug("Latest release version " + $"{latestGiteaRelease.Major}.{latestGiteaRelease.Minor}.{latestGiteaRelease.Build}");
}
}
#else
AnsiConsole.Markup("[yellow]Running in Debug/Local mode. Version check skipped.\n[/]");
Log.Debug("Running in Debug/Local mode. Version check skipped.");
#endif
}
catch (Exception e)
{
AnsiConsole.Markup("[red]Error checking latest release on GitHub:\n[/]");
Console.WriteLine(e);
Log.Error("Error checking latest release on GitHub.", e.Message);
}
AnsiConsole.Markup("[red]You are running OF-DL version " + $"{localVersion.Major}.{localVersion.Minor}.{localVersion.Build}\n[/]");
#else
AnsiConsole.Markup("[yellow]Running in Debug/Local mode. Version check skipped.\n[/]");
Log.Debug("Running in Debug/Local mode. Version check skipped.");
#endif
if (File.Exists("auth.json"))
{
@ -541,7 +580,7 @@ public class Program
Log.Debug("Deleting auth.json");
File.Delete("auth.json");
}
if (cliNonInteractive)
{
AnsiConsole.MarkupLine($"\n[red]auth.json has invalid JSON syntax. The file can be generated automatically when OF-DL is run in the standard, interactive mode.[/]\n");
@ -1646,7 +1685,7 @@ public class Program
{
archived = await downloadContext.ApiHelper.GetArchived($"/users/{user.Value}/posts", path, downloadContext.DownloadConfig!, ctx);
});
int oldArchivedCount = 0;
int newArchivedCount = 0;
if (archived != null && archived.ArchivedPosts.Count > 0)
@ -1779,7 +1818,7 @@ public class Program
{
posts = await downloadContext.ApiHelper.GetPosts($"/users/{user.Value}/posts", path, downloadContext.DownloadConfig!, paid_post_ids, ctx);
});
int oldPostCount = 0;
int newPostCount = 0;
if (posts == null || posts.Posts.Count <= 0)
@ -2301,7 +2340,7 @@ public class Program
{
streams = await downloadContext.ApiHelper.GetStreams($"/users/{user.Value}/posts/streams", path, downloadContext.DownloadConfig!, paid_post_ids, ctx);
});
int oldStreamsCount = 0;
int newStreamsCount = 0;
if (streams == null || streams.Streams.Count <= 0)