XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using XFEWarframe.Client;
using XFEWarframe.Player.ViewModels;

namespace XFEWarframe.Player.Utilities.Diagnostics;

internal static partial class DesktopVerification
{
    private static async Task VerifyInstallerAsync(string reportPath, string game)
    {
        var checks = new List<string>();
        string? error = null;
        try
        {
            var root = Path.GetDirectoryName(Path.GetFullPath(reportPath))! + Path.DirectorySeparatorChar;
            var profile = AppPath.Argument("profile-root") ?? throw new InvalidOperationException("An isolated profile is required.");
            game = Path.GetFullPath(game);
            if (!game.StartsWith(root, StringComparison.OrdinalIgnoreCase) || !Path.GetFullPath(profile).StartsWith(root, StringComparison.OrdinalIgnoreCase))
                throw new InvalidOperationException("Installer verification only writes to copies inside its report directory.");
            await App.Service.InitializeAsync();
            App.Service.State.GameDirectory = game;
            App.Service.State.ServerUrl = "http://127.0.0.1:1";
            var before = await Task.Run(() => Compatibility.Hash(Path.Combine(game, "Warframe.x64.exe")));
            var vm = new InstallPageViewModel();
            for (var attempt = 0; attempt < 2; attempt++)
            {
                await vm.InstallCommand.ExecuteAsync(null);
                if (vm.LastError is not null) throw new InvalidOperationException(vm.LastError);
                if (!App.Service.State.IsInstalled || App.Service.State.IsBusy || !App.Service.State.CompatibilityStatus.Contains("核心连接检查通过", StringComparison.Ordinal))
                    throw new InvalidOperationException("Installation did not finish with a compatible summary.");
                var installed = await Task.Run(() => ClientInstaller.VerifyInstalled(game));
                if (installed.GameSha256 != before || ClientInstaller.ReadState(game)?.Version != ClientInstaller.MinimumBridgeVersion)
                    throw new InvalidOperationException("Installed component or executable hash does not match.");
                checks.Add(attempt == 0 ? "player-install-command-completes-without-ui-thread-errors" : "player-install-command-repairs-existing-installation");
            }
            if (await Task.Run(() => Compatibility.Hash(Path.Combine(game, "Warframe.x64.exe"))) != before)
                throw new InvalidOperationException("Installation changed the executable.");
            checks.Add("game-executable-is-unchanged");
            checks.Add("no-network-or-game-start-needed-for-installation");
        }
        catch (Exception ex) { error = ex.ToString(); }
        Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(reportPath))!);
        await File.WriteAllTextAsync(reportPath, JsonSerializer.Serialize(new { passed = error is null, checks, error }));
    }
}