Added a few checks and delays to the driver loading code to increase the chance of loading the driver.
authormoel.mich
Sat, 11 Aug 2012 21:48:54 +0000
changeset 3797af3aaeb42e9
parent 378 64d3ddf8d73b
child 380 573f1fff48b2
Added a few checks and delays to the driver loading code to increase the chance of loading the driver.
Hardware/Ring0.cs
Properties/AssemblyVersion.cs
     1.1 --- a/Hardware/Ring0.cs	Sat Aug 11 21:32:59 2012 +0000
     1.2 +++ b/Hardware/Ring0.cs	Sat Aug 11 21:48:54 2012 +0000
     1.3 @@ -98,13 +98,29 @@
     1.4        try {
     1.5          using (FileStream target = new FileStream(fileName, FileMode.Create)) {
     1.6            target.Write(buffer, 0, buffer.Length);
     1.7 +          target.Flush();
     1.8          }
     1.9        } catch (IOException) { 
    1.10          // for example there is not enough space on the disk
    1.11          return false; 
    1.12        }
    1.13  
    1.14 -      return true;
    1.15 +      // make sure the file is actually writen to the file system
    1.16 +      for (int i = 0; i < 20; i++) {
    1.17 +        try {
    1.18 +          if (File.Exists(fileName) &&
    1.19 +            new FileInfo(fileName).Length == buffer.Length) 
    1.20 +          {
    1.21 +            return true;
    1.22 +          }
    1.23 +          Thread.Sleep(100);
    1.24 +        } catch (IOException) {
    1.25 +          Thread.Sleep(10);
    1.26 +        }
    1.27 +      }
    1.28 +      
    1.29 +      // file still has not the right size, something is wrong
    1.30 +      return false;
    1.31      }
    1.32  
    1.33      public static void Open() {
    1.34 @@ -141,6 +157,9 @@
    1.35              // install failed, try to delete and reinstall
    1.36              driver.Delete();
    1.37  
    1.38 +            // wait a short moment to give the OS a chance to remove the driver
    1.39 +            Thread.Sleep(2000);
    1.40 +
    1.41              string errorSecondInstall;
    1.42              if (driver.Install(fileName, out errorSecondInstall)) {
    1.43                driver.Open();
     2.1 --- a/Properties/AssemblyVersion.cs	Sat Aug 11 21:32:59 2012 +0000
     2.2 +++ b/Properties/AssemblyVersion.cs	Sat Aug 11 21:48:54 2012 +0000
     2.3 @@ -10,5 +10,5 @@
     2.4  
     2.5  using System.Reflection;
     2.6  
     2.7 -[assembly: AssemblyVersion("0.5.1.1")]
     2.8 -[assembly: AssemblyInformationalVersion("0.5.1.1 Alpha")]
     2.9 \ No newline at end of file
    2.10 +[assembly: AssemblyVersion("0.5.1.2")]
    2.11 +[assembly: AssemblyInformationalVersion("0.5.1.2 Alpha")]
    2.12 \ No newline at end of file