Skip to content

Commit f1da06e

Browse files
committed
Add Direct Saving Mode
1 parent 089344e commit f1da06e

File tree

7 files changed

+184
-58
lines changed

7 files changed

+184
-58
lines changed

UI/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Form implementation generated from reading ui file 'app.ui'
44
#
5-
# Created by: PyQt5 UI code generator 5.10
5+
# Created by: PyQt5 UI code generator 5.10.1
66
#
77
# WARNING! All changes made in this file will be lost!
88

UI/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Form implementation generated from reading ui file 'command.ui'
44
#
5-
# Created by: PyQt5 UI code generator 5.10
5+
# Created by: PyQt5 UI code generator 5.10.1
66
#
77
# WARNING! All changes made in this file will be lost!
88

UI/launch_dialog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Form implementation generated from reading ui file 'launch_dialog.ui'
44
#
5-
# Created by: PyQt5 UI code generator 5.10
5+
# Created by: PyQt5 UI code generator 5.10.1
66
#
77
# WARNING! All changes made in this file will be lost!
88

@@ -47,12 +47,12 @@ def setupUi(self, Dialog):
4747
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
4848
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
4949
self.radioButton_2 = QtWidgets.QRadioButton(Dialog)
50-
self.radioButton_2.setEnabled(False)
50+
self.radioButton_2.setEnabled(True)
5151
self.radioButton_2.setMaximumSize(QtCore.QSize(85, 16777215))
5252
self.radioButton_2.setObjectName("radioButton_2")
5353
self.horizontalLayout_2.addWidget(self.radioButton_2)
5454
self.label_2 = QtWidgets.QLabel(Dialog)
55-
self.label_2.setEnabled(False)
55+
self.label_2.setEnabled(True)
5656
self.label_2.setMinimumSize(QtCore.QSize(0, 60))
5757
self.label_2.setMaximumSize(QtCore.QSize(16777215, 240))
5858
self.label_2.setScaledContents(False)

UI/launch_dialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<item>
9191
<widget class="QRadioButton" name="radioButton_2">
9292
<property name="enabled">
93-
<bool>false</bool>
93+
<bool>true</bool>
9494
</property>
9595
<property name="maximumSize">
9696
<size>
@@ -106,7 +106,7 @@
106106
<item>
107107
<widget class="QLabel" name="label_2">
108108
<property name="enabled">
109-
<bool>false</bool>
109+
<bool>true</bool>
110110
</property>
111111
<property name="minimumSize">
112112
<size>

output.py

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import regutils
1+
import regutils as reg
22
import json
33
import os
44
import sys
@@ -13,6 +13,9 @@
1313
ComModes = None
1414

1515
def reg_save(data, oldData):
16+
global completedBat, completedIcon
17+
completedBat = {}
18+
completedIcon = {}
1619
global completed
1720
completed = {}
1821
comStorePath = Path(configLoc + "\\comStore")
@@ -52,33 +55,51 @@ def reg_save(data, oldData):
5255
subprocess.Popen(["explorer", "/select," + configLoc + "\\run\\Setup.reg"])
5356

5457
def direct_save(data, oldData):
58+
global completedBat, completedIcon
59+
completedBat = {}
60+
completedIcon = {}
5561
outData = data_to_out(data)
5662
if oldData != None:
5763
direct_clear(oldData)
64+
direct_add(data)
5865

5966
def create_reg_clear(data):
6067
result = ""
6168
outData = data_to_out(data)
6269
for filetype in outData["filetypes"]:
6370
info = outData["filetypes"][filetype]
6471
for command in info["commands"]:
65-
result += "[-HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + command["regname"] + "]\r\n\r\n"
72+
result += "[-HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin" + command["regname"] + "]\r\n\r\n"
6673
for group in info["groups"]:
67-
result += "[-HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + group + "]\r\n\r\n"
74+
result += "[-HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin" + group + "]\r\n\r\n"
6875
for command in outData["commandStore"]:
69-
result += "[-HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + outData["commandStore"][command]["regname"] + "]\r\n\r\n"
76+
result += "[-HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin" + outData["commandStore"][command]["regname"] + "]\r\n\r\n"
7077
return result
7178

