Skip to content

Commit

Permalink
Merge branch 'Main-Beta' into Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliminater74 committed Nov 29, 2023
2 parents e27b987 + e562c59 commit 20903e0
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 32 deletions.
Empty file added D0_Snippets.as
Empty file.
11 changes: 8 additions & 3 deletions OculusKiller/Core/MainOculusKiller.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OculusKiller.Utilities;
using OculusKiller.RuntimeManagement; // Add this to use OpenXRRuntimeChecker
using OculusKiller.Utilities;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
Expand All @@ -14,11 +15,14 @@ public static async Task Main()
// Logging the start of the application
ErrorLogger.Log("Application started.");

// Check and log OpenXR runtimes
OpenXRRuntimeChecker.CheckAndLogRuntimes(); // Added line to log OpenXR runtimes

// Retrieving and validating the Oculus path
string oculusPath = PathUtilities.GetOculusPath();
if (string.IsNullOrEmpty(oculusPath))
{
ErrorLogger.LogError(new Exception("Oculus path not found."));
ErrorLogger.LogError(new Exception("Oculus path not found."), isCritical: false);
return;
}
ErrorLogger.Log($"Oculus path: {oculusPath}");
Expand All @@ -27,7 +31,7 @@ public static async Task Main()
var steamPaths = PathUtilities.GetSteamPaths();
if (steamPaths == null)
{
ErrorLogger.LogError(new Exception("Steam paths not found."));
ErrorLogger.LogError(new Exception("Steam paths not found."), isCritical: false);
return;
}

Expand All @@ -40,6 +44,7 @@ public static async Task Main()
Process steamProcess = ProcessUtilities.StartProcess(startupPath);
if (steamProcess == null)
{
ErrorLogger.LogError(new Exception("Failed to start SteamVR process."), isCritical: false);
return;
}

Expand Down
1 change: 1 addition & 0 deletions OculusKiller/OculusKiller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ItemGroup>
<Compile Include="Core\MainOculusKiller.cs" />
<Compile Include="Utilities\ErrorLogger.cs" />
<Compile Include="Utilities\OpenXRRuntimeChecker.cs" />
<Compile Include="Utilities\PathUtilities.cs" />
<Compile Include="Utilities\ProcessExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
4 changes: 2 additions & 2 deletions OculusKiller/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
31 changes: 24 additions & 7 deletions OculusKiller/Utilities/ErrorLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,47 @@ namespace OculusKiller.Utilities
{
public static class ErrorLogger
{
private static string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "OculusKiller", "OculusKiller.log");
// Path for the log file
private static readonly string logPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"OculusKiller",
"OculusKiller.log");

// Method to log general messages
public static void Log(string message)
{
InitializeLogging();
File.AppendAllText(logPath, DateTime.Now + ": " + message + "\n");
string formattedMessage = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [INFO] {message}";
File.AppendAllText(logPath, formattedMessage + Environment.NewLine);
}

