|
|
|
@ -3,6 +3,7 @@ using SparkClient.Model.Helper; |
|
|
|
|
using SparkClient.ViewModel.Configuration.SettingsPages; |
|
|
|
|
using System.Data; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Windows; |
|
|
|
|
using System.Windows.Input; |
|
|
|
|
using Microsoft.Win32; |
|
|
|
@ -27,33 +28,93 @@ public partial class LoginWindow : Window |
|
|
|
|
private void checkNvidia() |
|
|
|
|
{ |
|
|
|
|
string nvidiaVersion = ""; |
|
|
|
|
const string regPath = @"SOFTWARE\NVIDIA Corporation\Global\NVSMI"; |
|
|
|
|
const string keyName = "DisplayDriverVersion"; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
using (Process process = new Process()) |
|
|
|
|
{ |
|
|
|
|
// 针对 64 位系统访问注册表 |
|
|
|
|
using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) |
|
|
|
|
using (var key = baseKey.OpenSubKey(regPath)) |
|
|
|
|
process.StartInfo.FileName = "nvidia-smi"; |
|
|
|
|
process.StartInfo.Arguments = "--query-gpu=driver_version --format=csv,noheader,nounits"; |
|
|
|
|
process.StartInfo.UseShellExecute = false; |
|
|
|
|
process.StartInfo.CreateNoWindow = true; |
|
|
|
|
process.StartInfo.RedirectStandardOutput = true; |
|
|
|
|
process.StartInfo.RedirectStandardError = true; |
|
|
|
|
|
|
|
|
|
// 使用StringBuilder来捕获输出和错误信息 |
|
|
|
|
StringBuilder outputBuilder = new StringBuilder(); |
|
|
|
|
StringBuilder errorBuilder = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
process.OutputDataReceived += (sender, e) => |
|
|
|
|
{ |
|
|
|
|
if (key != null) |
|
|
|
|
if (e.Data != null) |
|
|
|
|
outputBuilder.AppendLine(e.Data); |
|
|
|
|
}; |
|
|
|
|
process.ErrorDataReceived += (sender, e) => |
|
|
|
|
{ |
|
|
|
|
if (e.Data != null) |
|
|
|
|
errorBuilder.AppendLine(e.Data); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
process.Start(); |
|
|
|
|
|
|
|
|
|
// 开始异步读取输出和错误流 |
|
|
|
|
process.BeginOutputReadLine(); |
|
|
|
|
process.BeginErrorReadLine(); |
|
|
|
|
|
|
|
|
|
process.WaitForExit(); |
|
|
|
|
|
|
|
|
|
// 获取完整的输出和错误信息 |
|
|
|
|
string outputMsg = outputBuilder.ToString(); |
|
|
|
|
string errorMsg = errorBuilder.ToString(); |
|
|
|
|
nvidiaVersion = (string.IsNullOrWhiteSpace(errorMsg)?outputMsg:errorMsg).Trim(); |
|
|
|
|
if (process.ExitCode == 0 || !string.IsNullOrWhiteSpace(nvidiaVersion)) |
|
|
|
|
{ |
|
|
|
|
if (CompareVersions(nvidiaVersion, "528.33") <= 0) |
|
|
|
|
{ |
|
|
|
|
var value = key.GetValue(keyName)?.ToString(); |
|
|
|
|
nvidiaVersion = !string.IsNullOrEmpty(value) ? value : "未找到驱动版本"; |
|
|
|
|
MessageBox messageBox = new MessageBox(); |
|
|
|
|
messageBox.Show(MultilingualHelper.getString("NotNvidiaVersionLow").Replace("%version", nvidiaVersion)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
MessageBox messageBox = new MessageBox(); |
|
|
|
|
messageBox.Show(MultilingualHelper.getString("NotNvidia")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static int CompareVersions(string versionA, string versionB) |
|
|
|
|
{ |
|
|
|
|
int[] partsA = ParseVersion(versionA); |
|
|
|
|
int[] partsB = ParseVersion(versionB); |
|
|
|
|
|
|
|
|
|
int maxLength = Math.Max(partsA.Length, partsB.Length); |
|
|
|
|
for (int i = 0; i < maxLength; i++) |
|
|
|
|
{ |
|
|
|
|
nvidiaVersion = ex.Message; |
|
|
|
|
Logger.Error("Nvidia检测错误:"+ ex); |
|
|
|
|
int a = (i < partsA.Length) ? partsA[i] : 0; |
|
|
|
|
int b = (i < partsB.Length) ? partsB[i] : 0; |
|
|
|
|
|
|
|
|
|
if (a != b) |
|
|
|
|
{ |
|
|
|
|
return a.CompareTo(b); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MessageBox messageBox = new MessageBox(); |
|
|
|
|
messageBox.Show(nvidiaVersion); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; // 版本相同 |
|
|
|
|
} |
|
|
|
|
private static int[] ParseVersion(string version) |
|
|
|
|
{ |
|
|
|
|
string[] stringParts = version.Split('.'); |
|
|
|
|
int[] intParts = new int[stringParts.Length]; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < stringParts.Length; i++) |
|
|
|
|
{ |
|
|
|
|
if (!int.TryParse(stringParts[i], out int part)) |
|
|
|
|
{ |
|
|
|
|
return [0, 0, 0]; |
|
|
|
|
} |
|
|
|
|
intParts[i] = part; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return intParts; |
|
|
|
|
} |
|
|
|
|
private void checkCUDA() |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|