private void FolderDecryptionbgWorker_DoWork(object sender, DoWorkEventArgs e) { MessageBox.Show("Decrypting in background...\n Please wait", "Processing"); List <string> agms = e.Argument as List <string>; foreach (string i in Directory.GetFiles(agms[0], ".", SearchOption.AllDirectories)) { if (i.Contains(".Crypt")) { FileEncryption.DecryptFile(i, i.Replace(".Crypt", ""), agms[1]); if (App.FileEncryptPassErr) { break; } else { File.Delete(i); } } } if (!App.FileEncryptPassErr) { MainWindow.SuccessBox("Folder Decryption completed"); Application.Current.Shutdown(); } else { App.FileEncryptPassErr = false; } }
private void DecryptionDriveThread() { string[] Files = { }; this.Dispatcher.Invoke(() => { Files = Directory.GetFiles(DriveDecryptionListBox.SelectedItem.ToString(), "*", SearchOption.AllDirectories); }); foreach (string i in Files) { this.Dispatcher.Invoke(() => { if (i.Contains("Crypt")) { try { FileEncryption.DecryptFile(i, i.Replace("Crypt", ""), FolderDecryptionPassword.Password); CryptStatus.Document.Blocks.Add(new Paragraph(new Run("File Decrypted :" + i))); File.Delete(i); } catch (Exception Ex) { ErrorBox(Ex.Message); } } }); } this.Dispatcher.Invoke(() => { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("\n"))); }); }
void DriveDecryptionbgWorker_DoWork(object sender, DoWorkEventArgs e) { List <string> agms = e.Argument as List <string>;; string[] Files = { }; try { Files = Directory.GetFiles(agms[0], "*", SearchOption.AllDirectories); } catch { ErrorBox("No Drive selected"); this.Dispatcher.Invoke(() => { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("Decryption Terminated\n"))); }); return; } foreach (string i in Files) { if (i.Contains(".Crypt")) { try { FileEncryption.DecryptFile(i, i.Replace(".Crypt", ""), agms[1]); if (App.FileEncryptPassErr) { this.Dispatcher.Invoke(() => { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("Wrong Password... Decryption Terminated\n"))); }); break; } this.Dispatcher.Invoke(() => { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("File Decrypted :" + i))); }); File.Delete(i); } catch (Exception Ex) { ErrorBox(Ex.Message); } } } if (!App.FileEncryptPassErr) { this.Dispatcher.Invoke(() => { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("Folder Decryption completed\n"))); SuccessBox("Folder Decryption completed"); }); } else { App.FileEncryptPassErr = false; } }
private void DecryptFolder_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Decrypting Folder... The screen may freeze.", "Running", MessageBoxButton.OK, MessageBoxImage.Information); CryptStatus.Document.Blocks.Add(new Paragraph(new Run("Decrypting folder... This screen might freeze as the process is running in background"))); foreach (string i in Directory.GetFiles(FolderDecNameDisplay.Text, "*", SearchOption.AllDirectories)) { try { FileEncryption.DecryptFile(i, i.Replace("Crypt", ""), FolderDecryptionPassword.Password); CryptStatus.Document.Blocks.Add(new Paragraph(new Run("File Decrypted :" + i))); File.Delete(i); } catch (Exception Ex) { ErrorBox(Ex.Message); } } CryptStatus.Document.Blocks.Add(new Paragraph(new Run("\n"))); }
private void DecryptFile_Click(object sender, RoutedEventArgs e) { if (FileDecNameDisplay.Text.Equals("Not selected")) { ErrorBox("No File Selected"); } else { try { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("Decrypting... Please wait"))); FileEncryption.DecryptFile(FileDecNameDisplay.Text, FileDecNameDisplay.Text.Replace("Crypt", ""), FileDecryptionPassword.Password); if (!(bool)CheckFileDec.IsChecked && !FileEncryptPassErr) { File.Delete(FileDecNameDisplay.Text); } if (!FileEncryptPassErr) { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("File Decrypted :" + FileDecNameDisplay.Text + "\n"))); } FileEncryptPassErr = false; } catch (Exception ex) { if (ex.Message.Contains("The file") && ex.Message.Contains("already exists")) { ErrorBox("A file of the same name exists in that folder!"); } else if (ex.Message.Contains("Padding is invalid")) { ErrorBox("Wrong password"); } else { ErrorBox(ex.Message); } } } }
private void Decrypt_Click(object sender, RoutedEventArgs e) { if ((bool)FileDec.IsChecked) { FileEncryption.DecryptFile(FilePath, FilePath.Replace(".Crypt", ""), DecryptionPassword.Password); if (!App.FileEncryptPassErr) { MainWindow.SuccessBox("File Decrypted Successfully"); File.Delete(FilePath); Application.Current.Shutdown(); } } if ((bool)FolderDec.IsChecked) { List <string> Agms = new List <string>(); Agms.Add(FilePath.Replace(FilePath.Split('\\')[FilePath.Split('\\').Length - 1], "").Replace(FilePath.Split('\\')[FilePath.Split('\\').Length - 1], "")); Agms.Add(DecryptionPassword.Password); BackgroundWorker BW = new BackgroundWorker(); BW.DoWork += FolderDecryptionbgWorker_DoWork; BW.RunWorkerAsync(Agms); } }
void NewLocFileDecryptionbgWorker_DoWork(object sender, DoWorkEventArgs e) { List <string> agms = e.Argument as List <string>; FileEncryption.DecryptFile(agms[0], agms[4] + "." + agms[0].Split('.')[agms[0].Split('.').Length - 2], agms[1]); if (agms[2].Equals("Delete No Err") && !App.FileEncryptPassErr) { File.Delete(agms[0]); } else { File.Delete(agms[0].Replace(".Crypt", "")); } if (!App.FileEncryptPassErr) { this.Dispatcher.Invoke(() => { CryptStatus.Document.Blocks.Add(new Paragraph(new Run("File Decrypted :" + FileDecNameDisplay.Text + "\n"))); SuccessBox("File Decrypted :" + FileDecNameDisplay.Text); }); } }