Added some error reporting to the Ring0 driver loading code.

This commit is contained in:
Michael Möller
2011-02-08 22:02:29 +00:00
parent 12844967da
commit d1a963aa55
3 changed files with 43 additions and 11 deletions
+7
View File
@@ -222,6 +222,13 @@ namespace OpenHardwareMonitor.Hardware {
w.WriteLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
w.WriteLine();
string r = Ring0.GetReport();
if (r != null) {
NewSection(w);
w.Write(r);
w.WriteLine();
}
NewSection(w);
w.WriteLine("Sensors");
w.WriteLine();
+34 -9
View File
@@ -16,7 +16,7 @@
The Initial Developer of the Original Code is
Michael Möller <m.moeller@gmx.ch>.
Portions created by the Initial Developer are Copyright (C) 2010
Portions created by the Initial Developer are Copyright (C) 2010-2011
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -40,12 +40,14 @@ using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Text;
namespace OpenHardwareMonitor.Hardware {
internal static class Ring0 {
private static KernelDriver driver;
private static Mutex isaBusMutex;
private static readonly StringBuilder report = new StringBuilder();
private const uint OLS_TYPE = 40000;
private static IOControlCode
@@ -95,28 +97,41 @@ namespace OpenHardwareMonitor.Hardware {
}
public static void Open() {
// No implementation for Unix systems
// no implementation for unix systems
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
return;
if (driver != null)
return;
// clear the current report
report.Length = 0;
driver = new KernelDriver("WinRing0_1_2_0");
driver.Open();
if (!driver.IsOpen) {
// driver is not loaded, try to install and open
string fileName = Path.GetTempFileName();
if (ExtractDriver(fileName)) {
if (driver.Install(fileName)) {
File.Delete(fileName);
driver.Open();
driver.Install(fileName);
File.Delete(fileName);
driver.Open();
if (!driver.IsOpen)
driver.Delete();
if (!driver.IsOpen) {
driver.Delete();
report.AppendLine("Status: Opening driver failed");
}
} else {
report.AppendLine("Status: Installing driver failed");
report.AppendLine();
report.Append("Exception: " + Marshal.GetExceptionForHR(
Marshal.GetHRForLastWin32Error()).Message);
}
} else {
report.AppendLine(
"Status: Extracting driver to \"" + fileName + "\" failed");
}
}
@@ -147,6 +162,16 @@ namespace OpenHardwareMonitor.Hardware {
isaBusMutex.Close();
}
public static string GetReport() {
if (report.Length > 0) {
report.Insert(0, "Ring0" + Environment.NewLine +
Environment.NewLine);
report.AppendLine();
return report.ToString();
} else
return null;
}
public static bool WaitIsaBusMutex(int millisecondsTimeout) {
try {
return isaBusMutex.WaitOne(millisecondsTimeout, false);
+2 -2
View File
@@ -37,5 +37,5 @@
using System.Reflection;
[assembly: AssemblyVersion("0.2.1.11")]
[assembly: AssemblyInformationalVersion("0.2.1.11 Alpha")]
[assembly: AssemblyVersion("0.2.1.12")]
[assembly: AssemblyInformationalVersion("0.2.1.12 Alpha")]