XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
UTF-8
using SpaceEngineersBlueprintEditor.SpaceEngineersCore;
using SpaceEngineersBlueprintEditor.Utilities;
using SpaceEngineersBlueprintEditor.Views;
using XFEExtension.NetCore.StringExtension;
using XFEExtension.NetCore.WinUIHelper.Interface.Services;
using XFEExtension.NetCore.WinUIHelper.Utilities;
using RuntimeGameAssemblyLoader = SpaceEngineersBlueprintEditor.GameAssemblyLoader.GameAssemblyLoader;

namespace SpaceEngineersBlueprintEditor;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
    public static MainWindow MainWindow { get; set; } = null!;
    public App()
    {
        var gameRootPath = RuntimeGameAssemblyLoader.Initialize(SystemProfile.GameRootPath);
        if (!gameRootPath.IsNullOrEmpty() && !string.Equals(SystemProfile.GameRootPath, gameRootPath, StringComparison.OrdinalIgnoreCase))
            SystemProfile.GameRootPath = gameRootPath;

        this.InitializeComponent();
        PageManager.RegisterPage(typeof(AppShellPage));
        PageManager.RegisterPage(typeof(MainPage));
        PageManager.RegisterPage(typeof(BlueprintEditPage));
        PageManager.RegisterPage(typeof(BlueprintsViewPage));
        PageManager.RegisterPage(typeof(GameDefinitionsViewPage));
        PageManager.RegisterPage(typeof(BlueprintDetailPage));
        PageManager.RegisterPage(typeof(SettingPage));
        Task.Run(BlueprintsManager.LoadBlueprintsAsync);
        Task.Run(() =>
        {
            try
            {
                RuntimeGameAssemblyLoader.EnsureInitialized(SystemProfile.GameRootPath);
                Initializer.Initialize(SpaceEngineersPath.SpaceEngineerContentPath, SpaceEngineersPath.UserGameDataRoot);
            }
            catch (Exception ex)
            {
                ServiceManager.GetGlobalService<IMessageService>()?.ShowMessage($"{"Error_LoadingDefinitions".GetLocalized()}: {ex.Message}", "Error_LoadingDefinitions_Title".GetLocalized(), InfoBarSeverity.Error);
            }
        });
        UnhandledException += App_UnhandledException;
    }

    private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
    {
        if (ServiceManager.GetGlobalService<IMessageService>() is IMessageService messageService)
        {
            messageService.ShowMessage(e.Message, "Error".GetLocalized(), InfoBarSeverity.Error);
            e.Handled = true;
        }
    }

    /// <summary>
    /// Invoked when the application is launched.
    /// </summary>
    /// <param name="args">Details about the launch request and process.</param>
    protected override void OnLaunched(LaunchActivatedEventArgs args)
    {
        MainWindow = new MainWindow();
        MainWindow.Content = new AppShellPage();
        MainWindow.Activate();
    }
}