From b499fd68799b63ba0b7fe346c9783a0146c26b49 Mon Sep 17 00:00:00 2001 From: Bitl Date: Thu, 9 Mar 2023 11:19:09 -0700 Subject: [PATCH] improved wine compatibility --- .../StorageAndFunctions/ClientManagement.cs | 2 +- .../NovetusCore/StorageAndFunctions/Util.cs | 64 ------------------- Novetus/NovetusLauncher/Classes/LocalVars.cs | 2 + .../Forms/LauncherForm/LauncherFormShared.cs | 3 +- .../NovetusLauncherEntryPoint.cs | 11 ++++ 5 files changed, 16 insertions(+), 66 deletions(-) diff --git a/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs b/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs index f498930..edb05dc 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs @@ -1475,7 +1475,7 @@ namespace Novetus.Core } #if LAUNCHER - string md5dir = !info.AlreadyHasSecurity ? SecurityFuncs.GenerateMD5(Assembly.GetExecutingAssembly().Location) : ""; + string md5dir = !info.AlreadyHasSecurity ? SecurityFuncs.GenerateMD5(Assembly.GetExecutingAssembly().Location) : ""; #else string md5dir = !info.AlreadyHasSecurity ? SecurityFuncs.GenerateMD5(GlobalPaths.RootPathLauncher + "\\Novetus.exe") : ""; #endif diff --git a/Novetus/NovetusCore/StorageAndFunctions/Util.cs b/Novetus/NovetusCore/StorageAndFunctions/Util.cs index ea83b99..595d957 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/Util.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/Util.cs @@ -240,70 +240,6 @@ namespace Novetus.Core EnableMenuItem(GetSystemMenu(form.Handle, false), 0xF060, 0); } #endregion - - #region Process Extensions - //https://stackoverflow.com/questions/2633628/can-i-get-command-line-arguments-of-other-processes-from-net-c - // Define an extension method for type System.Process that returns the command - // line via WMI. - public static string GetCommandLine(this Process process) - { - string cmdLine = null; - using (var searcher = new ManagementObjectSearcher( - $"SELECT CommandLine FROM Win32_Process WHERE ProcessId = {process.Id}")) - { - // By definition, the query returns at most 1 match, because the process - // is looked up by ID (which is unique by definition). - using (var matchEnum = searcher.Get().GetEnumerator()) - { - if (matchEnum.MoveNext()) // Move to the 1st item. - { - cmdLine = matchEnum.Current["CommandLine"]?.ToString(); - } - } - } - if (cmdLine == null) - { - // Not having found a command line implies 1 of 2 exceptions, which the - // WMI query masked: - // An "Access denied" exception due to lack of privileges. - // A "Cannot process request because the process () has exited." - // exception due to the process having terminated. - // We provoke the same exception again simply by accessing process.MainModule. - var dummy = process.MainModule; // Provoke exception. - } - return cmdLine; - } - - // based off the above function - public static string GetFilePath(this Process process) - { - string path = null; - using (var searcher = new ManagementObjectSearcher( - $"SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = {process.Id}")) - { - // By definition, the query returns at most 1 match, because the process - // is looked up by ID (which is unique by definition). - using (var matchEnum = searcher.Get().GetEnumerator()) - { - if (matchEnum.MoveNext()) // Move to the 1st item. - { - path = matchEnum.Current["ExecutablePath"]?.ToString(); - } - } - } - if (path == null) - { - // Not having found a command line implies 1 of 2 exceptions, which the - // WMI query masked: - // An "Access denied" exception due to lack of privileges. - // A "Cannot process request because the process () has exited." - // exception due to the process having terminated. - // We provoke the same exception again simply by accessing process.MainModule. - var dummy = process.MainModule; // Provoke exception. - } - return path; - } - #endregion #endregion #region Utility Functions diff --git a/Novetus/NovetusLauncher/Classes/LocalVars.cs b/Novetus/NovetusLauncher/Classes/LocalVars.cs index 0f4c153..4d4b79d 100644 --- a/Novetus/NovetusLauncher/Classes/LocalVars.cs +++ b/Novetus/NovetusLauncher/Classes/LocalVars.cs @@ -8,6 +8,8 @@ namespace NovetusLauncher public static int Clicks = 0; public static string prevsplash = ""; public static bool launcherInitState = true; + //hack for linux. store the command line variables locally. + public static string cmdLine = ""; #endregion } #endregion diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index ef8eddb..d1fc99b 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -10,6 +10,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net; +using System.Reflection; using System.Threading.Tasks; using System.Windows.Forms; #endregion @@ -573,7 +574,7 @@ namespace NovetusLauncher public void RestartApp() { var process = Process.GetCurrentProcess(); - Process.Start(process.GetFilePath(), process.GetCommandLine()); + Process.Start(Assembly.GetExecutingAssembly().Location, LocalVars.cmdLine); CloseEventInternal(); } diff --git a/Novetus/NovetusLauncher/NovetusLauncherEntryPoint.cs b/Novetus/NovetusLauncher/NovetusLauncherEntryPoint.cs index 94ea42a..d15ebe5 100644 --- a/Novetus/NovetusLauncher/NovetusLauncherEntryPoint.cs +++ b/Novetus/NovetusLauncher/NovetusLauncherEntryPoint.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Globalization; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -80,6 +81,16 @@ namespace NovetusLauncher } } + foreach (string argString in args) + { + LocalVars.cmdLine += argString; + + if (!argString.Equals(args.Last())) + { + LocalVars.cmdLine += " "; + } + } + Run(args, isSDK, state); }