From 5a8544454e08f86b061ec829911d546c59e51c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sat, 11 Aug 2012 21:48:54 +0000 Subject: [PATCH] Added a few checks and delays to the driver loading code to increase the chance of loading the driver. --- Hardware/Ring0.cs | 21 ++++++++++++++++++++- Properties/AssemblyVersion.cs | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Hardware/Ring0.cs b/Hardware/Ring0.cs index b37ac80..155be61 100644 --- a/Hardware/Ring0.cs +++ b/Hardware/Ring0.cs @@ -98,13 +98,29 @@ namespace OpenHardwareMonitor.Hardware { try { using (FileStream target = new FileStream(fileName, FileMode.Create)) { target.Write(buffer, 0, buffer.Length); + target.Flush(); } } catch (IOException) { // for example there is not enough space on the disk return false; } - return true; + // make sure the file is actually writen to the file system + for (int i = 0; i < 20; i++) { + try { + if (File.Exists(fileName) && + new FileInfo(fileName).Length == buffer.Length) + { + return true; + } + Thread.Sleep(100); + } catch (IOException) { + Thread.Sleep(10); + } + } + + // file still has not the right size, something is wrong + return false; } public static void Open() { @@ -141,6 +157,9 @@ namespace OpenHardwareMonitor.Hardware { // install failed, try to delete and reinstall driver.Delete(); + // wait a short moment to give the OS a chance to remove the driver + Thread.Sleep(2000); + string errorSecondInstall; if (driver.Install(fileName, out errorSecondInstall)) { driver.Open(); diff --git a/Properties/AssemblyVersion.cs b/Properties/AssemblyVersion.cs index 8e06c7f..28c56fd 100644 --- a/Properties/AssemblyVersion.cs +++ b/Properties/AssemblyVersion.cs @@ -10,5 +10,5 @@ using System.Reflection; -[assembly: AssemblyVersion("0.5.1.1")] -[assembly: AssemblyInformationalVersion("0.5.1.1 Alpha")] \ No newline at end of file +[assembly: AssemblyVersion("0.5.1.2")] +[assembly: AssemblyInformationalVersion("0.5.1.2 Alpha")] \ No newline at end of file