Exemplo n.º 1
0
        private async void CreateSkeleton()
        {
            var source = Asset.Source;

            if (UPath.IsNullOrEmpty(source))
            {
                return;
            }

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var template = Session.FindTemplates(TemplateScope.Asset).SingleOrDefault(x => x.Id == SkeletonFromFileTemplateGenerator.Id);
                if (template != null)
                {
                    var viewModel = new TemplateDescriptionViewModel(ServiceProvider, template);
                    var skeleton  = (await Session.ActiveAssetView.RunAssetTemplate(viewModel, new[] { source })).SingleOrDefault();
                    if (skeleton == null)
                    {
                        return;
                    }

                    var skeletonNode = AssetRootNode[nameof(ModelAsset.Skeleton)];
                    var reference    = ContentReferenceHelper.CreateReference <Skeleton>(skeleton);
                    skeletonNode.Update(reference);
                }
                UndoRedoService.SetName(transaction, "Create Skeleton");
            }
        }
Exemplo n.º 2
0
 public void TestUPathIsNullOrEmpty()
 {
     Assert.True(UPath.IsNullOrEmpty(new UFile(null)));
     Assert.True(UPath.IsNullOrEmpty(new UFile("")));
     Assert.True(UPath.IsNullOrEmpty(new UFile(" ")));
     Assert.True(UPath.IsNullOrEmpty(new UDirectory(null)));
     Assert.True(UPath.IsNullOrEmpty(new UDirectory("")));
     Assert.True(UPath.IsNullOrEmpty(new UDirectory(" ")));
     Assert.True(UPath.IsNullOrEmpty(null));
     Assert.False(UPath.IsNullOrEmpty(new UFile("a")));
     Assert.False(UPath.IsNullOrEmpty(new UDirectory("a")));
     Assert.False(UPath.IsNullOrEmpty(new UDirectory("C:/")));
     Assert.False(UPath.IsNullOrEmpty(new UDirectory("/")));
 }
