From 48a7f24e5373a98fe7ccbb400b2d85efcf4113b7 Mon Sep 17 00:00:00 2001 From: Vasilis The Pikachu Date: Sat, 20 Jan 2024 17:33:34 +0100 Subject: [PATCH 01/39] Windows seems done --- PublishFiles/SS14.desktop | 2 + SS14.Launcher.Bootstrap/Program.cs | 2 +- SS14.Launcher/ProtocolSetup.cs | 89 +++++++++++++++++++ .../Views/MainWindowTabs/OptionsTabView.xaml | 2 + .../MainWindowTabs/OptionsTabView.xaml.cs | 16 ++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 SS14.Launcher/ProtocolSetup.cs diff --git a/PublishFiles/SS14.desktop b/PublishFiles/SS14.desktop index a6dc97476..5f6ffefd0 100755 --- a/PublishFiles/SS14.desktop +++ b/PublishFiles/SS14.desktop @@ -5,3 +5,5 @@ Version=1.0 Type=Application Exec=env ./SS14.Launcher %u Name=Space Station 14 +MimeType=x-scheme-handler/ss14s; +MimeType=x-scheme-handler/ss14; diff --git a/SS14.Launcher.Bootstrap/Program.cs b/SS14.Launcher.Bootstrap/Program.cs index 7d745d594..4bc61e93f 100644 --- a/SS14.Launcher.Bootstrap/Program.cs +++ b/SS14.Launcher.Bootstrap/Program.cs @@ -19,7 +19,7 @@ public static void Main(string[] args) var exeDir = Path.Combine(ourDir, "bin", "SS14.Launcher.exe"); Environment.SetEnvironmentVariable("DOTNET_ROOT", dotnetDir); - Process.Start(new ProcessStartInfo(exeDir)); + Process.Start(new ProcessStartInfo(exeDir, args[0])); } private static void UnfuckDotnetRoot() diff --git a/SS14.Launcher/ProtocolSetup.cs b/SS14.Launcher/ProtocolSetup.cs new file mode 100644 index 000000000..d4960b0c9 --- /dev/null +++ b/SS14.Launcher/ProtocolSetup.cs @@ -0,0 +1,89 @@ +using System; +using System.Diagnostics; +using Microsoft.Win32; +using Serilog; + +namespace SS14.Launcher; + +public static class ProtocolSetup +{ + public static bool CheckExisting() + { + var result = false; + if (OperatingSystem.IsWindows()) + { + using var key1 = Registry.ClassesRoot.OpenSubKey("ss14s", false); + using var key2 = Registry.ClassesRoot.OpenSubKey("ss14", false); + result = key1 != null && key2 != null; + } + + if (OperatingSystem.IsMacOS()) + { + } + + if (OperatingSystem.IsLinux()) + { + } + + return result; + } + + + public static void RegisterProtocol() + { + // Windows registration + if (OperatingSystem.IsWindows()) + { + try + { + var proc = new Process(); + proc.StartInfo.FileName = "powershell.exe"; + proc.StartInfo.Arguments = $"-executionpolicy bypass -windowstyle hidden -noninteractive -nologo " + + $"-file \"{AppDomain.CurrentDomain.BaseDirectory}windows_protocol_register.ps1\""; + proc.StartInfo.UseShellExecute = true; + proc.StartInfo.Verb = "runas"; + proc.Start(); + } + catch (System.ComponentModel.Win32Exception) + { + // Do nothing, the user either declined UAC, they don't have administrator rights or something else went wrong. + Log.Warning("User declined UAC or doesn't have admin rights."); + } + } + if (OperatingSystem.IsMacOS()) + { + } + + if (OperatingSystem.IsLinux()) + { + } + } + public static void UnregisterProtocol() + { + if (OperatingSystem.IsWindows()) + { + try + { + var proc = new Process(); + proc.StartInfo.FileName = "powershell.exe"; + proc.StartInfo.Arguments = $"-executionpolicy bypass -windowstyle hidden -noninteractive -nologo " + + $"-file \"{AppDomain.CurrentDomain.BaseDirectory}windows_protocol_unregister.ps1\""; + proc.StartInfo.UseShellExecute = true; + proc.StartInfo.Verb = "runas"; + proc.Start(); + } + catch (System.ComponentModel.Win32Exception) + { + // Do nothing, the user either declined UAC, they don't have administrator rights or something else went wrong. + Log.Warning("User declined UAC or doesn't have admin rights."); + } + } + if (OperatingSystem.IsMacOS()) + { + } + + if (OperatingSystem.IsLinux()) + { + } + } +} diff --git a/SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml b/SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml index 21b8212bb..994fe7a6e 100644 --- a/SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml +++ b/SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml @@ -19,6 +19,8 @@ HorizontalAlignment="Left" Click="ClearServerContentPressed" />