79+
def direct_clear(data):
80+
outData = data_to_out(data)
81+
for filetype in outData["filetypes"]:
82+
info = outData["filetypes"][filetype]
83+
for command in info["commands"]:
84+
reg.remove_file_association(filetype, "pyWin" + command["regname"])
85+
# result += "[-HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + command["regname"] + "]\r\n\r\n"
86+
for group in info["groups"]:
87+
reg.remove_file_association(filetype, "pyWin" + group)
88+
# result += "[-HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + group + "]\r\n\r\n"
89+
for command in outData["commandStore"]:
90+
reg.remove_command_store("pyWin" + outData["commandStore"][command]["regname"])
91+
# result += "[-HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + outData["commandStore"][command]["regname"] + "]\r\n\r\n"
92+
7293
def create_reg_add(data):
7394
result = ""
7495
outData = data_to_out(data)
7596
for filetype in outData["filetypes"]:
7697
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell]\r\n\r\n"
7798
info = outData["filetypes"][filetype]
7899
for command in info["commands"]:
79-
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + command["regname"] + "]\r\n"
100+
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin" + command["regname"] + "]\r\n"
80101
result += "@=\"" + command["description"].replace('"', '\\"') + "\"\r\n\r\n"
81-
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + command["regname"] + "\\command]\r\n"
102+
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin" + command["regname"] + "\\command]\r\n"
82103
result += "@=\"cmd /c " + configLoc.replace("\\", "\\\\") + "\\\\comStore\\\\" + str(command["id"]) + ".bat %1\"\r\n"
83104
if "icon_path" in command and command["icon_path"] != None:
84105
create_icon(command["icon_path"], command["id"])
@@ -87,18 +108,18 @@ def create_reg_add(data):
87108
create_bat(command)
88109
for group in info["groups"]:
89110
groupObj = info["groups"][group]
90-
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + group + "]\r\n"
111+
result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin" + group + "]\r\n"
91112
result += "\"MUIVerb\"=\"" + groupObj["name"] + "\"\r\n"
92113
coms = ""
93114
newSub = ""
94115
for com in groupObj["coms"]:
95116
if coms != "":
96117
coms += ";"
97118
if type(com) is int:
98-
coms += "pyWin-" + outData["commandStore"][com]["regname"]
119+
coms += "pyWin" + outData["commandStore"][com]["regname"]
99120
else:
100121
for key in com:
101-
coms += "pyWin-" + filetype + "-" + key
122+
coms += "pyWin" + filetype + "-" + key
102123
newSub += create_sub_commands(filetype, com[key], key, outData)
103124
result += "\"SubCommands\"=\"" + coms + "\"\r\n"
104125
if "icon_path" in groupObj and groupObj["icon_path"] != None:
@@ -108,17 +129,76 @@ def create_reg_add(data):
108129
result += newSub
109130
for command in outData["commandStore"]:
110131
com = outData["commandStore"][command]
111-
result += "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + com["regname"] + "]\r\n"
132+
result += "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin" + com["regname"] + "]\r\n"
112133
result += "@=\"" + com["description"] + "\"\r\n"
113134
if "icon_path" in com and com["icon_path"] != None:
114135
create_icon(com["icon_path"], com["id"])
115136
result += "\"Icon\"=\"" + configLoc.replace("\\", "\\\\") + "\\\\iconStore\\\\" + str(com["id"]) + ".ico,0\"\r\n"
116137
result += "\r\n"
117-
result += "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + com["regname"] + "\\command]\r\n"
138+
result += "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin" + com["regname"] + "\\command]\r\n"
118139
result += "@=\"cmd /c " + configLoc.replace("\\", "\\\\") + "\\\\comStore\\\\" + str(com["id"]) + ".bat \\\"%1\\\"\"\r\n\r\n"
119140
create_bat(com)
120141
return result
121142

