diff --git a/Dotnet/PWI/WorldDBManager.cs b/Dotnet/PWI/WorldDBManager.cs index f242c241..7bf50eda 100644 --- a/Dotnet/PWI/WorldDBManager.cs +++ b/Dotnet/PWI/WorldDBManager.cs @@ -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 + } } } } \ No newline at end of file diff --git a/Dotnet/Program.cs b/Dotnet/Program.cs index 8c00ce3b..daa9a6b4 100644 --- a/Dotnet/Program.cs +++ b/Dotnet/Program.cs @@ -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(); diff --git a/Dotnet/StartupArgs.cs b/Dotnet/StartupArgs.cs index 3b67cf46..47081ea5 100644 --- a/Dotnet/StartupArgs.cs +++ b/Dotnet/StartupArgs.cs @@ -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)