forked from cosmii02/RacingDSX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppCheckThread.cs
More file actions
179 lines (152 loc) · 4.58 KB
/
AppCheckThread.cs
File metadata and controls
179 lines (152 loc) · 4.58 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace RacingDSX
{
public struct AppCheckReportStruct
{
public enum AppType : ushort
{
NONE = 0,
DSX = 1,
GAME = 2
}
public AppCheckReportStruct(AppType type, string msg, bool val = false)
{
this.type = type;
this.message = msg;
this.value = val;
}
public AppCheckReportStruct(AppType type, bool val, string msg = null)
{
this.type = type;
this.message = msg;
this.value = val;
}
public AppCheckReportStruct(AppType type)
{
this.type = type;
this.message = String.Empty;
this.value = false;
}
public AppType type = 0;
public string message = string.Empty;
public bool value = false;
}
public class AppCheckThread
{
readonly RacingDSX.Config.Config settings;
private Dictionary<String, String> processProfilePairs = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private Process process;
readonly IProgress<AppCheckReportStruct> progressReporter;
protected bool bRunning = false;
public AppCheckThread(ref RacingDSX.Config.Config currentSettings, IProgress<AppCheckReportStruct> progressReporter, Process process = null)
{
settings = currentSettings;
this.progressReporter = progressReporter;
this.process = process;
bRunning = false;
}
public void updateExecutables()
{
lock (this)
{
processProfilePairs.Clear();
foreach (var profile in settings.Profiles)
{
if (!profile.Value.IsEnabled) { continue; }
profile.Value.executableNames.ForEach((name) =>
{
if (!processProfilePairs.ContainsKey(name))
{
processProfilePairs.Add(name, profile.Key);
}
});
}
// settings = currentSettings;
}
}
public void Run()
{
processProfilePairs.Clear();
foreach (var profile in settings.Profiles)
{
if (!profile.Value.IsEnabled) { continue; }
profile.Value.executableNames.ForEach((name) =>
{
if (!processProfilePairs.ContainsKey(name))
{
processProfilePairs.Add(name, profile.Key);
}
});
}
bRunning = true;
try
{
if (progressReporter != null)
{
progressReporter.Report(new AppCheckReportStruct(0, "Connecting to Forza and DSX"));
}
//int forzaProcesses = 0;
Process[] DSX, DSX_2, DSY;
AppCheckReportStruct dsxReport = new AppCheckReportStruct(AppCheckReportStruct.AppType.DSX);
AppCheckReportStruct forzaReport = new AppCheckReportStruct(AppCheckReportStruct.AppType.GAME);
while (bRunning)
{
System.Threading.Thread.Sleep(1000);
lock (this) {
if (!bRunning) { break; }
forzaReport.value = false;
forzaReport.message = "";
if (process != null)
{
if (!process.HasExited)
{
forzaReport.value = true;
forzaReport.message = processProfilePairs[process.ProcessName];
}
}
else
{
foreach (var processName in processProfilePairs.Keys.AsEnumerable())
{
if (Process.GetProcessesByName(processName).Length > 0)
{
forzaReport.value = true;
forzaReport.message = processProfilePairs[processName];
break;
}
}
}
// DSX = "DSX" or "DualSenseX"
DSX = Process.GetProcessesByName("DSX");
DSX_2 = Process.GetProcessesByName("DualsenseX");
DSY = Process.GetProcessesByName("DualSenseY");
dsxReport.value = (DSX.Length + DSX_2.Length + DSY.Length) > 0;
//forzaReport.value = forzaProcesses > 0;
//forzaReport.value = true;
//TODO: CHANGE
if (!bRunning) { break; }
if (progressReporter != null)
{
progressReporter.Report(dsxReport);
progressReporter.Report(forzaReport);
}
}
}
}
catch (Exception e)
{
if (progressReporter != null)
{
progressReporter.Report(new AppCheckReportStruct(0, "Application encountered an exception: " + e.Message));
}
}
}
public void Stop()
{
bRunning = false;
}
}
}