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