-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTSSHandler.cs
83 lines (76 loc) · 2.15 KB
/
RTSSHandler.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
using System.Diagnostics;
using System.Media;
using System.Threading;
using System.Windows.Forms;
using RTSSSharedMemoryNET;
namespace rtssh
{
internal static class RtssHandler
{
#region Fields
private static Process _rtssInstance;
private static OSD _osd;
#endregion
#region Properties
// Path to RTSS
private static string RtssPath {get;}
// Return true if RTSS is running
private static bool IsRunning => Process.GetProcessesByName("RTSS").Length != 0;
#endregion
#region Constructor
// Initialize a new instance of the RTSSHandler class
static RtssHandler()
{
RtssPath = @"C:\Program Files (x86)\RivaTuner Statistics Server\RTSS.exe";
}
#endregion
#region Methods
// Send text to RTSS
public static void Print(string text)
{
if (IsRunning)
{
_osd?.Update(text);
}
}
/// Launch RTSS
public static void RunRtss()
{
if (_rtssInstance == null && !IsRunning)
{
try
{
_rtssInstance = Process.Start(RtssPath);
Thread.Sleep(2000);
RunOsd();
}
catch
{
LaunchForm.MainForm.ConnectionStatus = ConnectionStatus.Disconnected;
SystemSounds.Beep.Play();
MessageBox.Show(@"Make sure RTSS is installed in the default location!");
}
}
else
{
RunOsd();
}
}
// Launches OSD
private static void RunOsd()
{
if (_osd != null) return;
try
{
_osd = new OSD("rtssh");
}
catch
{
LaunchForm.MainForm.ConnectionStatus = ConnectionStatus.Disconnected;
SystemSounds.Beep.Play();
MessageBox.Show(@"Could not start OSD!");
}
}
#endregion
}
}