Fixed Issue 387. The new implementation does not try to start a ring 0 driver that already exists, but could not be opened. It tries to delete the driver and install it new. The driver is now stored temporarily in the application folder. The driver is not correctly removed on system shutdown.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
11 using System.Collections.Generic;
12 using System.Globalization;
15 namespace OpenHardwareMonitor.Hardware.Nvidia {
17 internal class NvidiaGroup : IGroup {
19 private readonly List<Hardware> hardware = new List<Hardware>();
20 private readonly StringBuilder report = new StringBuilder();
22 public NvidiaGroup(ISettings settings) {
23 if (!NVAPI.IsAvailable)
26 report.AppendLine("NVAPI");
30 if (NVAPI.NvAPI_GetInterfaceVersionString(out version) == NvStatus.OK) {
31 report.Append("Version: ");
32 report.AppendLine(version);
35 NvPhysicalGpuHandle[] handles =
36 new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
38 if (NVAPI.NvAPI_EnumPhysicalGPUs == null) {
39 report.AppendLine("Error: NvAPI_EnumPhysicalGPUs not available");
43 NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count);
44 if (status != NvStatus.OK) {
45 report.AppendLine("Status: " + status);
51 IDictionary<NvPhysicalGpuHandle, NvDisplayHandle> displayHandles =
52 new Dictionary<NvPhysicalGpuHandle, NvDisplayHandle>();
54 if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null &&
55 NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null)
57 NvStatus status = NvStatus.OK;
59 while (status == NvStatus.OK) {
60 NvDisplayHandle displayHandle = new NvDisplayHandle();
61 status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle);
64 if (status == NvStatus.OK) {
65 NvPhysicalGpuHandle[] handlesFromDisplay =
66 new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
67 uint countFromDisplay;
68 if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle,
69 handlesFromDisplay, out countFromDisplay) == NvStatus.OK) {
70 for (int j = 0; j < countFromDisplay; j++) {
71 if (!displayHandles.ContainsKey(handlesFromDisplay[j]))
72 displayHandles.Add(handlesFromDisplay[j], displayHandle);
79 report.Append("Number of GPUs: ");
80 report.AppendLine(count.ToString(CultureInfo.InvariantCulture));
82 for (int i = 0; i < count; i++) {
83 NvDisplayHandle displayHandle;
84 displayHandles.TryGetValue(handles[i], out displayHandle);
85 hardware.Add(new NvidiaGPU(i, handles[i], displayHandle, settings));
91 public IHardware[] Hardware {
93 return hardware.ToArray();
97 public string GetReport() {
98 return report.ToString();
101 public void Close() {
102 foreach (Hardware gpu in hardware)