// Method to log exceptions
public static void LogError(Exception exception, bool isCritical = false)
{
string errorMessage = $"An error occurred: {exception.Message}";
Log(errorMessage);
InitializeLogging();
string errorMessage = FormatExceptionMessage(exception);
File.AppendAllText(logPath, errorMessage + Environment.NewLine);

if (isCritical)
{
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(errorMessage, "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

// Helper method to format exception messages
private static string FormatExceptionMessage(Exception exception)
{
return $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [ERROR] An error occurred: {exception.Message}\n" +
$"Stack Trace: {exception.StackTrace}";
}

// Ensures the log directory exists
private static void InitializeLogging()
{
if (!Directory.Exists(Path.GetDirectoryName(logPath)))
string directory = Path.GetDirectoryName(logPath);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(Path.GetDirectoryName(logPath));
Directory.CreateDirectory(directory);
}
}
}
Expand Down
66 changes: 66 additions & 0 deletions OculusKiller/Utilities/OpenXRRuntimeChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Microsoft.Win32;
using OculusKiller.Utilities;
using System;
using System.Collections.Generic;

namespace OculusKiller.RuntimeManagement
{
public static class OpenXRRuntimeChecker
{
private const string OpenXRKeyPath = @"SOFTWARE\Khronos\OpenXR\1";

public static void CheckAndLogRuntimes()
{
try
{
// Log available runtimes
var availableRuntimes = GetAvailableRuntimes();
ErrorLogger.Log("Available OpenXR Runtimes:");
foreach (var runtime in availableRuntimes)
{
ErrorLogger.Log(runtime);
}

// Log active runtime
var activeRuntime = GetActiveRuntime();
ErrorLogger.Log($"Active OpenXR Runtime: {activeRuntime}");
}
catch (Exception e)
{
ErrorLogger.LogError(e);
}
}

private static List<string> GetAvailableRuntimes()
{
var runtimes = new List<string>();
using (var key = Registry.LocalMachine.OpenSubKey($@"{OpenXRKeyPath}\AvailableRuntimes"))
{
if (key != null)
{
foreach (var valueName in key.GetValueNames())
{
var runtimePath = key.GetValue(valueName) as string;
if (!string.IsNullOrEmpty(runtimePath))
{
runtimes.Add(runtimePath);
}
}
}
}
return runtimes;
}

private static string GetActiveRuntime()
{
using (var key = Registry.LocalMachine.OpenSubKey(OpenXRKeyPath))
{
if (key != null)
{
return key.GetValue("ActiveRuntime") as string;
}
}
return "No active runtime found.";
}
}
}
43 changes: 28 additions & 15 deletions OculusKiller/Utilities/ProcessMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using OculusKiller.Utilities;
using System;
using System.Diagnostics;
using System.Linq;
using OculusKiller.Utilities;

namespace OculusKiller.Core
{
Expand All @@ -17,36 +17,35 @@ public static void MonitorProcesses(string vrServerPath, string oculusPath)
{
try
{
// Retrieving the vrserver and vrdashboard processes
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
// Wait for both processes to exit
vrServerProcess.WaitForExit();
vrDashboardProcess.WaitForExit();

// Check exit codes to determine if processes crashed
if (vrServerProcess.ExitCode != 0 || vrDashboardProcess.ExitCode != 0)
// Check if the user has intentionally exited SteamVR
if (DidUserExitSteamVR(vrServerProcess, vrDashboardProcess))
{
ErrorLogger.Log("vrserver or vrdashboard process crashed. Restarting...");
// Restarting the SteamVR process
ProcessUtilities.StartProcess(vrServerPath);
retryCount++;
ErrorLogger.Log("User has intentionally exited SteamVR.");
break; // Exit the loop as user has intentionally exited
}
else
{
ErrorLogger.Log("vrserver and vrdashboard processes exited normally.");
break; // Exit the loop if processes terminated normally
ErrorLogger.Log("vrserver or vrdashboard process crashed. Restarting...");
ProcessUtilities.StartProcess(vrServerPath);
retryCount++;
}
}
else
{
ErrorLogger.Log("vrserver or vrdashboard process not found. Starting...");
// Restarting the SteamVR process
ProcessUtilities.StartProcess(vrServerPath);
retryCount++;
}
Expand All @@ -63,5 +62,19 @@ public static void MonitorProcesses(string vrServerPath, string oculusPath)
ProcessUtilities.TerminateProcess("vrserver");
ProcessUtilities.TerminateProcess("OVRServer_x64");
}

private static bool DidUserExitSteamVR(Process vrServerProcess, Process vrDashboardProcess)
{
// Check if the exit code is 0, which usually indicates a normal exit
if (vrServerProcess.ExitCode == 0 && vrDashboardProcess.ExitCode == 0)
{
return true; // User likely exited SteamVR normally
}

// Additional timing analysis can be implemented here if needed
// For example, checking the runtime of the processes, user activity, etc.

return false; // Default assumption is that the user did not exit normally
}
}
}
}
9 changes: 4 additions & 5 deletions OculusKiller/Utilities/ProcessUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using OculusKiller.Utilities;
using System;
using System;
using System.Diagnostics;
using System.Linq;

namespace OculusKiller.Utilities
{
Expand Down Expand Up @@ -36,12 +34,13 @@ public static void TerminateProcess(string processName)
{
process.Kill();
process.WaitForExit();
ErrorLogger.Log($"Terminated process: {process.ProcessName}");
}
catch (Exception e)
{
ErrorLogger.LogError(e);
ErrorLogger.LogError(new Exception($"Error terminating process: {process.ProcessName}. Error: {e.Message}"));
}
}
}
}
}
}

0 comments on commit 20903e0

Please sign in to comment.