using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraSplashScreen; namespace NewArchivesCenter { public partial class register : DevExpress.XtraEditors.XtraForm { public register() { InitializeComponent(); Properties.Settings.Default.Islogin = false; Properties.Settings.Default.Save(); textEdit1.ImeMode = ImeMode.Disable; textEdit2.ImeMode = ImeMode.Disable; textEdit3.ImeMode = ImeMode.Disable; } private void simpleButton1_Click(object sender, EventArgs e) { splashScreenManager1.ShowWaitForm(); if (textEdit1.Text != "") { if (textEdit3.Text != "") { if (textEdit3.Text == textEdit2.Text) { if (MessageBox.Show("用户名和密码设定后无法修改,请谨慎操作。\n继续操作?", "Archives Center 提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { string UserDataCachePath = Path.GetTempPath() + @"ArchivesCenter\UsersData\"; string Password = "fbHQb7L9ODdO9pyPB4cDaMtiW7AgYKJLmQb7FewTiJZhyQwzCJucVf4scvQt7R6b"; string UserDataPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Users.encrypted"; if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Users.encrypted")) { Properties.Settings.Default.Islogin = true; Properties.Settings.Default.Save(); Directory.CreateDirectory(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textEdit1.Text); using (StreamWriter writer = new StreamWriter(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textEdit1.Text + @"\password.txt")) { writer.WriteLine(textEdit2.Text); } SevenZipHelper.CreateEncryptedZip(UserDataCachePath, UserDataPath, Password); this.Close(); Properties.Settings.Default.current_user = textEdit1.Text; Directory.CreateDirectory(Path.GetTempPath() + @"ArchivesCenter\Data\" + Properties.Settings.Default.current_user + @"\"); if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Backups\" + Properties.Settings.Default.current_user + @"\")) Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Backups\" + Properties.Settings.Default.current_user + @"\"); MainWindow MainWindow = new MainWindow(); MainWindow.Show(); this.Close(); } else { Properties.Settings.Default.Islogin = true; Properties.Settings.Default.Save(); SevenZipHelper.ExtractEncryptedArchive(UserDataPath, UserDataCachePath, Password); Thread.Sleep(1000); File.Delete(UserDataPath); Directory.CreateDirectory(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textEdit1.Text); using (StreamWriter writer = new StreamWriter(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textEdit1.Text + @"\password.txt")) { writer.WriteLine(textEdit2.Text); } SevenZipHelper.CreateEncryptedZip(UserDataCachePath, UserDataPath, Password); this.Close(); Properties.Settings.Default.current_user = textEdit1.Text; Directory.CreateDirectory(Path.GetTempPath() + @"ArchivesCenter\Data\" + Properties.Settings.Default.current_user + @"\"); if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Backups\" + Properties.Settings.Default.current_user + @"\")) Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Backups\" + Properties.Settings.Default.current_user + @"\"); MainWindow MainWindow = new MainWindow(); MainWindow.Show(); this.Close(); } } } else { MessageBox.Show("请检查您两次填入的字段是否一致", "新建用户 错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("请检查您填入的字段是否完整", "新建用户 错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("请填入用户名", "新建用户 错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } splashScreenManager1.CloseWaitForm(); } private void register_FormClosing(object sender, FormClosingEventArgs e) { if (Properties.Settings.Default.Islogin == false) { login login = new login(); login.Show(); } } private void simpleButton2_Click(object sender, EventArgs e) { textEdit1.Text = Environment.UserDomainName + @"\" + Environment.UserName; textEdit2.Text = null; textEdit3.Text = null; textEdit2.Focus(); } } }