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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using XFEEDToolBox.Core.Navigation;
using XFEEDToolBox.Views;

namespace XFEEDToolBox;

public partial class App
{
    // Explicit route-only integration test of the actual page command. Never
    // invokes StartNavigationCommand, flight inputs or any Journal/file writes.
    private static async Task RunGameRouteAcceptanceAsync(string[] args,string reportPath)
    {
        if(File.Exists(reportPath))throw new IOException("Use a new game route acceptance report path.");
        var target=GetArgument(args,"--accept-destination")??throw new ArgumentException("An explicit game-route destination is required.");
        var started=DateTimeOffset.UtcNow;var initial=Runtime.Player;var rounds=new List<object>();string? failure=null;var passed=false;
        try
        {
            ViewModel.DemoMode=false;ViewModel.NavigationDestination=target;AppShellPage.Current!.Navigate(typeof(NavigationPage));
            var count=args.Contains("--accept-replan")?2:1;
            for(var i=0;i<count;i++)
            {
                var previous=Runtime.Player.Navigation.Route;
                await ViewModel.PlanNavigationCommand.ExecuteAsync(null);
                var current=Runtime.Player;var route=current.Navigation.Route;
                if(Runtime.FlightDriver is not NativeFlightControlDriver driver)throw new InvalidOperationException("Native game route driver unavailable.");
                var native=await new NavigationPipeClient(driver.ProcessId).CallAsync(new{op="read"});
                var fsd=native.GetProperty("fsd");
                var valid=ViewModel.NavigationStatusSeverity==InfoBarSeverity.Success&&ViewModel.NavigationRouteMatches
                    &&route.Count>=2&&route[^1].Name.Equals(target,StringComparison.OrdinalIgnoreCase)
                    &&ViewModel.LastConfirmedGameRoute?.NativeRouteFingerprint==GameRouteFingerprint.Compute(route)
                    &&fsd.GetProperty("targetValid").GetBoolean()&&fsd.GetProperty("targetAddress").GetString()==ViewModel.NavigationLegs.First(r=>r.Record.Next).Record.SystemAddress.ToString(System.Globalization.CultureInfo.InvariantCulture)
                    &&current.Navigation.CurrentSystemAddress==initial.Navigation.CurrentSystemAddress&&current.Navigation.LastJumpAt==initial.Navigation.LastJumpAt
                    &&!fsd.GetProperty("ownedCharging").GetBoolean()&&!native.GetProperty("controlApplied").GetBoolean();
                rounds.Add(new{round=i+1,valid,ViewModel.NavigationStatus,ViewModel.NavigationRouteSummary,waypoints=route.Count,route=current.Navigation.Route,
                    routeChanged=!ReferenceEquals(previous,route),nativeFullRouteFingerprint=ViewModel.LastConfirmedGameRoute?.NativeRouteFingerprint,gameProcessId=driver.ProcessId,nativeFsd=fsd,controlApplied=native.GetProperty("controlApplied"),
                    current.Navigation.CurrentSystemAddress,current.Navigation.LastJumpAt});
                if(!valid)throw new InvalidOperationException("Game route page command acceptance failed: "+ViewModel.NavigationStatus);
                await Task.Delay(1250);
            }
            passed=true;
        }
        catch(Exception error){failure=error.ToString();}
        await File.WriteAllTextAsync(reportPath,JsonSerializer.Serialize(new{started,completed=DateTimeOffset.UtcNow,target,passed,failure,rounds,
            actualSystem=Runtime.Player.Navigation.CurrentSystemAddress,initialSystem=initial.Navigation.CurrentSystemAddress,
            planPageCommandUsed=true,realGameRouteUsed=true,screenUse=false,osInputSent=false,flightCommandsInvoked=false,journalWrites=0,navRouteWrites=0},new JsonSerializerOptions{WriteIndented=true}));
        MainWindow.Close();
    }
}