Skip to content

Commit

Permalink
Merge pull request #11 from Float3/dev
Browse files Browse the repository at this point in the history
Dev 11
  • Loading branch information
float3 authored Apr 19, 2022
2 parents 3261036 + 010d852 commit d818a08
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 311 deletions.
2 changes: 1 addition & 1 deletion VRCLauncher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<Setter Property="Foreground" Value="{DynamicResource ForegroundColorBrush}" />
<Setter Property="Background" Value="{DynamicResource WindowBackgroundColorBrush}" />
<Setter Property="ResizeMode" Value="CanResizeWithGrip" />
<Setter Property="SizeToContent" Value="WidthAndHeight" />
<!-- <Setter Property="SizeToContent" Value="WidthAndHeight" /> -->
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
<Setter Property="Template">
Expand Down
10 changes: 10 additions & 0 deletions VRCLauncher/Model/CompanionApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace VRCLauncher.Model;

public class CompanionApp
{
public string Name { get; set; }
public string Path { get; set; }
public string Args { get; set; }
public string Rules { get; set; }
public bool Enabled { get; set; }
}
125 changes: 105 additions & 20 deletions VRCLauncher/Model/Config.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Windows;
using Microsoft.Win32;

Expand All @@ -19,8 +23,10 @@ public class Config
public bool WatchAvatars { get; set; }
public bool Fullscreen { get; set; }
public int Width { get; set; }

public int Height { get; set; }
public int Monitor { get; set; }

// public int Monitor { get; set; }
public bool UdonDebugLogging { get; set; }
public bool DebugGUI { get; set; }
public bool SDKLogLevels { get; set; }
Expand All @@ -31,29 +37,43 @@ public class Config
public bool DisableShoulderTracking { get; set; }
public string LaunchInstance { get; set; }
public string ArbitraryArguments { get; set; }
public ObservableCollection<CompanionApp> CompanionApps { get; set; }
public bool LaunchCompanionApps { get; set; }

[JsonIgnore] public const string UserFolderPath = @"%AppData%\..\LocalLow\VRCLauncher\";
[JsonIgnore] public static string ExpandedUserFolderPath = Environment.ExpandEnvironmentVariables(UserFolderPath);
[JsonIgnore] public const string ConfigName = "config.json";

public Config()
{
NoVR = false;
FPS = 90;
LegacyFBTCalibrate = false;
Profile = 0;

WatchWorlds = false;
WatchAvatars = false;

Fullscreen = true;
Width = 0;
Height = 0;
Monitor = 0;
// Monitor = 0;

UdonDebugLogging = false;
DebugGUI = false;
SDKLogLevels = false;
VerboseLogging = false;
MidiDevice = "";

LegacyFBTCalibrate = false;
CustomArmRatio = "0.4537";
DisableShoulderTracking = false;

MidiDevice = "";
OSCPorts = "";
LaunchInstance = "";
ArbitraryArguments = "";

CompanionApps = new();
LaunchCompanionApps = true;
}

// ReSharper disable once IdentifierTypo
Expand All @@ -74,30 +94,28 @@ public static string FindVRCexePath()

public void Save()
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
"\\3\\VRCLauncher";
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
if (!Directory.Exists(ExpandedUserFolderPath)) Directory.CreateDirectory(ExpandedUserFolderPath);

string json = JsonSerializer.Serialize(this);
File.WriteAllText(appDataPath + "\\config.json", json);
File.WriteAllText(ExpandedUserFolderPath + ConfigName, json);
}

public static Config Load()
{
Config config = new();
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
"\\3\\VRCLauncher";
if (File.Exists(appDataPath + "\\config.json"))

if (File.Exists(ExpandedUserFolderPath + ConfigName))
{
string json = File.ReadAllText(appDataPath + "\\config.json");
string json = File.ReadAllText(ExpandedUserFolderPath + ConfigName);
try
{
config = JsonSerializer.Deserialize<Config>(json)!;
config.LaunchInstance = "";
}
catch (Exception e)
catch (Exception e) // JsonException
{
MessageBox.Show("Error loading config.json: \n" + e.Message + "\n this might be due to a update");
MessageBox.Show($"Error loading {ConfigName}: \n" + e.Message + "\n this might be due to a update",
"Error", MessageBoxButton.OK, MessageBoxImage.Error);
config = new();
}
}
Expand Down Expand Up @@ -144,16 +162,16 @@ public List<string> GetArgs()
args.Add(Height.ToString());
}

args.Add("-monitor");
args.Add(Monitor.ToString());
// args.Add("-monitor");
// args.Add(Monitor.ToString());

if (MidiDevice != "") args.Add("--midi=" + MidiDevice);

if (OSCPorts != "") args.Add("--osc-ports=" + OSCPorts);
if(CustomArmRatio != "") args.Add("--custom-arm-ratio=" + CustomArmRatio);
if(DisableShoulderTracking) args.Add("--disable-shoulder-tracking");

if (CustomArmRatio != "") args.Add("--custom-arm-ratio=" + CustomArmRatio);

if (DisableShoulderTracking) args.Add("--disable-shoulder-tracking");

if (LaunchInstance != "") args.Add(LaunchInstance);

Expand All @@ -164,4 +182,71 @@ public List<string> GetArgs()

return args;
}

public void LaunchApps(List<string> args)
{
if (LaunchCompanionApps)
{
foreach (CompanionApp app in CompanionApps)
{
bool launch = true;

if (app.Enabled)
{
if (app.Rules != "")
{
foreach (string rule in app.Rules.Split(";"))
{
if (rule.StartsWith("!"))
{
if (args.Contains(rule.Substring(1)))
{
launch = false;
break;
}
}
else
{
if (!args.Contains(rule))
{
launch = false;
break;
}
}
}
}

foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName.ToLower() == app.Name.ToLower())
{
launch = false;
break;
}
}

if (launch)
{
Process process = new();
if (app.Path.EndsWith(".exe"))
{
process.StartInfo.FileName = app.Path;
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(app.Path);
process.StartInfo.Arguments = app.Args;
process.Start();
}
else if (app.Path.EndsWith(".py"))
{
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = app.Path + " " + app.Args;
process.StartInfo.RedirectStandardInput = true;
process.Start();

process.StandardInput.WriteLine("python " + app.Path + " " + app.Args);
}
}
}
}
}
}
}
Loading

0 comments on commit d818a08

Please sign in to comment.