private void Decrypt() { Logging.Log("FAES_GUI(Decrypt): Started!'", Severity.DEBUG); string pathOverride = Path.Combine(Path.GetDirectoryName(_fileToPeek.GetPath()) ?? string.Empty, "faesPeekFilePath_" + new Random().Next(), "peekFile" + FileAES_Utilities.ExtentionUFAES); string dirName = Path.GetDirectoryName(pathOverride); string password = passTextbox.Text; string finalPath = Path.Combine(dirName ?? string.Empty, _fileToPeek.GetOriginalFileName()); DirectoryInfo di = Directory.CreateDirectory(dirName ?? string.Empty); di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; SetNote("Decrypting... Please wait.", 0); _inProgress = true; _decryptSuccessful = false; _mainDecryptThread = new Thread(() => { try { FileAES_Utilities.SetCryptoStreamBuffer(Program.programManager.GetCryptoStreamBufferSize()); FileAES_Decrypt decrypt = new FileAES_Decrypt(_fileToPeek, password, false); decrypt.DebugMode = FileAES_Utilities.GetVerboseLogging(); _faesThread = new Thread(() => { try { _decryptSuccessful = decrypt.DecryptFile(pathOverride); } catch (Exception e) { SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3); } }); _faesThread.Start(); while (_faesThread.ThreadState == ThreadState.Running) { _progress = decrypt.GetPercentComplete(); } { _inProgress = false; Invoke(new MethodInvoker(() => Locked(false))); if (_decryptSuccessful) { Logging.Log("FAES_GUI(Decrypt): Finished successfully!'", Severity.DEBUG); SetNote("Decryption Complete", 0); progressBar.CustomText = "Done"; progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage; Invoke(new MethodInvoker(() => { fileContentsTextbox.Text = File.ReadAllText(finalPath); })); Delete(pathOverride); } else { decryptionTimer.Stop(); progressBar.ProgressColor = Color.Red; progressBar.Value = progressBar.Maximum; Logging.Log("FAES_GUI(Decrypt): Finished unsuccessfully!'", Severity.DEBUG); if (!statusInformation.Text.ToLower().Contains("error")) { SetNote("Password Incorrect!", 3); progressBar.CustomText = "Password Incorrect!"; progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage; Invoke(new Action(() => passTextbox.Focus())); } } } } catch (Exception e) { SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3); } finally { Delete(pathOverride); } }); _mainDecryptThread.Start(); }
private void Encrypt() { string password = passTextbox.Text; string passHint = passHintTextbox.Text; int compressIndex = compressMode.SelectedIndex; bool delAfterEnc = deleteOriginal.Checked; bool ovDup = overwriteDuplicate.Checked; Logging.Log("FAES_GUI(Encrypt): Started!'", Severity.DEBUG); SetNote("Encrypting... Please wait.", 0); _inProgress = true; _encryptSuccessful = false; _mainEncryptThread = new Thread(() => { try { FileAES_Utilities.SetCryptoStreamBuffer(Program.programManager.GetCryptoStreamBufferSize()); FileAES_Utilities.TempEncrypt = Program.programManager.GetUseOSTemp(); FileAES_Encrypt encrypt = new FileAES_Encrypt(_fileToEncrypt, password, passHint, FAES.Packaging.CompressionUtils.GetAllOptimiseModes()[compressIndex]); encrypt.SetDeleteAfterEncrypt(delAfterEnc); encrypt.SetOverwriteDuplicate(ovDup); encrypt.DebugMode = FileAES_Utilities.GetVerboseLogging(); _faesThread = new Thread(() => { try { _encryptSuccessful = encrypt.EncryptFile(); } catch (Exception e) { SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3); } }); _faesThread.Start(); while (_faesThread.ThreadState == ThreadState.Running) { _progress = encrypt.GetPercentComplete(); } { _inProgress = false; Invoke(new MethodInvoker(() => Locked(false))); if (_encryptSuccessful) { Logging.Log("FAES_GUI(Encrypt): Finished successfully!'", Severity.DEBUG); SetNote("Encryption Complete", 0); progressBar.CustomText = "Done"; progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage; if (_closeAfterOp) { Application.Exit(); } else { ResetFile(); } } else { Logging.Log("FAES_GUI(Encrypt): Finished unsuccessfully!'", Severity.DEBUG); if (!statusInformation.Text.ToLower().Contains("error")) { SetNote("Encryption Failed. Try again later.", 1); } } } } catch (Exception e) { SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3); } }); _mainEncryptThread.Start(); }