forked from BnuuySolutions/OculusKiller
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Changed VRServerMonitor to ProcessMonitor, added better crash…
… detect
- Loading branch information
1 parent
fa33e4b
commit 5a69ce7
Showing
4 changed files
with
69 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using OculusKiller.Utilities; | ||
|
||
namespace OculusKiller.Core | ||
{ | ||
internal class ProcessMonitor | ||
{ | ||
private const int MaxRetries = 3; // Maximum number of consecutive restart attempts | ||
|
||
public static void MonitorProcesses(string vrServerPath, string oculusPath) | ||
{ | ||
int retryCount = 0; | ||
|
||
while (retryCount < MaxRetries) // Monitoring loop with retry limit | ||
{ | ||
try | ||
{ | ||
var vrServerProcess = Process.GetProcessesByName("vrserver") | ||
.FirstOrDefault(process => process.MainModule.FileName == vrServerPath); | ||
|
||
var vrDashboardProcess = Process.GetProcessesByName("vrdashboard").FirstOrDefault(); | ||
|
||
if (vrServerProcess != null && vrDashboardProcess != null) | ||
{ | ||
ErrorLogger.Log("Monitoring vrserver and vrdashboard processes."); | ||
|
||
vrServerProcess.WaitForExit(); // Wait for the vrserver process to exit | ||
vrDashboardProcess.WaitForExit(); // Wait for the vrdashboard process to exit | ||
|
||
// Check exit codes to determine if processes crashed | ||
if (vrServerProcess.ExitCode != 0 || vrDashboardProcess.ExitCode != 0) | ||
{ | ||
ErrorLogger.Log("vrserver or vrdashboard process crashed. Restarting..."); | ||
// Restarting the SteamVR process | ||
ProcessUtilities.StartProcess(vrServerPath); | ||
retryCount++; | ||
} | ||
else | ||
{ | ||
ErrorLogger.Log("vrserver and vrdashboard processes exited normally."); | ||
break; // Exit the loop if processes terminated normally | ||
} | ||
} | ||
else | ||
{ | ||
ErrorLogger.Log("vrserver or vrdashboard process not found. Starting..."); | ||
// Restarting the SteamVR process | ||
ProcessUtilities.StartProcess(vrServerPath); | ||
retryCount++; | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorLogger.LogError(e); | ||
retryCount++; | ||
} | ||
} | ||
|
||
// After reaching the maximum retry limit, terminate SteamVR and Oculus Air Link | ||
ErrorLogger.Log("Maximum retry limit reached. Terminating SteamVR and Oculus Air Link."); | ||
ProcessUtilities.TerminateProcess("vrserver"); | ||
ProcessUtilities.TerminateProcess("OVRServer_x64"); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.