improved wine compatibility

This commit is contained in:
Bitl 2023-03-09 11:19:09 -07:00
parent bc3f3661d9
commit b499fd6879
5 changed files with 16 additions and 66 deletions

View File

@ -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

View File

@ -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 (<pid>) 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 (<pid>) 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

View File

@ -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

View File

@ -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();
}

View File

@ -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);
}