143+
def direct_add(data):
144+
outData = data_to_out(data)
145+
for filetype in outData["filetypes"]:
146+
#result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell]\r\n\r\n"
147+
info = outData["filetypes"][filetype]
148+
for command in info["commands"]:
149+
iconPath = None
150+
if "icon_path" in command and command["icon_path"] != None:
151+
create_icon(command["icon_path"], command["id"])
152+
iconPath = configLoc + "\\iconStore\\" + str(command["id"]) + ".ico,0"
153+
reg.create_command("pyWin" + command["regname"], command["description"],
154+
"cmd /c " + configLoc + "\\comStore\\" + str(command["id"]) + ".bat %1",
155+
filetype, iconPath)
156+
#result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + command["regname"] + "]\r\n"
157+
#result += "@=\"" + command["description"].replace('"', '\\"') + "\"\r\n\r\n"
158+
#result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + command["regname"] + "\\command]\r\n"
159+
#result += "@=\"cmd /c " + configLoc.replace("\\", "\\\\") + "\\\\comStore\\\\" + str(command["id"]) + ".bat %1\"\r\n"
160+
#if "icon_path" in command and command["icon_path"] != None:
161+
# create_icon(command["icon_path"], command["id"])
162+
# result += "\"Icon\"=\"" + configLoc.replace("\\", "\\\\") + "\\\\iconStore\\\\" + str(command["id"]) + ".ico,0\"\r\n"
163+
#result += "\r\n"
164+
create_bat(command)
165+
for group in info["groups"]:
166+
groupObj = info["groups"][group]
167+
iconPath = None
168+
if "icon_path" in groupObj and groupObj["icon_path"] != None:
169+
create_icon(groupObj["icon_path"], group)
170+
iconPath = configLoc + "\\iconStore\\" + group + ".ico,0"
171+
coms = ""
172+
for com in groupObj["coms"]:
173+
if coms != "":
174+
coms += ";"
175+
if type(com) is int:
176+
coms += "pyWin" + outData["commandStore"][com]["regname"]
177+
else:
178+
for key in com:
179+
coms += "pyWin" + filetype + "-" + key
180+
direct_sub(filetype, com[key], key, outData)
181+
reg.create_group("pyWin" + group, groupObj["name"], filetype, iconPath, coms)
182+
#result += "[HKEY_CLASSES_ROOT\\SystemFileAssociations\\" + filetype + "\\shell\\pyWin-" + group + "]\r\n"
183+
#result += "\"MUIVerb\"=\"" + groupObj["name"] + "\"\r\n"
184+
#result += "\"SubCommands\"=\"" + coms + "\"\r\n"
185+
#result += "\r\n"
186+
#result += newSub
187+
for command in outData["commandStore"]:
188+
com = outData["commandStore"][command]
189+
#result += "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + com["regname"] + "]\r\n"
190+
#result += "@=\"" + com["description"] + "\"\r\n"
191+
iconPath = None
192+
if "icon_path" in com and com["icon_path"] != None:
193+
create_icon(com["icon_path"], com["id"])
194+
iconPath = configLoc+ "\\iconStore\\" + str(com["id"]) + ".ico,0"
195+
reg.create_sub_command("pyWin" + com["regname"], com["description"],
196+
"cmd /c " + configLoc + "\\comStore\\" + str(com["id"]) + ".bat \"%1\"", iconPath)
197+
#result += "\r\n"
198+
#result += "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + com["regname"] + "\\command]\r\n"
199+
#result += "@=\"cmd /c " + configLoc.replace("\\", "\\\\") + "\\\\comStore\\\\" + str(com["id"]) + ".bat \\\"%1\\\"\"\r\n\r\n"
200+
create_bat(com)
201+
122202
def data_to_out(data):
123203
res = create_db()
124204
for key in data:
@@ -208,26 +288,42 @@ def make_square(im, min_size=72, fill_color=(0, 0, 0, 0)):
208288
return new_im
209289

210290
def create_sub_commands(filetype, data, key, outData):
211-
result = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin-" + filetype + "-" + key + "]\r\n"
291+
result = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\pyWin" + filetype + "-" + key + "]\r\n"
212292
result += "\"MUIVerb\"=\"" + data["name"] + "\"\r\n"
213293
coms = ""
214294
newSub = ""
215295
for com in data["coms"]:
216296
if coms != "":
217297
coms += ";"
218298
if type(com) is int:
219-
coms += "pyWin-" + outData["commandStore"][com]["regname"]
299+
coms += "pyWin" + outData["commandStore"][com]["regname"]
220300
else:
221-
for key in com:
222-
coms += "pyWin-" + filetype + "-" + com[key]["name"]
301+
for subkey in com:
302+
coms += "pyWin" + filetype + "-" + com[key]["name"]
223303
newSub += create_sub_commands(filetype, com[key], key, outData)
224304
result += "\"SubCommands\"=\"" + coms + "\"\r\n\r\n"
305+
if "icon_path" in data and data["icon_path"] != None and data["icon_path"] != "":
306+
create_icon(data["icon_path"], data["name"])
307+
result += "\"Icon\"=\"" + configLoc.replace("\\", "\\\\") + "\\\\iconStore\\\\" + data["name"] + ".ico,0\"\r\n"
225308
result += newSub
226309
return result
227310

228-
229-
def direct_clear(data):
230-
pass
311+
def direct_sub(filetype, data, key, outData):
312+
coms = ""
313+
for com in data["coms"]:
314+
if coms != "":
315+
coms += ";"
316+
if type(com) is int:
317+
coms += "pyWin" + outData["commandStore"][com]["regname"]
318+
else:
319+
for subkey in com:
320+
coms += "pyWin" + filetype + "-" + subkey
321+
direct_sub(filetype, com[subkey], subkey, outData)
322+
iconPath = None
323+
if "icon_path" in data and data["icon_path"] != None and data["icon_path"] != "":
324+
create_icon(data["icon_path"], data["name"])
325+
iconPath = configLoc + "\\iconStore\\" + data["name"] + ".ico,0"
326+
reg.create_sub_group("pyWin" + filetype + "-" + key, data["name"], iconPath, coms)
231327

