Added some error reporting to the Ring0 driver loading code.
authormoel.mich
Tue, 08 Feb 2011 22:02:29 +0000
changeset 254d8079800a888
parent 253 0044b05a3094
child 255 a608358af258
Added some error reporting to the Ring0 driver loading code.
Hardware/Computer.cs
Hardware/Ring0.cs
Properties/AssemblyVersion.cs
     1.1 --- a/Hardware/Computer.cs	Mon Feb 07 22:06:58 2011 +0000
     1.2 +++ b/Hardware/Computer.cs	Tue Feb 08 22:02:29 2011 +0000
     1.3 @@ -222,6 +222,13 @@
     1.4          w.WriteLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
     1.5          w.WriteLine();
     1.6  
     1.7 +        string r = Ring0.GetReport();
     1.8 +        if (r != null) {
     1.9 +          NewSection(w);
    1.10 +          w.Write(r);
    1.11 +          w.WriteLine();
    1.12 +        }
    1.13 +
    1.14          NewSection(w);
    1.15          w.WriteLine("Sensors");
    1.16          w.WriteLine();
     2.1 --- a/Hardware/Ring0.cs	Mon Feb 07 22:06:58 2011 +0000
     2.2 +++ b/Hardware/Ring0.cs	Tue Feb 08 22:02:29 2011 +0000
     2.3 @@ -16,7 +16,7 @@
     2.4  
     2.5    The Initial Developer of the Original Code is 
     2.6    Michael Möller <m.moeller@gmx.ch>.
     2.7 -  Portions created by the Initial Developer are Copyright (C) 2010
     2.8 +  Portions created by the Initial Developer are Copyright (C) 2010-2011
     2.9    the Initial Developer. All Rights Reserved.
    2.10  
    2.11    Contributor(s):
    2.12 @@ -40,12 +40,14 @@
    2.13  using System.Reflection;
    2.14  using System.Runtime.InteropServices;
    2.15  using System.Threading;
    2.16 +using System.Text;
    2.17  
    2.18  namespace OpenHardwareMonitor.Hardware {
    2.19    internal static class Ring0 {
    2.20  
    2.21      private static KernelDriver driver;
    2.22      private static Mutex isaBusMutex;
    2.23 +    private static readonly StringBuilder report = new StringBuilder();
    2.24  
    2.25      private const uint OLS_TYPE = 40000;
    2.26      private static IOControlCode
    2.27 @@ -95,28 +97,41 @@
    2.28      }
    2.29  
    2.30      public static void Open() {
    2.31 -      // No implementation for Unix systems
    2.32 +      // no implementation for unix systems
    2.33        int p = (int)Environment.OSVersion.Platform;
    2.34        if ((p == 4) || (p == 128))
    2.35          return;  
    2.36        
    2.37        if (driver != null)
    2.38          return;
    2.39 +
    2.40 +      // clear the current report
    2.41 +      report.Length = 0;
    2.42       
    2.43        driver = new KernelDriver("WinRing0_1_2_0");
    2.44        driver.Open();
    2.45  
    2.46        if (!driver.IsOpen) {
    2.47 +        // driver is not loaded, try to install and open
    2.48          string fileName = Path.GetTempFileName();
    2.49          if (ExtractDriver(fileName)) {
    2.50 +          if (driver.Install(fileName)) {
    2.51 +            File.Delete(fileName);
    2.52 +            driver.Open();
    2.53  
    2.54 -          driver.Install(fileName);
    2.55 -          File.Delete(fileName);
    2.56 -
    2.57 -          driver.Open();
    2.58 -
    2.59 -          if (!driver.IsOpen)
    2.60 -            driver.Delete();
    2.61 +            if (!driver.IsOpen) {
    2.62 +              driver.Delete();
    2.63 +              report.AppendLine("Status: Opening driver failed");
    2.64 +            }
    2.65 +          } else {
    2.66 +            report.AppendLine("Status: Installing driver failed");
    2.67 +            report.AppendLine();
    2.68 +            report.Append("Exception: " + Marshal.GetExceptionForHR(
    2.69 +              Marshal.GetHRForLastWin32Error()).Message);
    2.70 +          }
    2.71 +        } else {
    2.72 +          report.AppendLine(
    2.73 +            "Status: Extracting driver to \"" + fileName + "\" failed");
    2.74          }
    2.75        }
    2.76  
    2.77 @@ -147,6 +162,16 @@
    2.78        isaBusMutex.Close(); 
    2.79      }
    2.80  
    2.81 +    public static string GetReport() {
    2.82 +      if (report.Length > 0) {
    2.83 +        report.Insert(0, "Ring0" + Environment.NewLine +
    2.84 +          Environment.NewLine);
    2.85 +        report.AppendLine();
    2.86 +        return report.ToString();
    2.87 +      } else
    2.88 +        return null;
    2.89 +    }
    2.90 +
    2.91      public static bool WaitIsaBusMutex(int millisecondsTimeout) {
    2.92        try {
    2.93          return isaBusMutex.WaitOne(millisecondsTimeout, false);
     3.1 --- a/Properties/AssemblyVersion.cs	Mon Feb 07 22:06:58 2011 +0000
     3.2 +++ b/Properties/AssemblyVersion.cs	Tue Feb 08 22:02:29 2011 +0000
     3.3 @@ -37,5 +37,5 @@
     3.4  
     3.5  using System.Reflection;
     3.6  
     3.7 -[assembly: AssemblyVersion("0.2.1.11")]
     3.8 -[assembly: AssemblyInformationalVersion("0.2.1.11 Alpha")]
     3.9 \ No newline at end of file
    3.10 +[assembly: AssemblyVersion("0.2.1.12")]
    3.11 +[assembly: AssemblyInformationalVersion("0.2.1.12 Alpha")]
    3.12 \ No newline at end of file