Fix launch args

This commit is contained in:
Natsumi
2024-10-22 09:12:06 +13:00
parent f9686ad803
commit 6180777652
6 changed files with 69 additions and 68 deletions

View File

@@ -280,24 +280,21 @@ namespace VRCX
/// <summary>
/// Restarts the VRCX application for an update by launching a new process with the upgrade argument and exiting the current process.
/// </summary>
public void RestartApplication()
public void RestartApplication(bool isUpgrade)
{
List<string> args = [ StartupArgs.VrcxLaunchArguements.IsUpgradePrefix ];
var args = new List<string>();
if (isUpgrade)
args.Add(StartupArgs.VrcxLaunchArguments.IsUpgradePrefix);
if (StartupArgs.LaunchArguements.IsDebug == true)
{
args.Add(StartupArgs.VrcxLaunchArguements.IsDebugPrefix);
}
if (StartupArgs.LaunchArguments.IsDebug)
args.Add(StartupArgs.VrcxLaunchArguments.IsDebugPrefix);
if (!string.IsNullOrWhiteSpace(StartupArgs.LaunchArguements.ConfigDirectory))
{
args.Add($"{StartupArgs.VrcxLaunchArguements.ConfigDirectoryPrefix}={StartupArgs.LaunchArguements.ConfigDirectory}");
}
if (!string.IsNullOrWhiteSpace(StartupArgs.LaunchArguments.ConfigDirectory))
args.Add($"{StartupArgs.VrcxLaunchArguments.ConfigDirectoryPrefix}={StartupArgs.LaunchArguments.ConfigDirectory}");
if (!string.IsNullOrWhiteSpace(StartupArgs.LaunchArguements.ProxyUrl))
{
args.Add($"{StartupArgs.VrcxLaunchArguements.ProxyUrlPrefix}={StartupArgs.LaunchArguements.ProxyUrl}");
}
if (!string.IsNullOrWhiteSpace(StartupArgs.LaunchArguments.ProxyUrl))
args.Add($"{StartupArgs.VrcxLaunchArguments.ProxyUrlPrefix}={StartupArgs.LaunchArguments.ProxyUrl}");
var vrcxProcess = new Process
{
@@ -379,8 +376,8 @@ namespace VRCX
/// <returns>The launch command.</returns>
public string GetLaunchCommand()
{
var command = StartupArgs.LaunchArguements.LaunchCommand;
StartupArgs.LaunchArguements.LaunchCommand = string.Empty;
var command = StartupArgs.LaunchArguments.LaunchCommand;
StartupArgs.LaunchArguments.LaunchCommand = string.Empty;
return command;
}

View File

@@ -59,13 +59,14 @@ namespace VRCX
if (Program.LaunchDebug)
{
// it's dead fuck https://github.com/chromiumembedded/cef/issues/3740
// chrome://inspect/#devices
// Discover network targets, Configure...
// Add Remote Target: localhost:8089
logger.Info("Debug mode enabled");
cefSettings.RemoteDebuggingPort = 8089;
cefSettings.CefCommandLineArgs["remote-allow-origins"] = "*";
}
//CefSharpSettings.WcfEnabled = true; // TOOD: REMOVE THIS LINE YO (needed for synchronous configRepository)
CefSharpSettings.ShutdownOnExit = false;
CefSharpSettings.ConcurrentTaskExecution = true;

View File

@@ -120,7 +120,7 @@ namespace VRCX
MessageBox.Show(
"vc_redist has finished installing, if the issue persists upon next restart, please reinstall VRCX From GitHub,\nVRCX Will now restart.", "vc_redist installation complete", MessageBoxButtons.OK);
Thread.Sleep(5000);
AppApi.Instance.RestartApplication();
AppApi.Instance.RestartApplication(false);
break;
case DialogResult.No:

View File

@@ -18,7 +18,7 @@ namespace VRCX
{
internal class StartupArgs
{
public static VrcxLaunchArguements LaunchArguements = new();
public static VrcxLaunchArguments LaunchArguments = new();
public static void ArgsCheck()
{
@@ -27,60 +27,57 @@ namespace VRCX
Debug.Assert(Program.LaunchDebug = true);
var currentProcessArgs = ParseArgs(args);
LaunchArguements = currentProcessArgs;
LaunchArguments = currentProcessArgs;
if (LaunchArguements.IsDebug)
if (LaunchArguments.IsDebug)
Program.LaunchDebug = true;
if (LaunchArguements.ConfigDirectory != null)
if (LaunchArguments.ConfigDirectory != null)
{
if (File.Exists(LaunchArguements.ConfigDirectory))
if (File.Exists(LaunchArguments.ConfigDirectory))
{
MessageBox.Show("Move your \"VRCX.sqlite3\" into a folder then specify the folder in the launch parameter e.g.\n--config=\"C:\\VRCX\\\"", "--config is now a directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
Program.AppDataDirectory = LaunchArguements.ConfigDirectory;
Program.AppDataDirectory = LaunchArguments.ConfigDirectory;
}
var disableClosing = false;
if (LaunchArguements.IsUpgrade || // we're upgrading, allow it
!string.IsNullOrEmpty(CommandLineArgsParser.GetArgumentValue(args, CefSharpArguments.SubProcessTypeArgument))) // we're launching a subprocess, allow it
disableClosing = true;
var disableClosing = LaunchArguments.IsUpgrade || // we're upgrading, allow it
!string.IsNullOrEmpty(CommandLineArgsParser.GetArgumentValue(args, CefSharpArguments.SubProcessTypeArgument)); // we're launching a subprocess, allow it
// if we're launching a second instance with same config directory, focus the first instance then exit
if (!disableClosing && IsDuplicateProcessRunning(LaunchArguements))
if (!disableClosing && IsDuplicateProcessRunning(LaunchArguments))
{
IPCToMain();
Environment.Exit(0);
}
}
private static VrcxLaunchArguements ParseArgs(string[] args)
private static VrcxLaunchArguments ParseArgs(string[] args)
{
VrcxLaunchArguements arguements = new VrcxLaunchArguements();
var arguments = new VrcxLaunchArguments();
foreach (var arg in args)
{
if (arg == VrcxLaunchArguements.IsUpgradePrefix)
arguements.IsUpgrade = true;
if (arg == VrcxLaunchArguments.IsUpgradePrefix)
arguments.IsUpgrade = true;
if (arg.StartsWith(VrcxLaunchArguements.IsDebugPrefix))
arguements.IsDebug = true;
if (arg.StartsWith(VrcxLaunchArguments.IsDebugPrefix))
arguments.IsDebug = true;
if (arg.StartsWith(VrcxLaunchArguements.LaunchCommandPrefix) && arg.Length > VrcxLaunchArguements.LaunchCommandPrefix.Length)
arguements.LaunchCommand = arg.Substring(VrcxLaunchArguements.LaunchCommandPrefix.Length);
if (arg.StartsWith(VrcxLaunchArguments.LaunchCommandPrefix) && arg.Length > VrcxLaunchArguments.LaunchCommandPrefix.Length)
arguments.LaunchCommand = arg.Substring(VrcxLaunchArguments.LaunchCommandPrefix.Length);
if (arg.StartsWith(VrcxLaunchArguements.ConfigDirectoryPrefix) && arg.Length > VrcxLaunchArguements.ConfigDirectoryPrefix.Length)
arguements.ConfigDirectory = arg.Substring(VrcxLaunchArguements.ConfigDirectoryPrefix.Length + 1);
if (arg.StartsWith(VrcxLaunchArguments.ConfigDirectoryPrefix) && arg.Length > VrcxLaunchArguments.ConfigDirectoryPrefix.Length)
arguments.ConfigDirectory = arg.Substring(VrcxLaunchArguments.ConfigDirectoryPrefix.Length + 1);
if (arg.StartsWith(VrcxLaunchArguements.ProxyUrlPrefix) && arg.Length > VrcxLaunchArguements.ProxyUrlPrefix.Length)
arguements.ProxyUrl = arg.Substring(VrcxLaunchArguements.ProxyUrlPrefix.Length + 1).Replace("'", string.Empty).Replace("\"", string.Empty);
if (arg.StartsWith(VrcxLaunchArguments.ProxyUrlPrefix) && arg.Length > VrcxLaunchArguments.ProxyUrlPrefix.Length)
arguments.ProxyUrl = arg.Substring(VrcxLaunchArguments.ProxyUrlPrefix.Length + 1).Replace("'", string.Empty).Replace("\"", string.Empty);
}
return arguements;
return arguments;
}
internal class VrcxLaunchArguements
internal class VrcxLaunchArguments
{
public const string IsUpgradePrefix = "/Upgrade";
public bool IsUpgrade { get; set; } = false;
@@ -98,7 +95,7 @@ namespace VRCX
public string ProxyUrl { get; set; } = null;
}
private static bool IsDuplicateProcessRunning(VrcxLaunchArguements launchArguements)
private static bool IsDuplicateProcessRunning(VrcxLaunchArguments launchArguments)
{
var processes = Process.GetProcessesByName("VRCX")
.Where(x => x.Id != Environment.ProcessId);
@@ -109,26 +106,23 @@ namespace VRCX
try
{
using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
{
using (var objects = searcher.Get())
{
commandLine = objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString() ?? string.Empty;
}
}
using var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id);
using var objects = searcher.Get();
commandLine =
objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString() ??
string.Empty;
}
catch
{
// ignored
}
catch { }
if (commandLine.Contains(CefSharpArguments.SubProcessTypeArgument)) // ignore subprocesses
{
continue;
}
var processArguements = ParseArgs(commandLine.Split(' '));
if (processArguements.ConfigDirectory == launchArguements.ConfigDirectory)
{
var processArguments = ParseArgs(commandLine.Split(' '));
if (processArguments.ConfigDirectory == launchArguments.ConfigDirectory)
return true;
}
}
return false;
@@ -142,7 +136,7 @@ namespace VRCX
if (ipcClient.IsConnected)
{
var buffer = Encoding.UTF8.GetBytes($"{{\"type\":\"LaunchCommand\",\"command\":\"{LaunchArguements.LaunchCommand}\"}}" + (char)0x00);
var buffer = Encoding.UTF8.GetBytes($"{{\"type\":\"LaunchCommand\",\"command\":\"{LaunchArguments.LaunchCommand}\"}}" + (char)0x00);
ipcClient.BeginWrite(buffer, 0, buffer.Length, IPCClient.Close, ipcClient);
}
}

View File

@@ -59,8 +59,8 @@ namespace VRCX
private void SetProxy()
{
if (!string.IsNullOrEmpty(StartupArgs.LaunchArguements.ProxyUrl))
ProxyUrl = StartupArgs.LaunchArguements.ProxyUrl;
if (!string.IsNullOrEmpty(StartupArgs.LaunchArguments.ProxyUrl))
ProxyUrl = StartupArgs.LaunchArguments.ProxyUrl;
if (string.IsNullOrEmpty(ProxyUrl))
{

View File

@@ -2920,6 +2920,10 @@ speechSynthesis.getVoices();
break retryLoop;
} catch (err) {
console.error(err);
if (!API.currentUser.isLoggedIn) {
console.error(`User isn't logged in`);
break mainLoop;
}
if (err?.message?.includes('Not Found')) {
console.error('Awful workaround for awful VRC API bug');
break retryLoop;
@@ -25070,7 +25074,11 @@ speechSynthesis.getVoices();
case -16:
if (this.downloadCurrent.ref.id === 'VRCXUpdate') {
if (this.downloadCurrent.autoInstall) {
workerTimers.setTimeout(() => this.restartVRCX(), 2000);
var isUpgrade = true;
workerTimers.setTimeout(
() => this.restartVRCX(isUpgrade),
2000
);
} else {
this.downloadDialog.visible = false;
this.pendingVRCXInstall = this.downloadCurrent.ref.name;
@@ -26202,8 +26210,8 @@ speechSynthesis.getVoices();
}
};
$app.methods.restartVRCX = function () {
AppApi.RestartApplication();
$app.methods.restartVRCX = function (isUpgrade) {
AppApi.RestartApplication(isUpgrade);
};
$app.methods.loadBranchVersions = async function () {
@@ -34005,7 +34013,8 @@ speechSynthesis.getVoices();
workerTimers.setTimeout(resolve, 100);
});
if (action === 'confirm') {
AppApi.RestartApplication();
var isUpgrade = false;
this.restartVRCX(isUpgrade);
}
}
}