Change --config behavior to allow for multi instance

This commit is contained in:
Natsumi
2024-02-14 14:19:10 +13:00
parent e2e907da77
commit b7d5255f3b
3 changed files with 33 additions and 14 deletions
+10 -3
View File
@@ -734,9 +734,16 @@ namespace VRCX
public void Stop()
{
listener?.Stop();
listener?.Close();
worldDB?.Close();
try
{
worldDB?.Close();
listener?.Stop();
listener?.Close();
}
catch (ObjectDisposedException ex)
{
// ignore
}
}
}
}
+11 -8
View File
@@ -8,7 +8,6 @@ using NLog;
using NLog.Targets;
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VRCX
@@ -16,15 +15,19 @@ namespace VRCX
public static class Program
{
public static string BaseDirectory { get; private set; }
public static readonly string AppDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX");
public static string ConfigLocation;
public static string AppDataDirectory;
public static string ConfigLocation { get; private set; }
public static string Version { get; private set; }
public static bool LaunchDebug;
private static readonly NLog.Logger logger = NLog.LogManager.GetLogger("VRCX");
static Program()
private static void SetProgramDirectories()
{
if (string.IsNullOrEmpty(AppDataDirectory))
AppDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX");
BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
ConfigLocation = Path.Combine(Program.AppDataDirectory, "VRCX.sqlite3");
ConfigLocation = Path.Combine(AppDataDirectory, "VRCX.sqlite3");
if (!Directory.Exists(AppDataDirectory))
{
@@ -97,8 +100,6 @@ namespace VRCX
[STAThread]
private static void Main()
{
ConfigureLogger();
try
{
Run();
@@ -127,8 +128,10 @@ namespace VRCX
private static void Run()
{
BrowserSubprocess.Start();
Update.Check();
StartupArgs.ArgsCheck();
SetProgramDirectories();
ConfigureLogger();
Update.Check();
GetVersion();
Application.EnableVisualStyles();
+12 -3
View File
@@ -6,6 +6,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Text;
using System.Windows.Forms;
@@ -31,14 +32,22 @@ namespace VRCX
LaunchCommand = arg.Substring(12);
if (arg.Length > 8 && arg.Substring(0, 8) == "--config")
Program.ConfigLocation = arg.Substring(9);
{
var filePath = arg.Substring(9);
if (File.Exists(filePath))
{
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 = filePath;
}
if ((arg.Length >= 7 && arg.Substring(0, 7) == "--debug") || isDebug)
Program.LaunchDebug = true;
}
if (processList.Length > 1 && !string.IsNullOrEmpty(LaunchCommand))
return; // if we're launching with a parameter, allow it
if (!string.IsNullOrEmpty(Program.AppDataDirectory))
return; // we're launching with a custom config path, allow it
// if we're launching a second instance, focus the first instance then exit
if (processList.Length > 1)