Exemplo n.º 3
0
        private static async void Startup(UFile initialSessionPath)
        {
            try
            {
                InitializeLanguageSettings();
                var serviceProvider = InitializeServiceProvider();

                try
                {
                    PackageSessionPublicHelper.FindAndSetMSBuildVersion();
                }
                catch (Exception e)
                {
                    var message = "Could not find a compatible version of MSBuild.\r\n\r\n" +
                                  "Check that you have a valid installation with the required workloads, or go to [www.visualstudio.com/downloads](https://www.visualstudio.com/downloads) to install a new one.\r\n\r\n" +
                                  e;
                    await serviceProvider.Get <IEditorDialogService>().MessageBox(message, Core.Presentation.Services.MessageBoxButton.OK, Core.Presentation.Services.MessageBoxImage.Error);

                    app.Shutdown();
                    return;
                }

                // Running first time? If yes, create nuget redirect package.
                var packageVersion = new PackageVersion(XenkoVersion.NuGetVersion);
                if (PackageStore.Instance.IsDevelopmentStore)
                {
                    await PackageStore.Instance.CheckDeveloperTargetRedirects("Xenko", packageVersion, PackageStore.Instance.InstallationPath);
                }

                // We use a MRU that contains the older version projects to display in the editor
                var mru = new MostRecentlyUsedFileCollection(InternalSettings.LoadProfileCopy, InternalSettings.MostRecentlyUsedSessions, InternalSettings.WriteFile, XenkoGameStudio.EditorVersionMajor, true);
                mru.LoadFromSettings();
                var editor = new GameStudioViewModel(serviceProvider, mru);
                AssetsPlugin.RegisterPlugin(typeof(XenkoDefaultAssetsPlugin));
                AssetsPlugin.RegisterPlugin(typeof(XenkoEditorPlugin));

                // Attempt to load the startup session, if available
                if (!UPath.IsNullOrEmpty(initialSessionPath))
                {
                    var sessionLoaded = await editor.OpenInitialSession(initialSessionPath);

                    if (sessionLoaded == true)
                    {
                        var mainWindow = new GameStudioWindow(editor);
                        Application.Current.MainWindow = mainWindow;
                        WindowManager.ShowMainWindow(mainWindow);
                        return;
                    }
                }

                // No session successfully loaded, open the new/open project window
                bool?completed;
                // The user might cancel after chosing a template to instantiate, in this case we'll reopen the window
                var startupWindow = new ProjectSelectionWindow
                {
                    WindowStartupLocation = WindowStartupLocation.CenterScreen,
                    ShowInTaskbar         = true,
                };
                var viewModel = new NewOrOpenSessionTemplateCollectionViewModel(serviceProvider, startupWindow);
                startupWindow.Templates = viewModel;
                startupWindow.ShowDialog();

                // The user selected a template to instantiate
                if (startupWindow.NewSessionParameters != null)
                {
                    // Clean existing entry in the MRU data
                    var directory = startupWindow.NewSessionParameters.OutputDirectory;
                    var name      = startupWindow.NewSessionParameters.OutputName;
                    var mruData   = new MRUAdditionalDataCollection(InternalSettings.LoadProfileCopy, GameStudioInternalSettings.MostRecentlyUsedSessionsData, InternalSettings.WriteFile);
                    mruData.RemoveFile(UFile.Combine(UDirectory.Combine(directory, name), new UFile(name + SessionViewModel.SolutionExtension)));

                    completed = await editor.NewSession(startupWindow.NewSessionParameters);
                }
                // The user selected a path to open
                else if (startupWindow.ExistingSessionPath != null)
                {
                    completed = await editor.OpenSession(startupWindow.ExistingSessionPath);
                }
                // The user cancelled from the new/open project window, so exit the application
                else
                {
                    completed = true;
                }

                if (completed != true)
                {
                    var windowsClosed = new List <Task>();
                    foreach (var window in Application.Current.Windows.Cast <Window>().Where(x => x.IsLoaded))
                    {
                        var tcs = new TaskCompletionSource <int>();
                        window.Unloaded += (s, e) => tcs.SetResult(0);
                        windowsClosed.Add(tcs.Task);
                    }

                    await Task.WhenAll(windowsClosed);

                    // When a project has been partially loaded, it might already have initialized some plugin that could conflict with
                    // the next attempt to start something. Better start the application again.
                    var commandLine = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(x => $"\"{x}\""));
                    var process     = new Process {
                        StartInfo = new ProcessStartInfo(typeof(Program).Assembly.Location, commandLine)
                    };
                    process.Start();
                    app.Shutdown();
                    return;
                }

                if (editor.Session != null)
                {
                    // If a session was correctly loaded, show the main window
                    var mainWindow = new GameStudioWindow(editor);
                    Application.Current.MainWindow = mainWindow;
                    WindowManager.ShowMainWindow(mainWindow);
                }
                else
                {
                    // Otherwise, exit.
                    app.Shutdown();
                }
            }
            catch (Exception)
            {
                app.Shutdown();
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            EditorPath.EditorTitle = XenkoGameStudio.EditorName;

            if (IntPtr.Size == 4)
            {
                MessageBox.Show("Xenko GameStudio requires a 64bit OS to run.", "Xenko", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(1);
            }

            PrivacyPolicyHelper.RestartApplication = RestartApplication;
            PrivacyPolicyHelper.EnsurePrivacyPolicyXenko30();

            // Set the XenkoDir environment variable
            var installDir = DirectoryHelper.GetInstallationDirectory("Xenko");

            Environment.SetEnvironmentVariable("XenkoDir", installDir);

            // We use MRU of the current version only when we're trying to reload last session.
            var mru = new MostRecentlyUsedFileCollection(InternalSettings.LoadProfileCopy, InternalSettings.MostRecentlyUsedSessions, InternalSettings.WriteFile, XenkoGameStudio.EditorVersionMajor, false);

            mru.LoadFromSettings();

            EditorSettings.Initialize();
            Thread.CurrentThread.Name = "Main thread";

            // Install Metrics for the editor
            using (XenkoGameStudio.MetricsClient = new MetricsClient(CommonApps.XenkoEditorAppId))
            {
                try
                {
                    // Environment.GetCommandLineArgs correctly process arguments regarding the presence of '\' and '"'
                    var args = Environment.GetCommandLineArgs().Skip(1).ToList();
                    var startupSessionPath = XenkoEditorSettings.StartupSession.GetValue();
                    var lastSessionPath    = EditorSettings.ReloadLastSession.GetValue() ? mru.MostRecentlyUsedFiles.FirstOrDefault() : null;
                    var initialSessionPath = !UPath.IsNullOrEmpty(startupSessionPath) ? startupSessionPath : lastSessionPath?.FilePath;

                    // Handle arguments
                    for (var i = 0; i < args.Count; i++)
                    {
                        if (args[i] == "/LauncherWindowHandle")
                        {
                            windowHandle = new IntPtr(long.Parse(args[++i]));
                        }
                        else if (args[i] == "/NewProject")
                        {
                            initialSessionPath = null;
                        }
                        else if (args[i] == "/DebugEditorGraphics")
                        {
                            EmbeddedGame.DebugMode = true;
                        }
                        else if (args[i] == "/RenderDoc")
                        {
                            // TODO: RenderDoc is not working here (when not in debug)
                            GameStudioPreviewService.DisablePreview = true;
                            renderDocManager = new RenderDocManager();
                        }
                        else if (args[i] == "/Reattach")
                        {
                            var debuggerProcessId = int.Parse(args[++i]);

                            if (!System.Diagnostics.Debugger.IsAttached)
                            {
                                using (var debugger = VisualStudioDebugger.GetByProcess(debuggerProcessId))
                                {
                                    debugger?.Attach();
                                }
                            }
                        }
                        else if (args[i] == "/RecordEffects")
                        {
                            GameStudioBuilderService.GlobalEffectLogPath = args[++i];
                        }
                        else
                        {
                            initialSessionPath = args[i];
                        }
                    }
                    RuntimeHelpers.RunModuleConstructor(typeof(Asset).Module.ModuleHandle);

                    //listen to logger for crash report
                    GlobalLogger.GlobalMessageLogged += GlobalLoggerOnGlobalMessageLogged;

                    mainDispatcher = Dispatcher.CurrentDispatcher;
                    mainDispatcher.InvokeAsync(() => Startup(initialSessionPath));

                    using (new WindowManager(mainDispatcher))
                    {
                        app = new App {
                            ShutdownMode = ShutdownMode.OnExplicitShutdown
                        };
                        app.Activated += (sender, eventArgs) =>
                        {
                            XenkoGameStudio.MetricsClient?.SetActiveState(true);
                        };
                        app.Deactivated += (sender, eventArgs) =>
                        {
                            XenkoGameStudio.MetricsClient?.SetActiveState(false);
                        };

                        app.InitializeComponent();
                        app.Run();
                    }

                    renderDocManager?.Shutdown();
                }
                catch (Exception e)
                {
                    HandleException(e, 0);
                }
            }
        }
Exemplo n.º 5
0
        public static void Main()
        {
            // wait, are we already running?
            int waitToClose = 16;

            while (Process.GetProcessesByName("Focus.GameStudio").Length > 1)
            {
                if (waitToClose-- <= 0)
                {
                    MessageBox.Show("Focus GameStudio is already running! Only one instance is possible at a time.", "Focus", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(1);
                }
                Thread.Sleep(250);
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            EditorPath.EditorTitle = XenkoGameStudio.EditorName;

            if (IntPtr.Size == 4)
            {
                MessageBox.Show(EngineName + " " + GameStudioName + " requires a 64bit OS to run.", "Focus", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(1);
            }

            PrivacyPolicyHelper.RestartApplication = RestartApplication;
            PrivacyPolicyHelper.EnsurePrivacyPolicyXenko30();

            // We use MRU of the current version only when we're trying to reload last session.
            var mru = new MostRecentlyUsedFileCollection(InternalSettings.LoadProfileCopy, InternalSettings.MostRecentlyUsedSessions, InternalSettings.WriteFile);

            mru.LoadFromSettings();

            EditorSettings.Initialize();
            Thread.CurrentThread.Name    = "EditorGameThread (GameStudio)";
            EntityManager.EnforceThreads = false;

            try
            {
                // Environment.GetCommandLineArgs correctly process arguments regarding the presence of '\' and '"'
                var args = Environment.GetCommandLineArgs().Skip(1).ToList();
                var startupSessionPath = XenkoEditorSettings.StartupSession.GetValue();
                var lastSessionPath    = EditorSettings.ReloadLastSession.GetValue() ? mru.MostRecentlyUsedFiles.FirstOrDefault() : null;
                var initialSessionPath = !UPath.IsNullOrEmpty(startupSessionPath) ? startupSessionPath : lastSessionPath?.FilePath;

                // Handle arguments
                for (var i = 0; i < args.Count; i++)
                {
                    if (args[i] == "/LauncherWindowHandle")
                    {
                        windowHandle = new IntPtr(long.Parse(args[++i]));
                    }
                    else if (args[i] == "/NewProject")
                    {
                        initialSessionPath = null;
                    }
                    else if (args[i] == "/DebugEditorGraphics")
                    {
                        EmbeddedGame.DebugMode = true;
                    }
                    else if (args[i] == "/RenderDoc")
                    {
                        // TODO: RenderDoc is not working here (when not in debug)
                        GameStudioPreviewService.DisablePreview = true;
                        renderDocManager = new RenderDocManager();
                    }
                    else if (args[i] == "/Reattach")
                    {
                        var debuggerProcessId = int.Parse(args[++i]);

                        if (!System.Diagnostics.Debugger.IsAttached)
                        {
                            using (var debugger = VisualStudioDebugger.GetByProcess(debuggerProcessId))
                            {
                                debugger?.Attach();
                            }
                        }
                    }
                    else if (args[i] == "/RecordEffects")
                    {
                        GameStudioBuilderService.GlobalEffectLogPath = args[++i];
                    }
                    else
                    {
                        initialSessionPath = args[i];
                    }
                }
                RuntimeHelpers.RunModuleConstructor(typeof(Asset).Module.ModuleHandle);

                //listen to logger for crash report
                GlobalLogger.GlobalMessageLogged += GlobalLoggerOnGlobalMessageLogged;

                mainDispatcher = Dispatcher.CurrentDispatcher;
                mainDispatcher.InvokeAsync(() => Startup(initialSessionPath));

                using (new WindowManager(mainDispatcher))
                {
                    app = new App {
                        ShutdownMode = ShutdownMode.OnExplicitShutdown
                    };
                    app.InitializeComponent();
                    app.Run();
                }

                renderDocManager?.Shutdown();
            }
            catch (Exception e)
            {
                HandleException(e, 0);
            }
        }