/// <summary> /// Constructs an object with decryptor options</br> /// If specified this constructor inits the database /// </summary> /// <param name="options"></param> public Decryptor(DecryptorOptions options, IProgress <int> pp, CancellationToken token) : this() { Options = options; if (options.UseDatabase) { Options.UseDatabase = InitDB(options.DatabasePath); } ProgressPercent = pp; ct = token; }
private async void CmdStartDecryption_Click(object sender, EventArgs e) { if (CheckInput() == false) { return; } var ProgressPercent = new Progress <int>(Percent => { ProgressBar1.Value = Percent; lblPercent.Text = Percent + "%"; }); var ProgressConsole = new Progress <Msg>(msg => { TxtOutput.SelectionStart = TxtOutput.TextLength; TxtOutput.SelectionLength = 0; TxtOutput.SelectionColor = msg.TextColor; TxtOutput.AppendText(msg.Text + "\n"); TxtOutput.SelectionColor = TxtOutput.ForeColor; TxtOutput.ScrollToCaret(); }); Utils.ProgressConsole = ProgressConsole; Decryptor decryptor; var decryptorOptions = new DecryptorOptions() { UsageMode = RadioFolder.Checked ? Mode.Folder : Mode.File, UseOutputFolder = ComboOutputPath.Text == "" ? false : true, UseDatabase = ComboDbFile.Text == "" ? false : true, RemoveFilesAfterDecryption = false, InputPath = ComboInputPath.Text, OutputPath = ComboOutputPath.Text == "" ? Path.ChangeExtension(ComboInputPath.Text, ".mp4") : ComboOutputPath.Text, OutputFolder = ComboOutputPath.Text == "" ? Path.GetDirectoryName(ComboInputPath.Text) : ComboOutputPath.Text, DatabasePath = ComboDbFile.Text, SubTitle = ChkSubtitle.Checked ? true : false }; CmdStartDecryption.Text = "Decrypting...."; CmdStartDecryption.Enabled = false; CmdExit.Text = "Cancel"; running = true; cts = new CancellationTokenSource(); ct = cts.Token; try { decryptor = new Decryptor(decryptorOptions, ProgressPercent, ct); decryptor.InitDecryptor(ENCRYPTION_KEY); if (decryptorOptions.UsageMode == Mode.Folder) { await decryptor.DecryptAll(decryptorOptions.InputPath, decryptorOptions.OutputFolder); } else if (decryptorOptions.UsageMode == Mode.File) { decryptor.Decrypt(decryptorOptions.InputPath, decryptorOptions.OutputPath); } } catch (OperationCanceledException Ex) { MessageBox.Show("[CANCEL] Operation Cancelled: " + Ex.Message); WriteToConsole("[CANCEL] Operation Cancelled: " + Ex.Message + Environment.NewLine, Color.Yellow); } catch (Exception Ex) { MessageBox.Show("[START] Error occured: " + Ex.Message); WriteToConsole("[START] Error occured: " + Ex.Message + Environment.NewLine, Color.Red); } finally { CmdStartDecryption.Text = "Start Decryption"; CmdStartDecryption.Enabled = true; CmdExit.Text = "Exit"; running = false; cts.Dispose(); } }