-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLockerDialog.py
109 lines (86 loc) · 3.75 KB
/
LockerDialog.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
import sys
import time
from PySide import QtCore, QtGui
from PySide.QtCore import QThread, SIGNAL, Qt, Signal, QObject
from PySide.QtGui import QDialog, QApplication, QMessageBox, QFileDialog
import ui_maindialog
from EXELockerFile.Encryptor import EncryptedFile, _ISPRODUCTION_
import admin
__appname__ = "EXE Locker"
class LockerDialog(QDialog, ui_maindialog.Ui_MainDialog):
signal = Signal(str)
def __init__(self, parent=None):
super(LockerDialog, self).__init__(parent)
if _ISPRODUCTION_:
if not admin.isUserAdmin():
admin.runAsAdmin()
sys.exit(0)
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
self.setFixedSize(self.width(), self.height())
self.lockButton.setEnabled(False) # lock the exe button still password is set
self.pickFileButton.clicked.connect(self.showFileDialog)
self.passwordLineEdit.textChanged.connect(self.checkPasswordMatch)
self.passwordAgainLineEdit.textChanged.connect(self.checkPasswordMatch)
self.lockButton.clicked.connect(self._lockFile)
# Connect to threadDone event
self.signal.connect(self.fileLockedEvent)
def fileLockedEvent(self, fileName):
msgSuccess = "{0} locked successfully.".format(fileName)
QMessageBox.information(self, __appname__, msgSuccess)
self.lockButton.setText("Lock EXE")
self.lockButton.setEnabled(True)
self.groupBox.setEnabled(True)
self.step1GroupBox.setEnabled(True)
def showFileDialog(self):
dir = "."
fileObj = QFileDialog.getOpenFileName(self, "Select Executable to lock", dir="", filter="EXE file (*.exe)")
if len(fileObj) > 0:
self.locationLineEdit.setText(fileObj[0])
else:
return None
def checkPasswordMatch(self):
if self._passwordNotEmpty() and self._passwordEquals():
self.lockButton.setEnabled(True)
self.label_4.setVisible(False)
else:
self.lockButton.setEnabled(False)
self.label_4.setVisible(True)
def _passwordNotEmpty(self):
if len(self.passwordLineEdit.text()) == 0 or len(self.passwordAgainLineEdit.text()) == 0:
return False
else:
return True
def _passwordEquals(self):
if self.passwordLineEdit.text() == self.passwordAgainLineEdit.text():
return True
else:
return False
def _lockFile(self):
fileName = self.locationLineEdit.text()
if len(self.locationLineEdit.text()) == 0 or self.locationLineEdit.text() == None:
QMessageBox.information(self, __appname__, "Pick an exe file first to lock.")
self.showFileDialog()
else:
password = self.passwordLineEdit.text()
makeBackup = self.checkBox.isChecked()
self.workerThread = WorkerThread(fileName, password, self.signal, makeBackup)
self.lockButton.setText("Working")
self.lockButton.setEnabled(False)
self.groupBox.setEnabled(False)
self.step1GroupBox.setEnabled(False)
self.workerThread.start()
class WorkerThread(QThread):
def __init__(self, fileName, password, signal, makeBackup = False, parent=None):
super(WorkerThread, self).__init__(parent)
self.fileName = fileName
self.signal = signal
self.password = password
self.makeBackup = makeBackup
def run(self):
file = EncryptedFile.createEncryptedFile(self.fileName, self.password, baseFileLocation=EncryptedFile.CALLER_LOCATION, makeBackup=self.makeBackup)
self.signal.emit(self.fileName)
app = QApplication(sys.argv)
locker = LockerDialog()
locker.show()
app.exec_()