private void StartEncrypting() { a.FileEncrypt(paths.PrevFile, password, paths.NewFile); File.Delete(paths.PrevFile); }
private void bwEncrypt_DoWork(object sender, DoWorkEventArgs e) { if (!stop) { int x = 0; bwEncrypt.ReportProgress(0); try { if (Password != Confirmed) { stop = true; MessageBox.Show("Passwords doesnt match!!!"); return; } if (rbFile.Checked || rbFolder.Checked) { FileAttributes attr = File.GetAttributes(FilePath); if (attr.HasFlag(FileAttributes.Directory)) { string zipfile = aes.Ziping(FilePath); aes.FileEncrypt(zipfile, Password, null); File.Delete(zipfile); } else { aes.FileEncrypt(FilePath, Password, null); } //delete paretnt files if (rbDelete.Checked && !attr.HasFlag(FileAttributes.Directory)) { File.Delete(FilePath); } else if (rbDelete.Checked && attr.HasFlag(FileAttributes.Directory)) { Directory.Delete(FilePath, true); } bwEncrypt.ReportProgress(1); stop = true; } else if (rbDisc.Checked) { foreach (var item in files) { if (this.bwEncrypt.CancellationPending) { e.Cancel = true; return; } FileAttributes attr = File.GetAttributes(item); if (attr.HasFlag(FileAttributes.Directory)) { string zipfile = aes.Ziping(item); aes.FileEncrypt(zipfile, Password, null); File.Delete(zipfile); } else { aes.FileEncrypt(item, Password, null); } if (rbDelete.Checked && !attr.HasFlag(FileAttributes.Directory)) { File.Delete(item); } else if (rbDelete.Checked && attr.HasFlag(FileAttributes.Directory)) { Directory.Delete(item, true); } x++; bwEncrypt.ReportProgress(x); } stop = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { e.Cancel = true; bwEncrypt.CancelAsync(); } }