Skip to content

Commit e2d6f49

Browse files
committed
Fix Various Crashes
1 parent aebcc93 commit e2d6f49

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

launch.pyw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ from PyQt5.QtWidgets import QDialog, QApplication
88
myappid = 'VodBox.pyWinContext.1.0' # arbitrary string
99
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
1010

11+
if not hasattr(sys, "_MEIPASS"):
12+
sys._MEIPASS = "."
13+
1114
class LaunchDialog(QDialog, launch_dialog.Ui_Dialog):
1215
def __init__(self):
1316
super(self.__class__, self).__init__()

regutils.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def create_sub_command(name, desc, command, icon):
1111
else:
1212
winreg.SetValueEx(key, "Icon", 0, winreg.REG_SZ, "")
1313
winreg.SetValueEx(key, "direct", 0, winreg.REG_SZ, "Yes")
14+
key.Close()
1415

1516
def create_sub_group(name, desc, icon, coms):
1617
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell',0,winreg.KEY_ALL_ACCESS|winreg.KEY_WOW64_64KEY)
@@ -22,6 +23,8 @@ def create_sub_group(name, desc, icon, coms):
2223
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, icon)
2324
else:
2425
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, "")
26+
key.Close()
27+
comKey.Close()
2528

2629
def create_group(name, desc, filetype, icon, coms):
2730
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
@@ -32,6 +35,8 @@ def create_group(name, desc, filetype, icon, coms):
3235
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, icon)
3336
else:
3437
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, "")
38+
key.Close()
39+
comKey.Close()
3540

3641
def create_command(name, desc, command, filetype, icon):
3742
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
@@ -41,6 +46,8 @@ def create_command(name, desc, command, filetype, icon):
4146
winreg.SetValue(comKey, "Icon", winreg.REG_SZ, icon)
4247
winreg.CreateKey(comKey, "command")
4348
winreg.SetValue(comKey, "command", winreg.REG_SZ, command)
49+
key.Close()
50+
comKey.Close()
4451

4552
def get_file_types():
4653
keys = {}
@@ -61,25 +68,37 @@ def get_file_types():
6168
return keys
6269

6370
def remove_file_association(filetype, name):
64-
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
65-
comKey = winreg.CreateKey(key, name)
66-
remove_all_sub_keys(comKey)
67-
winreg.DeleteKey(key, name)
71+
try:
72+
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
73+
comKey = winreg.CreateKey(key, name)
74+
remove_all_sub_keys(comKey)
75+
comKey.Close()
76+
winreg.DeleteKey(key, name)
77+
key.Close()
78+
except WindowsError:
79+
pass
6880

6981
def remove_command_store(name):
70-
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell")
71-
comKey = winreg.CreateKey(key, name)
72-
remove_all_sub_keys(comKey)
73-
winreg.DeleteKey(key, name)
82+
try:
83+
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell")
84+
comKey = winreg.CreateKey(key, name)
85+
remove_all_sub_keys(comKey)
86+
comKey.Close()
87+
winreg.DeleteKey(key, name)
88+
key.Close()
89+
except WindowsError as e:
90+
print(e)
7491

7592
def remove_all_sub_keys(key):
7693
index = 0
7794
length = winreg.QueryInfoKey(key)[0]
78-
for i in range(0, length):
95+
while length > 0:
7996
try:
80-
subname = winreg.EnumKey(key, i)
97+
subname = winreg.EnumKey(key, 0)
8198
subkey = winreg.CreateKey(key, subname)
8299
remove_all_sub_keys(subkey)
100+
subkey.Close()
101+
length -= 1
83102
winreg.DeleteKey(key, subname)
84103
except OSError as e:
85-
pass
104+
print(e)

wincontext.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class ComModes:
3838

3939
import output
4040

41+
if not hasattr(sys, "_MEIPASS"):
42+
sys._MEIPASS = "."
43+
4144
class WinContextApp(QMainWindow, app.Ui_MainWindow):
4245
def __init__(self, direct):
4346
super(self.__class__, self).__init__()
@@ -70,11 +73,11 @@ def changes(self):
7073

7174
def initUI(self):
7275
app_icon = QtGui.QIcon()
73-
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_16.png', QtCore.QSize(16,16))
74-
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_24.png', QtCore.QSize(24,24))
75-
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_32.png', QtCore.QSize(32,32))
76-
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_48.png', QtCore.QSize(48,48))
77-
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon.png', QtCore.QSize(256,256))
76+
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_16.png', QtCore.QSize(16,16))
77+
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_24.png', QtCore.QSize(24,24))
78+
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_32.png', QtCore.QSize(32,32))
79+
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_48.png', QtCore.QSize(48,48))
80+
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon.png', QtCore.QSize(256,256))
7881
self.setWindowIcon(app_icon)
7982
self.actionExit.triggered.connect(self.close)
8083
self.actionSave.triggered.connect(self.action_save)

0 commit comments

Comments
 (0)