Skip to content

Commit

Permalink
Fix Various Crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
VodBox committed Apr 3, 2018
1 parent aebcc93 commit e2d6f49
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
3 changes: 3 additions & 0 deletions launch.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ from PyQt5.QtWidgets import QDialog, QApplication
myappid = 'VodBox.pyWinContext.1.0' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

if not hasattr(sys, "_MEIPASS"):
sys._MEIPASS = "."

class LaunchDialog(QDialog, launch_dialog.Ui_Dialog):
def __init__(self):
super(self.__class__, self).__init__()
Expand Down
41 changes: 30 additions & 11 deletions regutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def create_sub_command(name, desc, command, icon):
else:
winreg.SetValueEx(key, "Icon", 0, winreg.REG_SZ, "")
winreg.SetValueEx(key, "direct", 0, winreg.REG_SZ, "Yes")
key.Close()

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

def create_group(name, desc, filetype, icon, coms):
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
Expand All @@ -32,6 +35,8 @@ def create_group(name, desc, filetype, icon, coms):
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, icon)
else:
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, "")
key.Close()
comKey.Close()

def create_command(name, desc, command, filetype, icon):
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
Expand All @@ -41,6 +46,8 @@ def create_command(name, desc, command, filetype, icon):
winreg.SetValue(comKey, "Icon", winreg.REG_SZ, icon)
winreg.CreateKey(comKey, "command")
winreg.SetValue(comKey, "command", winreg.REG_SZ, command)
key.Close()
comKey.Close()

def get_file_types():
keys = {}
Expand All @@ -61,25 +68,37 @@ def get_file_types():
return keys

def remove_file_association(filetype, name):
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
comKey = winreg.CreateKey(key, name)
remove_all_sub_keys(comKey)
winreg.DeleteKey(key, name)
try:
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
comKey = winreg.CreateKey(key, name)
remove_all_sub_keys(comKey)
comKey.Close()
winreg.DeleteKey(key, name)
key.Close()
except WindowsError:
pass

def remove_command_store(name):
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell")
comKey = winreg.CreateKey(key, name)
remove_all_sub_keys(comKey)
winreg.DeleteKey(key, name)
try:
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell")
comKey = winreg.CreateKey(key, name)
remove_all_sub_keys(comKey)
comKey.Close()
winreg.DeleteKey(key, name)
key.Close()
except WindowsError as e:
print(e)

def remove_all_sub_keys(key):
index = 0
length = winreg.QueryInfoKey(key)[0]
for i in range(0, length):
while length > 0:
try:
subname = winreg.EnumKey(key, i)
subname = winreg.EnumKey(key, 0)
subkey = winreg.CreateKey(key, subname)
remove_all_sub_keys(subkey)
subkey.Close()
length -= 1
winreg.DeleteKey(key, subname)
except OSError as e:
pass
print(e)
13 changes: 8 additions & 5 deletions wincontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ComModes:

import output

if not hasattr(sys, "_MEIPASS"):
sys._MEIPASS = "."

class WinContextApp(QMainWindow, app.Ui_MainWindow):
def __init__(self, direct):
super(self.__class__, self).__init__()
Expand Down Expand Up @@ -70,11 +73,11 @@ def changes(self):

def initUI(self):
app_icon = QtGui.QIcon()
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_16.png', QtCore.QSize(16,16))
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_24.png', QtCore.QSize(24,24))
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_32.png', QtCore.QSize(32,32))
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon_48.png', QtCore.QSize(48,48))
app_icon.addFile(sys._MEIPASS+ '/' + 'images/icon.png', QtCore.QSize(256,256))
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_16.png', QtCore.QSize(16,16))
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_24.png', QtCore.QSize(24,24))
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_32.png', QtCore.QSize(32,32))
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon_48.png', QtCore.QSize(48,48))
app_icon.addFile(sys._MEIPASS + '/' + 'images/icon.png', QtCore.QSize(256,256))
self.setWindowIcon(app_icon)
self.actionExit.triggered.connect(self.close)
self.actionSave.triggered.connect(self.action_save)
Expand Down

0 comments on commit e2d6f49

Please sign in to comment.