Ejemplo n.º 1
0
        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();
        }