Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,4 @@ fabric.properties
# *.ipr

### Custom ###
ShinRyuModManager-CE/Properties/launchSettings.json
launchSettings.json
42 changes: 42 additions & 0 deletions RyuUpdater/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Diagnostics;
using System.IO.Compression;

namespace RyuUpdater;

public static class Program {
private static async Task Main(string[] args) {
if (args.Length == 0) {
Console.WriteLine("This is a helper application for SRMM. Please don't run manually!\nPress any key to exit...");
Console.ReadKey();

return;
}

var pid = int.Parse(args[0]);
var updateFile = args[1];
var targetDir = args[2];
var srmmFileName = args[3];

var tempDir = new FileInfo(updateFile).Directory!.FullName;

try {
if (pid != -1) {
await Process.GetProcessById(pid).WaitForExitAsync();
}
} catch {
// ignore
}

await Task.Delay(500);

ZipFile.ExtractToDirectory(updateFile, targetDir, overwriteFiles: true);
Directory.Delete(tempDir, recursive: true);

var srmmPath = Path.Combine(targetDir, srmmFileName);

Process.Start(new ProcessStartInfo {
FileName = srmmPath,
UseShellExecute = true
});
}
}
10 changes: 10 additions & 0 deletions RyuUpdater/Properties/launchSettings.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"RyuUpdater": {
"commandName": "Project",
"commandLineArgs": "<SRMM PID> <ZipFilePath> <TempDir> <SRMMFileName>",
"workingDirectory": "" // Path to folder containing exe
}
}
}
21 changes: 21 additions & 0 deletions RyuUpdater/RyuUpdater.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net8.0-windows</TargetFrameworks>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Configurations>Debug;Release</Configurations>
<Platforms>x64</Platforms>
<IsPackable>false</IsPackable>
<ApplicationIcon>..\ShinRyuModManager-CE\UserInterface\Assets\Icons\SRMM_icon.ico</ApplicationIcon>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<AssemblyVersion>1.0.0</AssemblyVersion>
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>
<Version>$(AssemblyVersion)</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions ShinRyuModManager-CE.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParLibrary.Tests", "ParLibr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{7F2462E1-FB0A-4BFA-BBF9-91CD9DB1FC56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RyuUpdater", "RyuUpdater\RyuUpdater.csproj", "{FDE3D69A-37FA-4187-9CAE-07EA4382D8A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -30,5 +32,9 @@ Global
{7F2462E1-FB0A-4BFA-BBF9-91CD9DB1FC56}.Debug|x64.Build.0 = Debug|x64
{7F2462E1-FB0A-4BFA-BBF9-91CD9DB1FC56}.Release|x64.ActiveCfg = Release|x64
{7F2462E1-FB0A-4BFA-BBF9-91CD9DB1FC56}.Release|x64.Build.0 = Release|x64
{FDE3D69A-37FA-4187-9CAE-07EA4382D8A6}.Debug|x64.ActiveCfg = Debug|Any CPU
{FDE3D69A-37FA-4187-9CAE-07EA4382D8A6}.Debug|x64.Build.0 = Debug|Any CPU
{FDE3D69A-37FA-4187-9CAE-07EA4382D8A6}.Release|x64.ActiveCfg = Release|Any CPU
{FDE3D69A-37FA-4187-9CAE-07EA4382D8A6}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion ShinRyuModManager-CE/ShinRyuModManager-CE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>

<!-- Versioning -->
<AssemblyVersion>1.1.12</AssemblyVersion>
<AssemblyVersion>1.2.0</AssemblyVersion>
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
Expand Down Expand Up @@ -45,6 +45,7 @@
<PackageReference Include="ini-parser" Version="2.5.2" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="NetSparkleUpdater.UI.Avalonia" Version="3.0.4" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
Expand Down
5 changes: 5 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Assets/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
> ### **%{color:orange} Version 1.2.0 %** ###
* Added auto updater

---

> ### **%{color:orange} Version 1.1.12 %** ###
* Minor Cleanup
* Updated libraries
Expand Down
86 changes: 86 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Updater/AutoUpdating.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.IO.Compression;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using NetSparkleUpdater;
using NetSparkleUpdater.Enums;
using NetSparkleUpdater.SignatureVerifiers;
using NetSparkleUpdater.UI.Avalonia;
using Serilog;
using Utils;

namespace ShinRyuModManager.UserInterface.Updater;

public static class AutoUpdating {
private const string GH_PAGES_ROOT = "https://thetruecolonel.github.io/SRMM-AppCast";

private static string _tempDir;
private static SparkleUpdater _updater;

public static void Init() {
_tempDir = Path.Combine(Environment.CurrentDirectory, "srmm_temp");

try {
HandleRyuUpdater();
} catch (Exception ex) {
Log.Error(ex, "Problem trying to download RyuUpdater! Aborting auto updating...");

return;
}

var suffix = AssemblyVersion.GetBuildSuffix();

if (string.Equals(suffix, "debug", StringComparison.OrdinalIgnoreCase)) {
return; // Don't need to be annoyed with "Update Now" when debugging
}

var appcastUrl = $"{GH_PAGES_ROOT}/releases/appcast_{suffix}.xml";

// Update check for SRMM
_updater = new PortableUpdater(appcastUrl, new Ed25519Checker(SecurityMode.Unsafe)) {
UIFactory = new UIFactory {
HideReleaseNotes = true,
UseStaticUpdateWindowBackgroundColor = true,
UpdateWindowGridBackgroundBrush = new ImmutableSolidColorBrush(Color.Parse("#373535"))
},
TmpDownloadFilePath = _tempDir,
TmpDownloadFileNameWithExtension = $"{Guid.NewGuid()}.zip",
RelaunchAfterUpdate = false,
LogWriter = new SerilogWriter()
};

_ = _updater.StartLoop(true, TimeSpan.FromMinutes(5));
}

private static void HandleRyuUpdater() {
string ryuUpdaterPath;
string updaterAppcastUrl;
string updaterLatestUrl;

if (OperatingSystem.IsWindows()) {
ryuUpdaterPath = Path.Combine(Environment.CurrentDirectory, "RyuUpdater.exe");
updaterAppcastUrl = $"{GH_PAGES_ROOT}/releases/appcast_ryuupdater-windows.xml";
updaterLatestUrl = $"{GH_PAGES_ROOT}/updater/RyuUpdater-Windows-Latest.zip";
} else {
ryuUpdaterPath = Path.Combine(Environment.CurrentDirectory, "RyuUpdater");
updaterAppcastUrl = $"{GH_PAGES_ROOT}/releases/appcast_ryuupdater-linux.xml";
updaterLatestUrl = $"{GH_PAGES_ROOT}/updater/RyuUpdater-Linux-Latest.zip";
}

// Pull grab latest version of updater if missing
if (!File.Exists(ryuUpdaterPath)) {
using var downloadStream = Utils.Client.GetStreamAsync(updaterLatestUrl).GetAwaiter().GetResult();

ZipFile.ExtractToDirectory(downloadStream, Environment.CurrentDirectory, overwriteFiles: true);
}

// TODO: Linux doesn't store the required information for this to work on compiled binaries. To come back to.
/*// Update RyuUpdater quietly
var ryuUpdater = new RyuUpdaterUpdater(updaterAppcastUrl, new Ed25519Checker(SecurityMode.Unsafe), ryuUpdaterPath) {
UserInteractionMode = UserInteractionMode.DownloadAndInstall,
UIFactory = null,
TmpDownloadFilePath = _tempDir,
TmpDownloadFileNameWithExtension = $"{Guid.NewGuid()}.zip"
};
_ = ryuUpdater.StartLoop(true);*/
}
}
33 changes: 33 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Updater/PortableUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics;
using NetSparkleUpdater;
using NetSparkleUpdater.Interfaces;

namespace ShinRyuModManager.UserInterface.Updater;

public sealed class PortableUpdater : SparkleUpdater {
public PortableUpdater(string appcastUrl, ISignatureVerifier signatureVerifier) : base(appcastUrl, signatureVerifier) { }

protected override Task RunDownloadedInstaller(string downloadFilePath) {
var ryuPath = Path.Combine(Environment.CurrentDirectory, "RyuUpdater");

using var currentProcess = Process.GetCurrentProcess();

var pid = Environment.ProcessId;
var name = currentProcess.ProcessName;

Process.Start(new ProcessStartInfo {
FileName = ryuPath,
ArgumentList = {
pid.ToString(),
downloadFilePath,
Environment.CurrentDirectory,
name
},
UseShellExecute = false,
});

Environment.Exit(0x55504454); //UPDT

return Task.CompletedTask;
}
}
17 changes: 17 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Updater/RyuUpdaterUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.IO.Compression;
using NetSparkleUpdater;
using NetSparkleUpdater.Interfaces;

namespace ShinRyuModManager.UserInterface.Updater;

public class RyuUpdaterUpdater : SparkleUpdater {
public RyuUpdaterUpdater(string appcastUrl, ISignatureVerifier signatureVerifier) : base(appcastUrl, signatureVerifier) { }
public RyuUpdaterUpdater(string appcastUrl, ISignatureVerifier signatureVerifier, string referenceAssembly) : base(appcastUrl, signatureVerifier, referenceAssembly, null) { }
public RyuUpdaterUpdater(string appcastUrl, ISignatureVerifier signatureVerifier, string referenceAssembly, IUIFactory factory) : base(appcastUrl, signatureVerifier, referenceAssembly, factory) { }

protected override Task RunDownloadedInstaller(string downloadFilePath) {
ZipFile.ExtractToDirectory(downloadFilePath, Environment.CurrentDirectory, overwriteFiles: true);

return Task.CompletedTask;
}
}
12 changes: 12 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Updater/SerilogWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Serilog;
using ILogger = NetSparkleUpdater.Interfaces.ILogger;

namespace ShinRyuModManager.UserInterface.Updater;

public class SerilogWriter : ILogger {
public void PrintMessage(string message, params object[] arguments) {
#pragma warning disable CA2254
Log.Information(message, arguments);
#pragma warning restore CA2254
}
}
3 changes: 3 additions & 0 deletions ShinRyuModManager-CE/UserInterface/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Serilog.Events;
using ShinRyuModManager.Helpers;
using ShinRyuModManager.ModLoadOrder.Mods;
using ShinRyuModManager.UserInterface.Updater;
using ShinRyuModManager.UserInterface.ViewModels;
using Utils;
using YamlDotNet.Core;
Expand All @@ -23,6 +24,8 @@ public partial class MainWindow : Window {

public MainWindow() {
InitializeComponent();

AutoUpdating.Init();
}

private void Window_OnLoaded(object sender, RoutedEventArgs e) {
Expand Down
16 changes: 13 additions & 3 deletions Utils/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ public static class AssemblyVersion {
/// </summary>
/// <returns>A <see cref="string"/>.</returns>
public static string GetVersion() {
var version = Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;

return version;
return Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
}

public static string GetBuildVersion() {
var fullVersion = GetVersion();

return fullVersion[..(fullVersion.IndexOf('-'))];
}

public static string GetBuildSuffix() {
var fullVersion = GetVersion();

return fullVersion[(fullVersion.IndexOf('-') + 1)..];
}
}
2 changes: 1 addition & 1 deletion Utils/GamePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class GamePath {
public static string GameExe { get; }

static GamePath() {
FullGamePath = Directory.GetCurrentDirectory();
FullGamePath = Environment.CurrentDirectory;
DataPath = Path.Combine(FullGamePath, DATA);
ModsPath = Path.Combine(FullGamePath, MODS);
ExternalModsPath = Path.Combine(ModsPath, Constants.EXTERNAL_MODS);
Expand Down
Loading