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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

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

namespace XFEEDToolBox.ViewModels;

public partial class ToolboxViewModel
{
    private bool syncingGalaxyDisplay;
    private int galaxyDisplayProcess;
    public event Action? GalaxyDisplayReady;
    private async Task EnsureGalaxyDisplayAsync()
    {
        if(syncingGalaxyDisplay||NavigationActive||!CurrentPlayer.InGame||runtime.FlightDriver is not NativeFlightControlDriver{SupportsGalaxyRegion:true} driver
            ||galaxyDisplayProcess==driver.ProcessId)return;
        syncingGalaxyDisplay=true;
        try
        {
            var nativeRoot=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"XFEstudio","XFEEDToolBox","galaxy");
            var destination=Path.Combine(runtime.DataDirectory,"galaxy");Directory.CreateDirectory(destination);
            var pipe=new NavigationPipeClient(driver.ProcessId);
            if(!File.Exists(Path.Combine(nativeRoot,"galaxy-density.bin")))
            {
                var response=await pipe.CallAsync(new{op="galaxy.overview"},lifetime.Token);
                if(response.GetProperty("width").GetInt32()<16)throw new InvalidDataException("银河全景未完整读取。");
            }
            var source=Path.Combine(nativeRoot,"galaxy-density.bin");var output=Path.Combine(destination,"galaxy-density.bin");
            if(!File.Exists(source))throw new InvalidDataException("原游戏银河密度资源尚未就绪。");
            if(!Path.GetFullPath(source).Equals(Path.GetFullPath(output),StringComparison.OrdinalIgnoreCase))File.Copy(source,output,true);
            // A diffuse density texture says nothing about catalogue coverage.
            // The streaming receipts remain the sole owner of that status.
            galaxyDisplayProcess=driver.ProcessId;GalaxyDisplayReady?.Invoke();
        }
        catch(Exception error)when(error is not OperationCanceledException)
        {runtime.Log("银河资源",error.Message);try{File.WriteAllText(Path.Combine(runtime.DataDirectory,"galaxy","display-error.txt"),error.ToString());}catch(IOException){ }}
        finally{syncingGalaxyDisplay=false;}
    }
}