53 lines
3.1 KiB
C#
53 lines
3.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
|
|
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
|
|
|
|
// Run under .NET Framework after compiling with the framework's csc.exe.
|
|
// Uses the launcher's real release API parser without starting its main window.
|
|
internal static class CheckLauncherRelease {
|
|
[STAThread]
|
|
private static int Main(string[] args) {
|
|
try {
|
|
Assembly launcher = Assembly.LoadFrom(Path.GetFullPath(args[0]));
|
|
Activator.CreateInstance(launcher.GetType("PCL.Application", true), true);
|
|
Assembly core = Assembly.Load("MeloongCore");
|
|
core.GetType("MeloongCore.Main", true).GetMethod("Init").Invoke(null, new object[] { "PCL" });
|
|
// Initialize the launcher's UI-thread identity on the main thread,
|
|
// as normal application startup does, before starting network work.
|
|
launcher.GetType("PCL.ModBase", true).GetMethod("RunInUi", Type.EmptyTypes).Invoke(null, null);
|
|
Type module = launcher.GetType("PCL.ModSecret", true);
|
|
object info = Task.Run(() => module.GetMethod("GetLatestLauncherUpdate", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null)).GetAwaiter().GetResult();
|
|
Type infoType = info.GetType();
|
|
string tag = (string)infoType.GetField("TagName").GetValue(info);
|
|
string hash = (string)infoType.GetField("AssetHash").GetValue(info);
|
|
string url = (string)infoType.GetField("DownloadUrl").GetValue(info);
|
|
string version = infoType.GetField("VersionNumber").GetValue(info).ToString();
|
|
Console.WriteLine("Release: " + tag + ", version: " + version);
|
|
Console.WriteLine("Asset: " + url);
|
|
Console.WriteLine("SHA256: " + hash);
|
|
if (args.Length > 1) {
|
|
using (SHA256 sha = SHA256.Create())
|
|
using (Stream file = File.OpenRead(args[1])) {
|
|
string expected = BitConverter.ToString(sha.ComputeHash(file)).Replace("-", "");
|
|
if (!expected.Equals(hash, StringComparison.OrdinalIgnoreCase))
|
|
throw new InvalidDataException("Release SHA256 does not match local build");
|
|
}
|
|
}
|
|
if (tag != "v0.1.1" || version != "0.1.1.0") throw new InvalidDataException("Unexpected test release version");
|
|
bool newer = (bool)module.GetMethod("IsUpdateNewer", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { info });
|
|
bool expectedNewer = new Version(version) > launcher.GetName().Version;
|
|
if (newer != expectedNewer) throw new InvalidDataException("Unexpected update comparison result");
|
|
Console.WriteLine("Installed: " + launcher.GetName().Version + ", update offered: " + newer);
|
|
Console.WriteLine("PASS: launcher resolves published test release and checksum");
|
|
return 0;
|
|
} catch (Exception ex) {
|
|
Console.Error.WriteLine(ex.ToString());
|
|
return 1;
|
|
}
|
|
}
|
|
}
|