Пример #1
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count <= 0)
     {
         return;
     }
     for (int i = 0; i < listView1.SelectedItems.Count; i++)
     {
         ListViewItem item = listView1.SelectedItems[i];
         if (item.SubItems[1].Text.Equals("文件夹"))
         {
             bool s = checkpassword(item.Name);
             if (s)
             {
                 EnyHelper.DecryptFolder(item.Name);
                 listView1.Items.Remove(item);
             }
         }
         else
         {
             SaveFileDialog saveFile = new SaveFileDialog();
             saveFile.Filter       = "所有文件(*.*)|*.*";
             saveFile.DefaultExt   = Path.GetExtension(item.Name); //设置默认格式
             saveFile.AddExtension = true;                         //设置自动在文件名中添加扩展名
             if (saveFile.ShowDialog() == DialogResult.OK)
             {
                 EnyHelper.DecryptFile(item.Name, saveFile.FileName);
                 listView1.Items.Remove(item);
             }
         }
     }
     SerializeListViewItems(listView1);
 }
Пример #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBox1.Text))
     {
         MessageBox.Show("请选择文件或文件夹路径!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (radioButton1.Checked)//文件夹加密
     {
         string pwd = setpassword(textBox1.Text);
         if (string.IsNullOrEmpty(pwd))
         {
             MessageBox.Show("密码设置出错!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         else
         {
             string file = EnyHelper.EncryptFolder(textBox1.Text, pwd);
             listViewAdd(file, radioButton1.Checked);
         }
     }
     else //文件加密
     {
         string outPath = Application.StartupPath + "\\encryFile\\";
         if (!Directory.Exists(outPath))
         {
             Directory.CreateDirectory(outPath);
         }
         string outfile = outPath + Path.GetFileName(textBox1.Text);
         EnyHelper.EncryptFile(textBox1.Text, outfile);
         listViewAdd(outfile, radioButton1.Checked);
     }
     SerializeListViewItems(listView1);
 }