Files
VRCX/Program.cs
Natsumi bb31ce5736 feat: Add an automatic app launcher (#541)
* refactor: Change OpenImageFolder to use a winapi call

It will open the given file in any existing explorer instances instead of opening a new shell every time, handle longer paths, and work with third-party filesystem viewers with winapi hooks(well, this one).

* feat: Add an automatic app launcher

The launcer will automatically launch apps in the 'startup' folder under the VRCX appdata folder when VRChat has started, and close them when VRChat dies(or is closed).

* refactor: Add new class for monitoring VRC processes

This replaces the old AppApi functionality that would poll all processes twice to grab the status of both VRChat and vrserver.exe every... *checks app.js* 500ms.

It also raises events for when a monitored process is started/closed, mainly for the new AppLauncher feature, which is now using this class instead of monitoring vrchat itself.

* refactor: Add tooltip for launch folder button

* docs: Add some notes on potential issues with Process.HasExited

* Change CheckGameRunning from polling to events

---------

Co-authored-by: Teacup <git@teadev.xyz>
2023-05-10 16:57:25 +12:00

109 lines
3.7 KiB
C#

// Copyright(c) 2019-2022 pypy, Natsumi and individual contributors.
// All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using System;
using System.IO;
using System.Windows.Forms;
namespace VRCX
{
public static class Program
{
public static string BaseDirectory { get; private set; }
public static string AppDataDirectory { get; private set; }
public static string ConfigLocation;
public static string Version { get; private set; }
public static bool LaunchDebug;
public static bool GPUFix;
static Program()
{
BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
AppDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX");
ConfigLocation = Path.Combine(Program.AppDataDirectory, "VRCX.sqlite3");
if (!Directory.Exists(AppDataDirectory))
{
Directory.CreateDirectory(AppDataDirectory);
// Migrate config to AppData
if (File.Exists(Path.Combine(BaseDirectory, "VRCX.json")))
{
File.Move(Path.Combine(BaseDirectory, "VRCX.json"), Path.Combine(AppDataDirectory, "VRCX.json"));
File.Copy(Path.Combine(AppDataDirectory, "VRCX.json"), Path.Combine(AppDataDirectory, "VRCX-backup.json"));
}
if (File.Exists(Path.Combine(BaseDirectory, "VRCX.sqlite3")))
{
File.Move(Path.Combine(BaseDirectory, "VRCX.sqlite3"), Path.Combine(AppDataDirectory, "VRCX.sqlite3"));
File.Copy(Path.Combine(AppDataDirectory, "VRCX.sqlite3"), Path.Combine(AppDataDirectory, "VRCX-backup.sqlite3"));
}
}
}
[STAThread]
private static void Main()
{
try
{
Run();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "PLEASE REPORT IN https://vrcx.pypy.moe/discord", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
}
private static void GetVersion()
{
var buildName = "VRCX";
try
{
Version = $"{buildName} {File.ReadAllText(Path.Combine(BaseDirectory, "Version"))}";
}
catch (Exception)
{
Version = $"{buildName} Build";
}
}
private static void Run()
{
Update.Check();
StartupArgs.ArgsCheck();
GetVersion();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ProcessMonitor.Instance.Init();
SQLite.Instance.Init();
VRCXStorage.Load();
CpuMonitor.Instance.Init();
Discord.Instance.Init();
WebApi.Instance.Init();
LogWatcher.Instance.Init();
AutoAppLaunchManager.Instance.Init();
CefService.Instance.Init();
IPCServer.Instance.Init();
VRCXVR.Instance.Init();
Application.Run(new MainForm());
WebApi.Instance.SaveCookies();
VRCXVR.Instance.Exit();
CefService.Instance.Exit();
AutoAppLaunchManager.Instance.Exit();
LogWatcher.Instance.Exit();
WebApi.Instance.Exit();
Discord.Instance.Exit();
CpuMonitor.Instance.Exit();
VRCXStorage.Save();
SQLite.Instance.Exit();
ProcessMonitor.Instance.Exit();
}
}
}