From f7a66fecc16204db6039558a07b52f78d2eda1b3 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sun, 10 Nov 2024 19:45:26 -0300 Subject: [PATCH 1/2] Do not start the UI when using the "-playmod" cmdline argument --- Knossos.NET/Classes/Knossos.cs | 42 ++++++++++++++++++++-------------- Knossos.NET/Program.cs | 35 +++++++++++++++++++--------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index ceb69a2b..23e8a21f 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -250,7 +250,7 @@ private static async Task QuickLaunch() await Task.Delay(2000); Dispatcher.UIThread.Invoke(() => { - MainWindow.instance!.Close(); + MainWindow.instance?.Close(); }); } @@ -740,7 +740,7 @@ private static void AutoUpdateBuilds() /// public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standaloneServer = false, int standalonePort = 0) { - if (TaskViewModel.Instance!.IsSafeState() == false) + if (TaskViewModel.Instance?.IsSafeState() == false) { var result = await MessageBox.Show(MainWindow.instance!, "Other important tasks are running, it is recommended that you wait until they finish before launching the game because it may cause them to fail.\nIf you are absolutely sure those tasks cannot interfere you can continue.", "Tasks are running", MessageBox.MessageBoxButtons.ContinueCancel); if(result != MessageBox.MessageBoxResult.Continue) @@ -1064,15 +1064,17 @@ public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standalo if (fsoBuild == null) { Log.Add(Log.LogSeverity.Error, "Knossos.PlayMod()", "Unable to find a valid FSO build for this mod!"); - if(hasBuildDependency) - { - await MessageBox.Show(MainWindow.instance!, "Unable to find a valid FSO build for this mod!", "Error launching mod", MessageBox.MessageBoxButtons.OK); - } - else + if (MainWindow.instance != null) { - await MessageBox.Show(MainWindow.instance!, "This mod does not especifies a engine build to use, you should select one in the mod settings.", "Error launching mod", MessageBox.MessageBoxButtons.OK); + if (hasBuildDependency) + { + await MessageBox.Show(MainWindow.instance!, "Unable to find a valid FSO build for this mod!", "Error launching mod", MessageBox.MessageBoxButtons.OK); + } + else + { + await MessageBox.Show(MainWindow.instance!, "This mod does not especifies a engine build to use, you should select one in the mod settings.", "Error launching mod", MessageBox.MessageBoxButtons.OK); + } } - return; } else @@ -1084,9 +1086,12 @@ public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standalo { if (mod.modSettings.isCompressed) { - var result = await MessageBox.Show(MainWindow.instance!, "This mod currently resolves to FSO build: " + fsoBuild.version + " and it is compressed, the minimum to fully support all compression features is: " + VPCompression.MinimumFSOVersion + ".\n23.0.0 may work if the mod do not have loose files, older versions are not going to work. Use a newer FSO version or uncompress this mod.", "FSO Version below minimum for compression", MessageBox.MessageBoxButtons.ContinueCancel); - if (result != MessageBox.MessageBoxResult.Continue) - return; + if (MainWindow.instance != null) + { + var result = await MessageBox.Show(MainWindow.instance!, "This mod currently resolves to FSO build: " + fsoBuild.version + " and it is compressed, the minimum to fully support all compression features is: " + VPCompression.MinimumFSOVersion + ".\n23.0.0 may work if the mod do not have loose files, older versions are not going to work. Use a newer FSO version or uncompress this mod.", "FSO Version below minimum for compression", MessageBox.MessageBoxButtons.ContinueCancel); + if (result != MessageBox.MessageBoxResult.Continue) + return; + } } else { @@ -1113,9 +1118,12 @@ public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standalo } if (compressedMods != string.Empty) { - var result = await MessageBox.Show(MainWindow.instance!, "This mod currently resolves to FSO build: " + fsoBuild.version + " and depends on mods: " + compressedMods + " that are currently compressed, the minimum to fully support all compression features is: " + VPCompression.MinimumFSOVersion + ".\n23.0.0 may work if the mod do not have loose files, older versions are not going to work. Use a newer FSO version or uncompress those mods.", "FSO Version below minimum for compression", MessageBox.MessageBoxButtons.ContinueCancel); - if (result != MessageBox.MessageBoxResult.Continue) - return; + if (MainWindow.instance != null) + { + var result = await MessageBox.Show(MainWindow.instance!, "This mod currently resolves to FSO build: " + fsoBuild.version + " and depends on mods: " + compressedMods + " that are currently compressed, the minimum to fully support all compression features is: " + VPCompression.MinimumFSOVersion + ".\n23.0.0 may work if the mod do not have loose files, older versions are not going to work. Use a newer FSO version or uncompress those mods.", "FSO Version below minimum for compression", MessageBox.MessageBoxButtons.ContinueCancel); + if (result != MessageBox.MessageBoxResult.Continue) + return; + } } } } @@ -1344,9 +1352,9 @@ private static async Task FolderSearchRecursive(string path, bool isQuickLaunch, await Dispatcher.UIThread.InvokeAsync(() => FsoBuildsViewModel.Instance?.AddBuildToUi(build), DispatcherPriority.Background); break; } - if(modJson.devMode) + if(modJson.devMode && !isQuickLaunch) { - await Dispatcher.UIThread.InvokeAsync(() => MainWindowViewModel.Instance!.AddDevMod(modJson), DispatcherPriority.Background); + await Dispatcher.UIThread.InvokeAsync(() => MainWindowViewModel.Instance?.AddDevMod(modJson), DispatcherPriority.Background); } } catch (Exception ex) diff --git a/Knossos.NET/Program.cs b/Knossos.NET/Program.cs index 241edab8..e321a365 100644 --- a/Knossos.NET/Program.cs +++ b/Knossos.NET/Program.cs @@ -13,6 +13,7 @@ internal class Program public static void Main(string[] args) { bool softwareRendering = false; + bool isQuickLaunch = false; //Check app args foreach (var arg in args) @@ -21,24 +22,36 @@ public static void Main(string[] args) { softwareRendering = true; } + if (arg.ToLower() == "-playmod") + { + isQuickLaunch = true; + } } - //Check enviroment variables - var renderMode = KnUtils.GetEnvironmentVariable("KNET_RENDER_MODE"); - if (renderMode != null && renderMode.ToLower() == "software") + if (isQuickLaunch) { - softwareRendering = true; - } - - //Start App - if (softwareRendering) - { - BuildAvaloniaAppSoftware().StartWithClassicDesktopLifetime(args); + Knossos.StartUp(true, false); } else { - BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + //Check enviroment variables + var renderMode = KnUtils.GetEnvironmentVariable("KNET_RENDER_MODE"); + + if (renderMode != null && renderMode.ToLower() == "software") + { + softwareRendering = true; + } + + //Start App + if (softwareRendering) + { + BuildAvaloniaAppSoftware().StartWithClassicDesktopLifetime(args); + } + else + { + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } } } From 0047b9f4df002040ace9e65c7cbd0bcf4155bbad Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sun, 10 Nov 2024 19:52:17 -0300 Subject: [PATCH 2/2] Do not call Dispatcher.UIThread if there is no ui. --- Knossos.NET/Classes/Knossos.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index 23e8a21f..66679c12 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -248,10 +248,13 @@ private static async Task QuickLaunch() Log.Add(Log.LogSeverity.Error, "Knossos.QuickLaunch", "Quick launch was used but the modid was not detected."); } await Task.Delay(2000); - Dispatcher.UIThread.Invoke(() => + if (MainWindow.instance != null) { - MainWindow.instance?.Close(); - }); + Dispatcher.UIThread.Invoke(() => + { + MainWindow.instance.Close(); + }); + } } ///