diff --git a/launch.pyw b/launch.pyw index b6b9590..c70b990 100644 --- a/launch.pyw +++ b/launch.pyw @@ -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__() diff --git a/regutils.py b/regutils.py index c0bc0b3..1aa3380 100644 --- a/regutils.py +++ b/regutils.py @@ -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) @@ -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") @@ -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") @@ -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 = {} @@ -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) diff --git a/wincontext.py b/wincontext.py index d3540ca..2fe16d0 100644 --- a/wincontext.py +++ b/wincontext.py @@ -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__() @@ -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)