Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 5, 2025
2 parents 1fe626b + 28133af commit 0e1ac95
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/NoMercy.NmSystem/AppFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static class AppFiles
public static readonly string FfmpegPath = Path.Combine(FfmpegFolder, "ffmpeg" + Info.ExecSuffix);
public static readonly string FfProbePath = Path.Combine(FfmpegFolder, "ffprobe" + Info.ExecSuffix);
public static readonly string FpCalcPath = Path.Combine(BinariesPath, "fpcalc", "fpcalc" + Info.ExecSuffix);

public static string UpdaterPath => Path.Combine(BinariesPath, "NoMercyUpdater" + Info.ExecSuffix);

public static readonly string SubtitleEdit =
Path.Combine(BinariesPath, "subtitleedit", "SubtitleEdit" + Info.ExecSuffix);

Expand Down
4 changes: 0 additions & 4 deletions src/NoMercy.NmSystem/NoMercy.NmSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@
<ItemGroup>
<EmbeddedResource Include="Resources\I18N.xml" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NoMercy.Updater\NoMercy.Updater.csproj" />
</ItemGroup>
</Project>
22 changes: 19 additions & 3 deletions src/NoMercy.NmSystem/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Diagnostics;
using NoMercy.Updater;
using Newtonsoft.Json;

namespace NoMercy.NmSystem;

Expand All @@ -12,7 +12,7 @@ public static Task StartPeriodicUpdateCheck()
while (true)
{
await Task.Delay(TimeSpan.FromHours(6));
Config.UpdateAvailable = await NoMercyUpdater.CheckForUpdate();
Config.UpdateAvailable = IsUpdateAvailable();
}

// ReSharper disable once FunctionNeverReturns
Expand All @@ -25,7 +25,23 @@ public static bool IsUpdateAvailable()
{
try
{
return NoMercyUpdater.CheckForUpdate().Result;
ProcessStartInfo startInfo = new()
{
FileName = AppFiles.UpdaterPath,
Arguments = "--check",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};

using Process? process = Process.Start(startInfo);
string? output = process?.StandardOutput.ReadToEnd();
process?.WaitForExit();

if (string.IsNullOrEmpty(output)) return false;

UpdateCheckResult? result = JsonConvert.DeserializeObject<UpdateCheckResult>(output);
return result?.UpdateAvailable ?? false;
}
catch
{
Expand Down
3 changes: 1 addition & 2 deletions src/NoMercy.Server/NoMercy.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
<Authors>NoMercy Entertainment</Authors>
<Description>The Effortless Encoder</Description>
<Copyright>(c) 2023 NoMercy Entertainment</Copyright>
<Copyright>(c) 2025 NoMercy Entertainment</Copyright>
<PackageProjectUrl>https://nomercy.tv</PackageProjectUrl>
<PackageIcon>Assets\icon.png</PackageIcon>
<Company>NoMercy Entertainment</Company>
Expand Down Expand Up @@ -80,7 +80,6 @@
<ProjectReference Include="..\NoMercy.MediaProcessing\NoMercy.MediaProcessing.csproj"/>
<ProjectReference Include="..\NoMercy.Networking\NoMercy.Networking.csproj"/>
<ProjectReference Include="..\NoMercy.Providers\NoMercy.Providers.csproj"/>
<ProjectReference Include="..\NoMercy.Updater\NoMercy.Updater.csproj"/>
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion src/NoMercy.Updater/NoMercy.Updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<!-- <RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>-->
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
<Authors>NoMercy Entertainment</Authors>
<Description>The Effortless Encoder</Description>
<Copyright>(c) 2023 NoMercy Entertainment</Copyright>
<Copyright>(c) 2025 NoMercy Entertainment</Copyright>
<PackageProjectUrl>https://nomercy.tv</PackageProjectUrl>
<PackageIcon>Assets\icon.png</PackageIcon>
<Company>NoMercy Entertainment</Company>
Expand All @@ -31,6 +32,10 @@
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
Expand Down
27 changes: 19 additions & 8 deletions src/NoMercy.Updater/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Diagnostics;
using System.Text.Json;
using Newtonsoft.Json;

namespace NoMercy.Updater;

Expand All @@ -15,9 +15,9 @@ static async Task Main(string[] args)
if (args.Length > 0 && args[0] == "--check")
{
bool isUpdateAvailable = await CheckForUpdate();
Console.WriteLine(JsonSerializer.Serialize(new
Console.WriteLine(JsonConvert.SerializeObject(new
{
updateAvailable = isUpdateAvailable
UpdateAvailable = isUpdateAvailable
}));
return;
}
Expand Down Expand Up @@ -90,21 +90,32 @@ private static string GetInstalledCommitHash()
: "unknown";
}

private class Release
{
[JsonProperty("assets")] public List<Asset> Assets { get; set; } = [];
}

private class Asset
{
[JsonProperty("name")] public string Name { get; set; } = "";
[JsonProperty("browser_download_url")] public string DownloadUrl { get; set; } = "";
}

private static async Task<(string commitHash, string? downloadUrl)> GetLatestReleaseInfo(string? osIdentifier)
{
string url = $"https://api.github.com/repos/{RepoOwner}/{RepoName}/releases/latest";
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0");

string response = await HttpClient.GetStringAsync(url);
using JsonDocument doc = JsonDocument.Parse(response);
Release? doc = JsonConvert.DeserializeObject<Release>(response);

foreach (JsonElement asset in doc.RootElement.GetProperty("assets").EnumerateArray())
foreach (Asset asset in doc?.Assets ?? [])
{
string? fileName = asset.GetProperty("name").GetString();
if (fileName == null || osIdentifier == null || !fileName.Contains(osIdentifier)) continue;
string fileName = asset.Name;
if (osIdentifier == null || !fileName.Contains(osIdentifier)) continue;

string commitHash = fileName.Split('-')[^1].Replace(".exe", "").Trim();
string? downloadUrl = asset.GetProperty("browser_download_url").GetString();
string downloadUrl = asset.DownloadUrl;
return (commitHash, downloadUrl);
}
return ("unknown", null);
Expand Down

0 comments on commit 0e1ac95

Please sign in to comment.