From e3c6590e0a91c33fba0b290380966691e2ef05c8 Mon Sep 17 00:00:00 2001 From: Tongg Date: Fri, 28 Feb 2025 09:18:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9D=9ENvidia?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E6=97=A0=E6=B3=95=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LoginWindow.xaml.cs | 86 +++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/LoginWindow.xaml.cs b/LoginWindow.xaml.cs index 67139a9..aaa95c0 100644 --- a/LoginWindow.xaml.cs +++ b/LoginWindow.xaml.cs @@ -28,55 +28,65 @@ public partial class LoginWindow : Window private void checkNvidia() { string nvidiaVersion = ""; - using (Process process = new Process()) + try { - 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; + using (Process process = new Process()) + { + 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(); + // 使用StringBuilder来捕获输出和错误信息 + StringBuilder outputBuilder = new StringBuilder(); + StringBuilder errorBuilder = new StringBuilder(); - process.OutputDataReceived += (sender, e) => - { - if (e.Data != null) - outputBuilder.AppendLine(e.Data); - }; - process.ErrorDataReceived += (sender, e) => - { - if (e.Data != null) - errorBuilder.AppendLine(e.Data); - }; + process.OutputDataReceived += (sender, e) => + { + if (e.Data != null) + outputBuilder.AppendLine(e.Data); + }; + process.ErrorDataReceived += (sender, e) => + { + if (e.Data != null) + errorBuilder.AppendLine(e.Data); + }; - process.Start(); + process.Start(); - // 开始异步读取输出和错误流 - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); + // 开始异步读取输出和错误流 + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); - process.WaitForExit(); + 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) + // 获取完整的输出和错误信息 + 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) + { + MessageBox messageBox = new MessageBox(); + messageBox.Show(MultilingualHelper.getString("NotNvidiaVersionLow") + .Replace("%version", nvidiaVersion)); + } + } + else { MessageBox messageBox = new MessageBox(); - messageBox.Show(MultilingualHelper.getString("NotNvidiaVersionLow").Replace("%version", nvidiaVersion)); + messageBox.Show(MultilingualHelper.getString("NotNvidia")); } } - else - { - MessageBox messageBox = new MessageBox(); - messageBox.Show(MultilingualHelper.getString("NotNvidia")); - } + } + catch (Exception ex) + { + Logger.Error(ex.Message); + MessageBox messageBox = new MessageBox(); + messageBox.Show(MultilingualHelper.getString("NotNvidia")); } }