This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
115 lines (93 loc) · 3.61 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace SteamVRSwitcher
{
public partial class Form1 : Form
{
private const string Version = "1.0.0.0";
private readonly string[] _SteamVRProcesses =
{
"vrdashboard", "vrserver",
"vrmonitor", "vrcompositor",
"steamvr_tutorial", "steamtours",
"vrwebhelper"
};
private readonly string _SteamInstallPath = @"D:\Jeux\Steam\steamapps\common";
private readonly string _SteamVREnabledPath;
private readonly string _SteamVRDisabledPath;
public bool IsEnabled => Directory.Exists(Path.Combine(_SteamInstallPath, "SteamVR"));
public bool IsDisabled => Directory.Exists(Path.Combine(_SteamInstallPath, "_SteamVR"));
public Form1()
{
InitializeComponent();
var openvrpaths = $@"c:\Users\{Environment.UserName}\AppData\Local\openvr\openvrpaths.vrpath";
if (File.Exists(openvrpaths))
{
var content = File.ReadAllText(openvrpaths);
var json = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
if (json.ContainsKey("runtime"))
{
var item = (JArray)json["runtime"];
if (item != null)
_SteamInstallPath = item.First.ToString().Replace("SteamVR\\", "");
}
}
_SteamVRDisabledPath = Path.Combine(_SteamInstallPath, "_SteamVR");
_SteamVREnabledPath = Path.Combine(_SteamInstallPath, "SteamVR");
LabelToggleStatus.Text = IsEnabled ? "Enabled" : "Disabled";
LabelSteamVRStatus.Text = IsSteamVRActive() ? "Active" : "Stopped";
Text += $" {Version}";
}
private void OnToggleButtonClick(object sender, EventArgs e)
{
var enabledPath = IsEnabled;
var disabledPath = IsDisabled;
if (!enabledPath && !disabledPath)
{
MessageBox.Show("SteamVR is not installed on this PC.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
KillSteamVR();
try
{
if (enabledPath)
Directory.Move(_SteamVREnabledPath, _SteamVRDisabledPath);
else
Directory.Move(_SteamVRDisabledPath, _SteamVREnabledPath);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error during change", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LabelToggleStatus.Text = !enabledPath ? "Enabled" : "Disabled";
}
private void OnKillButtonClick(object sender, EventArgs e) => KillSteamVR();
private void KillSteamVR()
{
foreach (var name in _SteamVRProcesses)
{
var processes = Process.GetProcessesByName(name);
if (processes.Length == 0)
continue;
foreach (var process in processes)
process.Kill();
}
LabelSteamVRStatus.Text = "Stopped";
}
private bool IsSteamVRActive()
{
foreach (var name in _SteamVRProcesses)
{
var processes = Process.GetProcessesByName(name);
if (processes.Length > 0)
return true;
}
return false;
}
}
}