123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- namespace Archives_Center
- {
- public partial class register : Form
- {
- public register()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox2.Text != "")
- {
- if (textBox1.Text != "")
- {
- if (textBox1.Text == textBox3.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 (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter"))
- Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter");
- if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Backups"))
- Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Backups");
- if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Users.encrypted"))
- {
- Directory.CreateDirectory(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textBox2.Text);
- using (StreamWriter writer = new StreamWriter(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textBox2.Text + @"\password.txt"))
- {
- writer.WriteLine(textBox3.Text);
- }
- SevenZipHelper.CreateEncryptedZip(UserDataCachePath, UserDataPath, Password);
- this.Close();
- }
- else
- {
- SevenZipHelper.ExtractEncryptedArchive(UserDataPath, UserDataCachePath, Password);
- Thread.Sleep(1000);
- File.Delete(UserDataPath);
- Directory.CreateDirectory(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textBox2.Text);
- using (StreamWriter writer = new StreamWriter(Path.GetTempPath() + @"ArchivesCenter\UsersData\" + textBox2.Text + @"\password.txt"))
- {
- writer.WriteLine(textBox3.Text);
- }
- SevenZipHelper.CreateEncryptedZip(UserDataCachePath, UserDataPath, Password);
- this.Close();
- }
- Directory.Delete(Path.GetTempPath() + @"ArchivesCenter", true);
- }
- }
- else
- {
- MessageBox.Show("请检查您两次填入的字段是否一致", "新建用户 错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("请检查您填入的字段是否完整", "新建用户 错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("请填入用户名", "新建用户 错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void toolStripButton3_CheckedChanged(object sender, EventArgs e)
- {
- if (toolStripButton3.Checked == true)
- {
- textBox2.Text = null;
- textBox1.Text = null;
- textBox3.Text = null;
- textBox2.Text = Environment.UserDomainName + @"\" + Environment.UserName;
- textBox2.ReadOnly = true;
- textBox3.Focus();
- }
- else
- {
- textBox2.Text = null;
- textBox1.Text = null;
- textBox3.Text = null;
- textBox2.ReadOnly = false;
- textBox2.Focus();
- }
- }
- private void toolStripButton1_Click(object sender, EventArgs e)
- {
- string UserDataCachePath = Path.GetTempPath() + @"ArchivesCenter\UsersData\";
- string Password = "fbHQb7L9ODdO9pyPB4cDaMtiW7AgYKJLmQb7FewTiJZhyQwzCJucVf4scvQt7R6b";
- string UserDataPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Users.encrypted";
- Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\");
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Title = "选择导入的用户数据文件";
- openFileDialog.Filter = "Archives Center 用户数据文件 (*.encrypted)|*.encrypted|所有文件 (*.*)|*.*";
- openFileDialog.Multiselect = false;
- if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ArchivesCenter\Users.encrypted"))
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- SevenZipHelper.ExtractEncryptedArchive(openFileDialog.FileName, UserDataCachePath, Password);
- }
- this.Close();
- }
- else
- {
- SevenZipHelper.ExtractEncryptedArchive(UserDataPath, UserDataCachePath, Password);
- Thread.Sleep(1000);
- File.Delete(UserDataPath);
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- SevenZipHelper.ExtractEncryptedArchive(openFileDialog.FileName, UserDataCachePath, Password);
- }
- SevenZipHelper.CreateEncryptedZip(UserDataCachePath, UserDataPath, Password);
- this.Close();
- }
- Directory.Delete(Path.GetTempPath() + @"ArchivesCenter", true);
- }
- }
- }
|