From 7f2849e5fd6f89b1bc791e081dab8872d53ed402 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Tue, 6 May 2025 15:56:55 -0500 Subject: [PATCH 1/3] Restore version check using gitea API --- OF DL/Entities/LatestReleaseAPIResponse.cs | 9 ++++ OF DL/Helpers/VersionHelper.cs | 52 +++++++++++++++++++++ OF DL/OF DL.csproj | 1 - OF DL/Program.cs | 53 +++++++++++++++++++--- 4 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 OF DL/Entities/LatestReleaseAPIResponse.cs create mode 100644 OF DL/Helpers/VersionHelper.cs diff --git a/OF DL/Entities/LatestReleaseAPIResponse.cs b/OF DL/Entities/LatestReleaseAPIResponse.cs new file mode 100644 index 0000000..1081765 --- /dev/null +++ b/OF DL/Entities/LatestReleaseAPIResponse.cs @@ -0,0 +1,9 @@ +using Newtonsoft.Json; + +namespace OF_DL.Entities; + +public class LatestReleaseAPIResponse +{ + [JsonProperty(PropertyName = "tag_name")] + public string TagName { get; set; } = ""; +} diff --git a/OF DL/Helpers/VersionHelper.cs b/OF DL/Helpers/VersionHelper.cs new file mode 100644 index 0000000..c21d835 --- /dev/null +++ b/OF DL/Helpers/VersionHelper.cs @@ -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(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; + } +} diff --git a/OF DL/OF DL.csproj b/OF DL/OF DL.csproj index 8b35a6e..20dc207 100644 --- a/OF DL/OF DL.csproj +++ b/OF DL/OF DL.csproj @@ -19,7 +19,6 @@ - diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 14b8820..67580f7 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -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; @@ -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")) { -- 2.43.0 From 44890f51ee18fc036dca067a6576b493c84a7f01 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Tue, 6 May 2025 15:57:03 -0500 Subject: [PATCH 2/3] Add default value to video resolution config option --- OF DL/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 67580f7..bac1b0d 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -280,7 +280,7 @@ public class Program DownloadDateSelection = Enum.Parse(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"), -- 2.43.0 From 6a42dbe53eaeadaaf69c3d8950c6f5f7a279e1d3 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Tue, 6 May 2025 15:57:09 -0500 Subject: [PATCH 3/3] Remove whitespace --- OF DL/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OF DL/Program.cs b/OF DL/Program.cs index bac1b0d..b47be8c 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -580,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"); @@ -1685,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) @@ -1818,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) @@ -2340,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) -- 2.43.0