6
6
from PyQt5 import QtGui
7
7
from PyQt5 .QtWidgets import QMainWindow , QApplication , QFileDialog , QMessageBox
8
8
from PyQt5 .uic import loadUi
9
+ from cryptography .fernet import InvalidToken
9
10
10
11
from secauax import Secauax
11
12
12
- log = []
13
-
14
13
15
14
def resource_path (relative_path : str ) -> str :
16
15
"""
@@ -27,6 +26,8 @@ class MainWindow(QMainWindow):
27
26
def __init__ (self ):
28
27
super (MainWindow , self ).__init__ ()
29
28
29
+ self .log_data = []
30
+
30
31
# Set Window settings
31
32
loadUi (resource_path ("resources/main.ui" ), self )
32
33
self .setWindowTitle ("Secauax by Auax" )
@@ -35,6 +36,7 @@ def __init__(self):
35
36
self .enable = False # Enable the encrypt and decrypt buttons
36
37
37
38
# Connect Menu
39
+ self .clear_log .triggered .connect (self .reset_logger )
38
40
self .open_github .triggered .connect (lambda : webbrowser .open ("https://github.com/auax" ))
39
41
self .report_issue .triggered .connect (lambda : webbrowser .open ("https://github.com/auax/secauax/issues/new" ))
40
42
self .donate .triggered .connect (lambda : webbrowser .open ("https://paypal.me/zellius" ))
@@ -160,16 +162,17 @@ def encrypt(self) -> None:
160
162
if self .save_key_path .text ():
161
163
# Save key to the desired path
162
164
secauax .save_key (self .save_key_path .text ())
163
- self .logger (f"Key loaded from { self .save_key_path .text ()} !" )
165
+ self .logger (f"Key saved in { self .save_key_path .text ()} !" )
164
166
165
167
if self .load_key_path .text ():
166
168
# Load key from the desired path
167
169
secauax .load_key_into_class (self .load_key_path .text ())
168
- self .logger (f"Key saved in { self .load_key_path .text ()} !" )
170
+ self .logger (f"Key loaded from { self .load_key_path .text ()} !" )
169
171
170
172
if self .mode_cb .isChecked ():
171
173
# Directory mode
172
- secauax .bulk_encrypt (self .input_path .text (), self .output_path .text ())
174
+ if not secauax .bulk_encrypt (self .input_path .text (), self .output_path .text ()):
175
+ raise InvalidToken
173
176
else :
174
177
# File mode
175
178
secauax .encrypt_file (self .input_path .text (), self .output_path .text ())
@@ -180,8 +183,11 @@ def encrypt(self) -> None:
180
183
# Show a message
181
184
MainWindow .create_dialog ("File(s) encrypted successfuly!" , "" , "Success!" , QMessageBox .Information )
182
185
186
+ except InvalidToken :
187
+ self .logger ("InvalidToken! Make sure to select the correct key." )
188
+
183
189
except Exception as E :
184
- self .logger ("Something went wrong! Please try again." ) # Log error
190
+ self .logger (f"Unhandled error: { type ( E ). __name__ } " )
185
191
186
192
def decrypt (self ) -> None :
187
193
"""
@@ -195,16 +201,17 @@ def decrypt(self) -> None:
195
201
if self .save_key_path .text ():
196
202
# Save key to the desired path
197
203
secauax .save_key (self .save_key_path .text ())
198
- self .logger (f"Key loaded from { self .save_key_path .text ()} !" )
204
+ self .logger (f"Key saved in { self .save_key_path .text ()} !" )
199
205
200
206
if self .load_key_path .text ():
201
207
# Load key from the desired path
202
208
secauax .load_key_into_class (self .load_key_path .text ())
203
- self .logger (f"Key saved in { self .load_key_path .text ()} !" )
209
+ self .logger (f"Key loaded from { self .load_key_path .text ()} !" )
204
210
205
211
if self .mode_cb .isChecked ():
206
212
# Directory mode
207
- secauax .bulk_decrypt (self .input_path .text (), self .output_path .text ())
213
+ if not secauax .bulk_decrypt (self .input_path .text (), self .output_path .text ()):
214
+ raise InvalidToken
208
215
else :
209
216
# File mode
210
217
secauax .decrypt_file (self .input_path .text (), self .output_path .text ())
@@ -215,8 +222,11 @@ def decrypt(self) -> None:
215
222
# Show message
216
223
MainWindow .create_dialog ("File(s) decrypted successfuly!" , "" , "Success!" , QMessageBox .Information )
217
224
218
- except :
219
- self .logger ("Something went wrong! Please try again." ) # Log error
225
+ except InvalidToken :
226
+ self .logger ("InvalidToken! Make sure to select the correct key." )
227
+
228
+ except Exception as E :
229
+ self .logger (f"Unhandled error: { type (E ).__name__ } " )
220
230
221
231
def logger (self , message : str , color : str = "red" ) -> None :
222
232
"""
@@ -225,13 +235,20 @@ def logger(self, message: str, color: str = "red") -> None:
225
235
:param color: the color of the message
226
236
:return: None
227
237
"""
228
- global log
229
- log .append (message )
238
+ self .log_data .append (message )
230
239
to_html = ""
231
- for i in log :
240
+ for i in self . log_data :
232
241
to_html += f"<p style='margin: 2px 4px 2px 4px !important;'><code style='color:red'>>></code> { i } </p>"
233
242
self .log .setHtml (to_html )
234
243
244
+ def reset_logger (self ) -> None :
245
+ """
246
+ Clear all log data
247
+ :return: None
248
+ """
249
+ self .log_data = []
250
+ self .log .setHtml ("" )
251
+
235
252
@staticmethod
236
253
def create_dialog (message : str , informative_text : str , title : str = "Info" , icon = QMessageBox .Critical ) -> None :
237
254
"""
0 commit comments