mirror of
https://github.com/Novetus/Novetus_src.git
synced 2025-01-31 17:53:01 +02:00
improved wine compatibility
This commit is contained in:
parent
bc3f3661d9
commit
b499fd6879
@ -240,70 +240,6 @@ namespace Novetus.Core
|
|||||||
EnableMenuItem(GetSystemMenu(form.Handle, false), 0xF060, 0);
|
EnableMenuItem(GetSystemMenu(form.Handle, false), 0xF060, 0);
|
||||||
}
|
}
|
||||||
#endregion
|
#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
|
#endregion
|
||||||
|
|
||||||
#region Utility Functions
|
#region Utility Functions
|
||||||
|
@ -8,6 +8,8 @@ namespace NovetusLauncher
|
|||||||
public static int Clicks = 0;
|
public static int Clicks = 0;
|
||||||
public static string prevsplash = "";
|
public static string prevsplash = "";
|
||||||
public static bool launcherInitState = true;
|
public static bool launcherInitState = true;
|
||||||
|
//hack for linux. store the command line variables locally.
|
||||||
|
public static string cmdLine = "";
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -10,6 +10,7 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
#endregion
|
#endregion
|
||||||
@ -573,7 +574,7 @@ namespace NovetusLauncher
|
|||||||
public void RestartApp()
|
public void RestartApp()
|
||||||
{
|
{
|
||||||
var process = Process.GetCurrentProcess();
|
var process = Process.GetCurrentProcess();
|
||||||
Process.Start(process.GetFilePath(), process.GetCommandLine());
|
Process.Start(Assembly.GetExecutingAssembly().Location, LocalVars.cmdLine);
|
||||||
CloseEventInternal();
|
CloseEventInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
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);
|
Run(args, isSDK, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user