You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
6.4 KiB
204 lines
6.4 KiB
using log4net; |
|
using SparkClient.Model.Helper; |
|
using SparkClient.ViewModel.Configuration.SettingsPages; |
|
using System.Data; |
|
using System.Diagnostics; |
|
using System.Windows; |
|
using System.Windows.Input; |
|
using MessageBox = SparkClient.Views.Dialog.MessageBox; |
|
namespace SparkClient; |
|
|
|
public partial class LoginWindow : Window |
|
{ |
|
private static readonly ILog Logger = LogManager.GetLogger(typeof(LoginWindow)); |
|
public LoginWindow() |
|
{ |
|
InitializeComponent(); |
|
WindowStartupLocation = WindowStartupLocation.CenterScreen; |
|
AccountTextBox.Text = Settings.SelectValueById("SAVE_ACCOUNT"); |
|
PasswordBox.Password = Settings.SelectValueById("SAVE_PASSWORD"); |
|
checkCUDA(); |
|
// 检测MSVCRuntime是否安装 |
|
checkMSVCRuntime(); |
|
} |
|
|
|
private void checkCUDA() |
|
{ |
|
try |
|
{ |
|
ProcessStartInfo startInfo = new ProcessStartInfo |
|
{ |
|
FileName = "nvcc", |
|
Arguments = "--version", |
|
RedirectStandardOutput = true, |
|
UseShellExecute = false, |
|
CreateNoWindow = true |
|
}; |
|
|
|
using (Process process = new Process { StartInfo = startInfo }) |
|
{ |
|
process.Start(); |
|
string output = process.StandardOutput.ReadToEnd(); |
|
process.WaitForExit(); |
|
|
|
if (process.ExitCode == 0) |
|
{ |
|
Logger.Error("CUDA 已安装\n" + output); |
|
} |
|
else |
|
{ |
|
MessageBox messageBox = new MessageBox(); |
|
messageBox.Show(MultilingualHelper.getString("CUDANoInstall")); |
|
Logger.Error("CUDA 未安装"); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageBox messageBox = new MessageBox(); |
|
messageBox.Show(MultilingualHelper.getString("CUDANoInstall")); |
|
Logger.Error("CUDA 安装检测错误:"+ ex); |
|
} |
|
} |
|
private void checkMSVCRuntime() |
|
{ |
|
try |
|
{ |
|
ProcessStartInfo startInfo = new ProcessStartInfo |
|
{ |
|
FileName = "where", |
|
Arguments = "msvcp140.dll", |
|
RedirectStandardOutput = true, |
|
UseShellExecute = false, |
|
CreateNoWindow = true |
|
}; |
|
|
|
using (Process process = new Process { StartInfo = startInfo }) |
|
{ |
|
process.Start(); |
|
string output = process.StandardOutput.ReadToEnd(); |
|
process.WaitForExit(); |
|
|
|
if (string.IsNullOrEmpty(output)) |
|
{ |
|
MessageBox messageBox = new MessageBox(); |
|
messageBox.Show(MultilingualHelper.getString("MSVCRuntimeNoInstall")); |
|
Logger.Error("MSVC Runtime 未安装"); |
|
Environment.Exit(0); // 退出程序 |
|
} |
|
else |
|
{ |
|
Logger.Info("MSVC Runtime 已安装"); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageBox messageBox = new MessageBox(); |
|
messageBox.Show(MultilingualHelper.getString("MSVCRuntimeNoInstall")); |
|
Logger.Error("MSVC Runtime 安装检测错误:" + ex); |
|
Environment.Exit(0); // 退出程序 |
|
} |
|
} |
|
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
|
{ |
|
if (e.ButtonState == MouseButtonState.Pressed) |
|
{ |
|
this.DragMove(); |
|
} |
|
} |
|
|
|
private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
|
{ |
|
AccountTextBox.Text = string.Empty; |
|
} |
|
|
|
private void CloseButton_OnClick(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
Environment.Exit(0); |
|
} |
|
|
|
private void ConfirmButton_Click(object sender, RoutedEventArgs e) |
|
{ |
|
#if DEBUG |
|
|
|
new MainWindow().Show(); |
|
this.Close(); |
|
|
|
#else |
|
string account = AccountTextBox.Text; |
|
string password = PasswordBox.Password; |
|
string passwordEnc = Common.GenerateMd5Hash(password); |
|
string passworddb = getPassword(account); |
|
if (string.IsNullOrEmpty(password) || !passworddb.Equals(passwordEnc)) |
|
{ |
|
MessageBox messageBox = new MessageBox(); |
|
messageBox.Show(MultilingualHelper.getString("NoPassword")); |
|
return; |
|
} |
|
savePassword(); |
|
new MainWindow().Show(); |
|
this.Close(); |
|
#endif |
|
} |
|
|
|
private void savePassword() |
|
{ |
|
if (IsRemberPassword.IsChecked ?? false) |
|
{ |
|
if (!"admin".Equals(AccountTextBox.Text)){ |
|
Settings saveAccount = new Settings() |
|
{ |
|
Key = "SAVE_ACCOUNT", |
|
ItemName = "保存用户名", |
|
Value = AccountTextBox.Text, |
|
}; |
|
saveAccount.insert(); |
|
Settings savePassword = new Settings() |
|
{ |
|
Key = "SAVE_PASSWORD", |
|
ItemName = "保存密码", |
|
Value = PasswordBox.Password, |
|
}; |
|
savePassword.insert(); |
|
} |
|
} |
|
else |
|
{ |
|
Settings saveAccount = new Settings() |
|
{ |
|
Key = "SAVE_ACCOUNT", |
|
ItemName = "保存用户名", |
|
Value = "", |
|
}; |
|
saveAccount.insert(); |
|
Settings savePassword = new Settings() |
|
{ |
|
Key = "SAVE_PASSWORD", |
|
ItemName = "保存密码", |
|
Value = "", |
|
}; |
|
savePassword.insert(); |
|
} |
|
Settings PERMISSIONS = new Settings() |
|
{ |
|
Key = "PERMISSIONS", |
|
ItemName = "权限", |
|
Value = AccountTextBox.Text, |
|
}; |
|
PERMISSIONS.insert(); |
|
} |
|
|
|
private string getPassword(string userName) |
|
{ |
|
string password = string.Empty; |
|
string sql = $"SELECT USER_PASSWORD FROM USER WHERE USER_NAME='{userName}';"; |
|
DataTable dt = DataBaseHelper.ExecuteQuery(sql); |
|
if (dt != null && dt.Rows.Count > 0) |
|
{ |
|
password = dt.Rows[0]["USER_PASSWORD"].ToString(); |
|
} |
|
return password; |
|
} |
|
} |