-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·388 lines (337 loc) · 14.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/usr/bin/python3
import os
import sys
import time
import platform
import resources
import pyperclip
from functools import partial
import tmpdir
import filesMD5
import versionInfo
from threadClass import Hashing
from HashChecker import checkHash
from about import AboutWindow
# PyQt5 Imports
import sip
import PyQt5
from PyQt5 import uic
from PyQt5 import QtGui
from PyQt5.QtGui import QIcon, QPixmap, QMovie
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QLabel, QPushButton
from PyQt5.QtWidgets import QFileDialog, QDesktopWidget, QTextEdit
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QThread
# PyInstaller requirements
import packaging
from packaging import specifiers
from packaging import requirements
# Application root location ↓
appFolder = os.path.dirname(os.path.realpath(sys.argv[0])) + '/'
# Application's Main Window Class ↓
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
# Loading Main UI Design Files ↓
if(checkHash(appFolder + 'ui/MainWindow.ui', 'md5') == filesMD5.MainWindow_ui or filesMD5.skipCheck == 'skip'):
uic.loadUi(appFolder + 'ui/MainWindow.ui', self)
else:
sys.exit('MainWindow.ui file is corrupted')
# Loading custom styleSheet ↓
if(checkHash(appFolder + 'ui/default.css', 'md5') == filesMD5.default_css or filesMD5.skipCheck == 'skip'):
self.loadStyleSheet()
else:
sys.exit('default.css file is corrupted')
# Other UI Design Variables
if(checkHash(appFolder + 'ui/AboutWindow.ui', 'md5') == filesMD5.AboutWindow_ui or filesMD5.skipCheck == 'skip'):
self.aboutUiVar = AboutWindow()
else:
sys.exit('AboutWindow.ui file is corrupted')
# Loaded File Location Variable ↓
self.currentFileLoc = None
# Temp Variable
self.temp486 = tmpdir.tmpLoc + 'temp486.temp'
# Icons Variables ↓
self.icon = QIcon(':icon/icon.png')
self.doneIcon = QPixmap(':/done/done.png')
self.matchedIcon = QPixmap(':/matched/matched.png')
self.errorIcon = QPixmap(':/error/error.png')
self.loading = QMovie(':loading/loading.gif')
self.loadingBall = QMovie(':loadingBall/loadingBall.gif')
self.folderOpenIcon = QPixmap(':folder_open/folder_open.png')
# Software Version Variable
self.labelVersionString.setText(versionInfo.Software_Version)
# Main UI Calling ↓
self.hashCheckerUI()
def makeWindowCenter(self):
# For launching windows in center
qtRectangle = self.frameGeometry()
centerPoint = QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
self.move(qtRectangle.topLeft())
def customFont(self):
from QtGui import QFontDatabase, QFont
font = QFontDatabase.addApplicationFont('NAME.ttf')
font = QFont('NAME');
self.setFont(font)
def hashCheckerUI(self):
# Making window centered ↓
self.makeWindowCenter()
# Window customizing ↓
self.setWindowTitle('Hash Checker')
self.setWindowIcon(self.icon)
# Enabling Drag and Drop
self.setAcceptDrops(True)
# A Status
self.statusBar().showMessage('You can drag and drop a file, not multiple file')
# Buttons actions ↓
self.openFileButton.clicked.connect(self.openFileDialog)
self.removeFileButton.clicked.connect(self.removeFileButton_OnClick)
self.clearButton.clicked.connect(self.clearButton_OnClick)
self.clipboardButton.clicked.connect(self.clipboardText)
self.checkButton.clicked.connect(self.checkButton_OnClick)
self.aboutButton.clicked.connect(self.aboutUI)
# Clipboard Buttons actions ↓
self.clipboardMD5Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'md5'))
self.clipboardSHA256Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'sha256'))
self.clipboardSHA512Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'sha512'))
# Adding Place Holder Text ↓
self.textBoxMD5.setPlaceholderText('...')
self.textBoxSHA256.setPlaceholderText('...')
self.textBoxSHA512.setPlaceholderText('...')
self.textBoxCheck.setPlaceholderText('Paste your hash here to match with or leave empty\nOnly MD5 or SHA256 or SHA512 is allowed')
@pyqtSlot() # Qt Framework's Slot Decorator
def closeEvent(self, event):
try:
# Closing All Opened Window
self.aboutUiVar.close()
except AttributeError:
pass
# Custom Style Sheet ↓
def loadStyleSheet(self):
with open(appFolder + 'ui/default.css', 'r') as css:
self.styleSheet = css.read()
# Label font size customizing using CSS ↓
self.labelMD5.setStyleSheet(self.styleSheet)
self.labelSHA256.setStyleSheet(self.styleSheet)
self.labelSHA512.setStyleSheet(self.styleSheet)
self.labelHashBox.setStyleSheet(self.styleSheet)
# Button customizing using CSS ↓
self.aboutButton.setStyleSheet(self.styleSheet)
# Textbox font size customizing using CSS ↓
self.textBoxMD5.setStyleSheet(self.styleSheet)
self.textBoxSHA256.setStyleSheet(self.styleSheet)
self.textBoxSHA512.setStyleSheet(self.styleSheet)
self.textBoxCheck.setStyleSheet(self.styleSheet)
# Other User Interface Function ↓
def aboutUI(self):
# About Window
try:
self.aboutButton.clicked.disconnect()
except:
pass
self.aboutUiVar.show()
self.aboutButton.clicked.connect(self.aboutUI)
# Drag and Drop Functions ↓
def dragEnterEvent(self, e):
if e.mimeData().hasUrls():
e.accept()
else:
e.ignore()
def dragMoveEvent(self, e):
if e.mimeData().hasUrls():
e.accept()
else:
e.ignore()
def dropEvent(self, e):
if e.mimeData().text():
self.currentFileLoc = e.mimeData().text()
if(platform.system() == 'Windows'): # For Windows OS
# Removing 'file:///' # Example: 'file:///Rizwan Hasan' -> 'Rizwan Hasan'
self.currentFileLoc = self.currentFileLoc.replace('file:///', '')
print(self.currentFileLoc)
else:
# Removing 'file://' # Example: 'file:///Rizwan Hasan' -> '/Rizwan Hasan'
self.currentFileLoc = self.currentFileLoc.replace('file://', '')
# Removing '\n' # Example: 'Rizwan Hasan\n' -> 'Rizwan Hasan'
self.currentFileLoc = self.currentFileLoc[:len(self.currentFileLoc) - 2]
# Replacing '%20' with ' ' # Example: 'Rizwan%20Hasan' -> 'Rizwan Hasan'
self.currentFileLoc = self.currentFileLoc.replace('%20', ' ')
self.labelFile.setPixmap(self.doneIcon)
self.openFileButton.setText("'" + os.path.basename(self.currentFileLoc) + "' is loaded")
with open(self.temp486, 'w') as temp:
temp.write(self.currentFileLoc)
self.start_Hash_Calculation()
# Open With Function ↓
def openWith(self, argFile):
self.currentFileLoc = argFile
self.labelFile.setPixmap(self.doneIcon)
self.openFileButton.setText("'" + os.path.basename(self.currentFileLoc) + "' is loaded")
with open(self.temp486, 'w') as temp:
temp.write(self.currentFileLoc)
self.start_Hash_Calculation()
print(argFile)
# Clipboard Buttons Action Functions ↓
def clipboardButtonActions_OnClick(self, hashName):
try:
self.clipboardMD5Button.clicked.disconnect()
self.clipboardSHA256Button.clicked.disconnect()
self.clipboardSHA512Button.clicked.disconnect()
except:
pass
if(self.currentFileLoc != None):
if(hashName == 'md5'):
clipText = self.textBoxMD5.toPlainText()
pyperclip.copy(clipText.strip())
self.statusBar().showMessage('MD5sum has been copied to clipboard')
elif(hashName == 'sha256'):
clipText = self.textBoxSHA256.toPlainText()
pyperclip.copy(clipText.strip())
self.statusBar().showMessage('SHA256sum has been copied to clipboard')
elif(hashName == 'sha512'):
clipText = self.textBoxSHA512.toPlainText()
pyperclip.copy(clipText.strip())
self.statusBar().showMessage('SHA512sum has been copied to clipboard')
else:
pass
self.clipboardMD5Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'md5'))
self.clipboardSHA256Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'sha256'))
self.clipboardSHA512Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'sha512'))
# Clipboard Text ↓
def clipboardText(self):
try:
self.clipboardButton.clicked.disconnect()
except:
pass
clipText = QApplication.clipboard().text()
clipText = clipText.strip()
self.textBoxCheck.setText(clipText)
self.loadingBallAnimation('start')
self.clipboardButton.clicked.connect(self.clipboardText)
# Clear Button's Action ↓
def clearButton_OnClick(self):
self.loadingBallAnimation('stop')
self.labelLoadingBall.clear()
# Loading Ball Animation ↓
def loadingBallAnimation(self, decider):
self.loadingBall.setSpeed(150)
self.labelLoadingBall.setMovie(self.loadingBall)
if(decider == 'start'):
self.loadingBall.start()
elif(decider == 'stop'):
self.loadingBall.stop()
# Check Button's Action Function ↓
def checkButton_OnClick(self):
try:
self.checkButton.clicked.disconnect()
except:
pass
clipText = self.textBoxCheck.toPlainText()
clipText = clipText.strip()
if(len(clipText) == 32):
if(self.textBoxMD5.toPlainText() == clipText):
self.checkButtonDialogue('Congrats 😄😄😄\nMD5sum has matched')
else:
self.checkButtonDialogue('Sorry 😢😢😢\nMD5sum doesn\'t matched', -1)
elif(len(clipText) == 64):
if(self.textBoxSHA256.toPlainText() == clipText):
self.checkButtonDialogue('Congrats 😄😄😄\nSHA256sum has matched')
else:
self.checkButtonDialogue('Sorry 😢😢😢\nSHA256sum doesn\'t matched', -1)
elif(len(clipText) == 128):
if(self.textBoxSHA512.toPlainText() == clipText):
self.checkButtonDialogue('Congrats 😄😄😄\nSHA512sum has matched')
else:
self.checkButtonDialogue('Sorry 😢😢😢\nSHA512sum doesn\'t matched', -1)
elif(len(clipText) == 0):
self.checkButtonDialogue('Error 😠😠😠\nNo hash found', -1)
else:
self.checkButtonDialogue('Error 😤😤😤\nWrong Hashtype', -1)
self.checkButton.clicked.connect(self.checkButton_OnClick)
# Check Buttons Action Dialogue ↓
def checkButtonDialogue(self, message, checkResult=0):
msgBox = QMessageBox()
msgBox.setWindowTitle('Result')
if checkResult is 0:
msgBox.setIconPixmap(self.matchedIcon)
else:
msgBox.setIconPixmap(self.errorIcon)
msgBox.setWindowIcon(QIcon(':icon/icon.png'))
msgBox.setText(str(message))
msgBox.exec_()
# File Dialogs ↓
def openFileDialog(self):
try:
self.openFileButton.clicked.disconnect()
except:
pass
options = QFileDialog.Options()
# options |= QFileDialog.DontUseNativeDialog # Qt's builtin File Dialogue
fileName, _= QFileDialog.getOpenFileName(self, "Open", "", "All Files (*.*)", options=options)
if fileName:
self.currentFileLoc = fileName
self.labelFile.setPixmap(self.doneIcon)
self.openFileButton.setText("'" + os.path.basename(self.currentFileLoc) + "' is loaded")
with open(self.temp486, 'w') as temp:
temp.write(self.currentFileLoc)
self.start_Hash_Calculation()
self.openFileButton.clicked.connect(self.openFileDialog)
# Buttons Actions Function ↓
def start_Hash_Calculation(self):
self.loadingCircle('start')
self.textBoxMD5.setText("Computing...")
self.textBoxSHA256.setText("Computing...")
self.textBoxSHA512.setText("Computing...")
self.hashing = Hashing()
self.hashing.signalMD5.connect(self.textBoxMD5.setText)
self.hashing.signalSHA256.connect(self.textBoxSHA256.setText)
self.hashing.signalSHA512.connect(self.textBoxSHA512.setText)
self.hashing.signalStopLoading.connect(self.loadingCircle)
self.hashing.start()
# Loading Circle Initialize ↓
def loadingCircle(self, x):
if(x == 'start'):
self.loading.setSpeed(280)
self.labelDoneMD5.setMovie(self.loading)
self.labelDoneSHA256.setMovie(self.loading)
self.labelDoneSHA512.setMovie(self.loading)
self.loading.start()
elif(x == 'stop_MD5'):
self.labelDoneMD5.setPixmap(self.doneIcon)
elif(x == 'stop_SHA256'):
self.labelDoneSHA256.setPixmap(self.doneIcon)
elif(x == 'stop_SHA512'):
self.labelDoneSHA512.setPixmap(self.doneIcon)
# Remove Button's Action Function ↓
def removeFileButton_OnClick(self):
try:
self.removeFileButton.clicked.disconnect()
except:
pass
self.currentFileLoc = None
self.openFileButton.setText('Click to open a file')
self.textBoxMD5.clear()
self.textBoxSHA256.clear()
self.textBoxSHA512.clear()
self.textBoxCheck.clear()
self.labelDoneMD5.clear()
self.labelDoneSHA256.clear()
self.labelDoneSHA512.clear()
self.clearButton_OnClick()
self.labelFile.setPixmap(self.folderOpenIcon)
self.statusBar().showMessage('Cleared...')
time.sleep(1.0)
self.statusBar().showMessage('You can drag and drop a file, not multiple file')
self.removeFileButton.clicked.connect(self.removeFileButton_OnClick)
# Main Function ↓
def main():
app = QApplication(sys.argv)
mainWindow = MainWindow()
try:
mainWindow.openWith(sys.argv[1])
except IndexError:
pass
mainWindow.show()
sys.exit(app.exec_())
# Start Application ↓
if __name__ == '__main__':
main()