test: verify published release from launcher runtime

This commit is contained in:
Coldsmile_7 committed 2026-10-25 23:06:28 +08:00
1 parent 3ef14b65fe
commit 5d549ff66a
1 file changed
+11 -1
+11 -1
View File
@@ -2,6 +2,9 @@ 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.
@@ -13,8 +16,11 @@ internal static class CheckLauncherRelease {
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 = module.GetMethod("GetLatestLauncherUpdate", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
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);
@@ -32,6 +38,10 @@ internal static class CheckLauncherRelease {
}
}
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) {