@@ -16,6 +16,7 @@ public partial class FileAES_Decrypt : Form
1616 private FAES_File _fileToDecrypt ;
1717 private string _autoPassword ;
1818 private decimal _progress = 0 ;
19+ private bool _deleteOriginal , _overwriteDuplicate ;
1920
2021 public FileAES_Decrypt ( string file , string password = null )
2122 {
@@ -55,6 +56,10 @@ private void decryptButton_Click(object sender, EventArgs e)
5556 if ( decryptButton . Enabled )
5657 {
5758 _progress = 0 ;
59+
60+ _deleteOriginal = deleteOriginal . Checked ;
61+ _overwriteDuplicate = forceOverwrite . Checked ;
62+
5863 if ( _fileToDecrypt . isFileDecryptable ( ) && ! _inProgress ) backgroundDecrypt . RunWorkerAsync ( ) ;
5964 else if ( _inProgress ) SetNote ( "Decryption already in progress." , 1 ) ;
6065 else SetNote ( "Decryption Failed. Try again later." , 1 ) ;
@@ -65,29 +70,38 @@ private void decryptButton_Click(object sender, EventArgs e)
6570
6671 private void SetNote ( string note , int severity )
6772 {
68- if ( note . Contains ( "ERROR:" ) )
69- {
70- note = note . Replace ( "ERROR:" , "Error:" ) ;
71- noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = note ; } ) ) ;
72- }
73- else
73+ try
7474 {
75- switch ( severity )
75+ if ( ! noteLabel . IsDisposed )
7676 {
77- case 1 :
78- noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Warning: " + note ; } ) ) ;
79- break ;
80- case 2 :
81- noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Important: " + note ; } ) ) ;
82- break ;
83- case 3 :
84- noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Error: " + note ; } ) ) ;
85- break ;
86- default :
87- noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Note: " + note ; } ) ) ;
88- break ;
77+ if ( note . Contains ( "ERROR:" ) )
78+ {
79+ note = note . Replace ( "ERROR:" , "Error:" ) ;
80+ noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = note ; } ) ) ;
81+ }
82+ else
83+ {
84+ switch ( severity )
85+ {
86+ case 1 :
87+ noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Warning: " + note ; } ) ) ;
88+ break ;
89+ case 2 :
90+ noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Important: " + note ; } ) ) ;
91+ break ;
92+ case 3 :
93+ noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Error: " + note ; } ) ) ;
94+ break ;
95+ default :
96+ noteLabel . Invoke ( new MethodInvoker ( delegate { this . noteLabel . Text = "Note: " + note ; } ) ) ;
97+ break ;
98+ }
99+ }
89100 }
90101 }
102+ catch
103+ { }
104+
91105 }
92106
93107 private void Decrypt ( )
@@ -103,9 +117,19 @@ private void Decrypt()
103117 {
104118 FAES . FileAES_Decrypt decrypt = new FAES . FileAES_Decrypt ( _fileToDecrypt , passwordInput . Text ) ;
105119
120+ decrypt . SetDeleteAfterDecrypt ( _deleteOriginal ) ;
121+ decrypt . SetOverwriteDuplicate ( _overwriteDuplicate ) ;
122+
106123 Thread dThread = new Thread ( ( ) =>
107124 {
108- _decryptSuccessful = decrypt . decryptFile ( ) ;
125+ try
126+ {
127+ _decryptSuccessful = decrypt . decryptFile ( ) ;
128+ }
129+ catch ( Exception e )
130+ {
131+ SetNote ( FileAES_Utilities . FAES_ExceptionHandling ( e ) , 3 ) ;
132+ }
109133 } ) ;
110134 dThread . Start ( ) ;
111135
@@ -132,7 +156,7 @@ private void backgroundDecrypt_Complete(object sender, RunWorkerCompletedEventAr
132156 {
133157 _inProgress = false ;
134158 if ( _decryptSuccessful ) Application . Exit ( ) ;
135- else
159+ else if ( ! noteLabel . Text . ToLower ( ) . Contains ( "error" ) )
136160 {
137161 SetNote ( "Password Incorrect!" , 3 ) ;
138162 progressBar . CustomText = "Password Incorrect!" ;
@@ -146,6 +170,8 @@ private void runtime_Tick(object sender, EventArgs e)
146170 {
147171 decryptButton . Enabled = false ;
148172 passwordInput . Enabled = false ;
173+ deleteOriginal . Enabled = false ;
174+ forceOverwrite . Enabled = false ;
149175
150176 if ( _progress < 100 )
151177 {
@@ -165,12 +191,16 @@ private void runtime_Tick(object sender, EventArgs e)
165191 {
166192 decryptButton . Enabled = true ;
167193 passwordInput . Enabled = true ;
194+ deleteOriginal . Enabled = true ;
195+ forceOverwrite . Enabled = true ;
168196
169197 }
170198 else
171199 {
172200 decryptButton . Enabled = false ;
173201 passwordInput . Enabled = true ;
202+ deleteOriginal . Enabled = true ;
203+ forceOverwrite . Enabled = true ;
174204 }
175205 }
176206
0 commit comments