mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-31 06:15:08 +00:00
Fixed Issue 218.
This commit is contained in:
@@ -71,6 +71,27 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
IOCTL_OLS_READ_MEMORY = new IOControlCode(OLS_TYPE, 0x841,
|
IOCTL_OLS_READ_MEMORY = new IOControlCode(OLS_TYPE, 0x841,
|
||||||
IOControlCode.Access.Read);
|
IOControlCode.Access.Read);
|
||||||
|
|
||||||
|
private static string GetTempFileName() {
|
||||||
|
|
||||||
|
// try to get a file in the temporary folder
|
||||||
|
try {
|
||||||
|
return Path.GetTempFileName();
|
||||||
|
} catch (IOException) { }
|
||||||
|
catch (UnauthorizedAccessException) { }
|
||||||
|
|
||||||
|
// if this failed, we try to create one in the application folder
|
||||||
|
string fileName = Path.ChangeExtension(
|
||||||
|
Assembly.GetExecutingAssembly().Location, ".sys");
|
||||||
|
try {
|
||||||
|
using (FileStream stream = File.Create(fileName)) {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
} catch (IOException) { }
|
||||||
|
catch (UnauthorizedAccessException) { }
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool ExtractDriver(string fileName) {
|
private static bool ExtractDriver(string fileName) {
|
||||||
string resourceName = "OpenHardwareMonitor.Hardware." +
|
string resourceName = "OpenHardwareMonitor.Hardware." +
|
||||||
(IntPtr.Size == 4 ? "WinRing0.sys" : "WinRing0x64.sys");
|
(IntPtr.Size == 4 ? "WinRing0.sys" : "WinRing0x64.sys");
|
||||||
@@ -118,8 +139,8 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
// driver is not loaded, try to reinstall and open
|
// driver is not loaded, try to reinstall and open
|
||||||
|
|
||||||
driver.Delete();
|
driver.Delete();
|
||||||
fileName = Path.GetTempFileName();
|
fileName = GetTempFileName();
|
||||||
if (ExtractDriver(fileName)) {
|
if (fileName != null && ExtractDriver(fileName)) {
|
||||||
if (driver.Install(fileName)) {
|
if (driver.Install(fileName)) {
|
||||||
driver.Open();
|
driver.Open();
|
||||||
|
|
||||||
@@ -128,17 +149,15 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
report.AppendLine("Status: Opening driver failed");
|
report.AppendLine("Status: Opening driver failed");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report.AppendLine("Status: Installing driver \"" +
|
report.AppendLine("Status: Installing driver \"" +
|
||||||
fileName + "\" failed" +
|
fileName + "\" failed" +
|
||||||
(File.Exists(fileName) ? " and file exists" : ""));
|
(File.Exists(fileName) ? " and file exists" : ""));
|
||||||
report.AppendLine();
|
report.AppendLine();
|
||||||
report.Append("Exception: " + Marshal.GetExceptionForHR(
|
report.Append("Exception: " + Marshal.GetExceptionForHR(
|
||||||
Marshal.GetHRForLastWin32Error()).Message);
|
Marshal.GetHRForLastWin32Error()).Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
report.AppendLine(
|
report.AppendLine("Status: Extracting driver failed");
|
||||||
"Status: Extracting driver to \"" + fileName + "\" failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user