Restore release version check #7
9
OF DL/Entities/LatestReleaseAPIResponse.cs
Normal file
9
OF DL/Entities/LatestReleaseAPIResponse.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace OF_DL.Entities;
|
||||||
|
|
||||||
|
public class LatestReleaseAPIResponse
|
||||||
|
{
|
||||||
|
[JsonProperty(PropertyName = "tag_name")]
|
||||||
|
public string TagName { get; set; } = "";
|
||||||
|
}
|
52
OF DL/Helpers/VersionHelper.cs
Normal file
52
OF DL/Helpers/VersionHelper.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,6 @@
|
|||||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.0" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.12.0" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.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="protobuf-net" Version="3.2.46" />
|
||||||
<PackageReference Include="PuppeteerSharp" Version="20.1.3" />
|
<PackageReference Include="PuppeteerSharp" Version="20.1.3" />
|
||||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||||
|
@ -9,7 +9,6 @@ using OF_DL.Entities.Streams;
|
|||||||
using OF_DL.Enumerations;
|
using OF_DL.Enumerations;
|
||||||
using OF_DL.Enumurations;
|
using OF_DL.Enumurations;
|
||||||
using OF_DL.Helpers;
|
using OF_DL.Helpers;
|
||||||
using Octokit;
|
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
@ -281,7 +280,7 @@ public class Program
|
|||||||
DownloadDateSelection = Enum.Parse<DownloadDateSelection>(hoconConfig.GetString("Download.DownloadDateSelection"), true),
|
DownloadDateSelection = Enum.Parse<DownloadDateSelection>(hoconConfig.GetString("Download.DownloadDateSelection"), true),
|
||||||
CustomDate = !string.IsNullOrWhiteSpace(hoconConfig.GetString("Download.CustomDate")) ? DateTime.Parse(hoconConfig.GetString("Download.CustomDate")) : null,
|
CustomDate = !string.IsNullOrWhiteSpace(hoconConfig.GetString("Download.CustomDate")) ? DateTime.Parse(hoconConfig.GetString("Download.CustomDate")) : null,
|
||||||
ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"),
|
ShowScrapeSize = hoconConfig.GetBoolean("Download.ShowScrapeSize"),
|
||||||
DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution")),
|
DownloadVideoResolution = ParseVideoResolution(hoconConfig.GetString("Download.DownloadVideoResolution", "source")),
|
||||||
|
|
||||||
// File Settings
|
// File Settings
|
||||||
PaidPostFileNameFormat = hoconConfig.GetString("File.PaidPostFileNameFormat"),
|
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.
|
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"))
|
if (File.Exists("auth.json"))
|
||||||
{
|
{
|
||||||
@ -541,7 +580,7 @@ public class Program
|
|||||||
Log.Debug("Deleting auth.json");
|
Log.Debug("Deleting auth.json");
|
||||||
File.Delete("auth.json");
|
File.Delete("auth.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cliNonInteractive)
|
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");
|
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);
|
archived = await downloadContext.ApiHelper.GetArchived($"/users/{user.Value}/posts", path, downloadContext.DownloadConfig!, ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
int oldArchivedCount = 0;
|
int oldArchivedCount = 0;
|
||||||
int newArchivedCount = 0;
|
int newArchivedCount = 0;
|
||||||
if (archived != null && archived.ArchivedPosts.Count > 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);
|
posts = await downloadContext.ApiHelper.GetPosts($"/users/{user.Value}/posts", path, downloadContext.DownloadConfig!, paid_post_ids, ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
int oldPostCount = 0;
|
int oldPostCount = 0;
|
||||||
int newPostCount = 0;
|
int newPostCount = 0;
|
||||||
if (posts == null || posts.Posts.Count <= 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);
|
streams = await downloadContext.ApiHelper.GetStreams($"/users/{user.Value}/posts/streams", path, downloadContext.DownloadConfig!, paid_post_ids, ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
int oldStreamsCount = 0;
|
int oldStreamsCount = 0;
|
||||||
int newStreamsCount = 0;
|
int newStreamsCount = 0;
|
||||||
if (streams == null || streams.Streams.Count <= 0)
|
if (streams == null || streams.Streams.Count <= 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user