232328
def main():
233329
file = open("C:\\Users\\Dillon\\AppData\\Roaming\\pyWinContext\\config.json", 'r')

regutils.py

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
import winreg
2+
import time
23

3-
def create_sub_command(name, desc, command):
4-
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell\\" + name)
5-
winreg.SetValue(key, "", winreg.REG_SZ, desc)
6-
comKey = winreg.CreateKey(key, "command")
7-
winreg.SetValue(comKey, "", winreg.REG_SZ, command)
4+
def create_sub_command(name, desc, command, icon):
5+
hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell',0,winreg.KEY_ALL_ACCESS|winreg.KEY_WOW64_64KEY)
6+
key = winreg.CreateKey(hkey, name)
7+
winreg.SetValueEx(key, "", 0, winreg.REG_SZ, desc)
8+
winreg.SetValue(key, "command", winreg.REG_SZ, command)
9+
if icon != None:
10+
winreg.SetValueEx(key, "Icon", 0, winreg.REG_SZ, icon)
11+
else:
12+
winreg.SetValueEx(key, "Icon", 0, winreg.REG_SZ, "")
13+
winreg.SetValueEx(key, "direct", 0, winreg.REG_SZ, "Yes")
814

9-
def link_sub_command(name, desc, comName, filetype):
10-
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\." + filetype + "\\shell")
15+
def create_sub_group(name, desc, icon, coms):
16+
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CommandStore\\shell',0,winreg.KEY_ALL_ACCESS|winreg.KEY_WOW64_64KEY)
1117
comKey = winreg.CreateKey(key, name)
1218
winreg.SetValueEx(comKey, "MUIVerb", 0, winreg.REG_SZ, desc)
13-
subs = ("")
14-
try:
15-
subs = winreg.QueryValueEx(comKey, "SubCommands")
16-
except Exception as e:
17-
subs = ("")
18-
winreg.SetValueEx(comKey, "SubCommands", 0, winreg.REG_SZ, ((subs[0] + ";") if subs[0] != "" else "") + comName)
19-
20-
def create_command(name, desc, command, filetype):
21-
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\." + filetype + "\\shell")
19+
winreg.SetValueEx(comKey, "SubCommands", 0, winreg.REG_SZ, coms)
20+
winreg.SetValueEx(comKey, "Direct", 0, winreg.REG_SZ, "Yes")
21+
if icon != None:
22+
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, icon)
23+
else:
24+
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, "")
25+
26+
def create_group(name, desc, filetype, icon, coms):
27+
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
28+
comKey = winreg.CreateKey(key, name)
29+
winreg.SetValueEx(comKey, "MUIVerb", 0, winreg.REG_SZ, desc)
30+
winreg.SetValueEx(comKey, "SubCommands", 0, winreg.REG_SZ, coms)
31+
if icon != None:
32+
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, icon)
33+
else:
34+
winreg.SetValueEx(comKey, "Icon", 0, winreg.REG_SZ, "")
35+
36+
def create_command(name, desc, command, filetype, icon):
37+
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\" + filetype + "\\shell")
2238
comKey = winreg.CreateKey(key, name)
2339
winreg.SetValue(key, name, winreg.REG_SZ, desc)
40+
if icon != None:
41+
winreg.SetValue(comKey, "Icon", winreg.REG_SZ, icon)
2442
winreg.CreateKey(comKey, "command")
2543
winreg.SetValue(comKey, "command", winreg.REG_SZ, command)
2644

27-
def get_sub_command_string(filetype, name):
28-
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "SystemFileAssociations\\." + filetype + "\\shell\\" + name)
29-
try:
30-
subs = winreg.QueryValueEx(key, "SubCommands")
31-
return subs[0]
32-
except Exception as e:
33-
return ""
34-
35-
def get_sub_commands(filetype, name):
36-
subs = get_sub_command_string(filetype, name)
37-
return subs.split(";")
38-
3945
def get_file_types():
4046
keys = {}
4147
length = winreg.QueryInfoKey(winreg.HKEY_CLASSES_ROOT)[0]
@@ -53,3 +59,27 @@ def get_file_types():
5359
except Exception as e:
5460
pass
5561
return keys
62+
63+
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)
68+
69+
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)
74+
75+
def remove_all_sub_keys(key):
76+
index = 0
77+
length = winreg.QueryInfoKey(key)[0]
78+
for i in range(0, length):
79+
try:
80+
subname = winreg.EnumKey(key, i)
81+
subkey = winreg.CreateKey(key, subname)
82+
remove_all_sub_keys(subkey)
83+
winreg.DeleteKey(key, subname)
84+
except OSError as e:
85+
pass

0 commit comments

Comments
 (0)