1
- import regutils
1
+ import regutils as reg
2
2
import json
3
3
import os
4
4
import sys
13
13
ComModes = None
14
14
15
15
def reg_save (data , oldData ):
16
+ global completedBat , completedIcon
17
+ completedBat = {}
18
+ completedIcon = {}
16
19
global completed
17
20
completed = {}
18
21
comStorePath = Path (configLoc + "\\ comStore" )
@@ -52,33 +55,51 @@ def reg_save(data, oldData):
52
55
subprocess .Popen (["explorer" , "/select," + configLoc + "\\ run\\ Setup.reg" ])
53
56
54
57
def direct_save (data , oldData ):
58
+ global completedBat , completedIcon
59
+ completedBat = {}
60
+ completedIcon = {}
55
61
outData = data_to_out (data )
56
62
if oldData != None :
57
63
direct_clear (oldData )
64
+ direct_add (data )
58
65
59
66
def create_reg_clear (data ):
60
67
result = ""
61
68
outData = data_to_out (data )
62
69
for filetype in outData ["filetypes" ]:
63
70
info = outData ["filetypes" ][filetype ]
64
71
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 "
66
73
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 "
68
75
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 "
70
77
return result
71
78
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
+
72
93
def create_reg_add (data ):
73
94
result = ""
74
95
outData = data_to_out (data )
75
96
for filetype in outData ["filetypes" ]:
76
97
result += "[HKEY_CLASSES_ROOT\\ SystemFileAssociations\\ " + filetype + "\\ shell]\r \n \r \n "
77
98
info = outData ["filetypes" ][filetype ]
78
99
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 "
80
101
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 "
82
103
result += "@=\" cmd /c " + configLoc .replace ("\\ " , "\\ \\ " ) + "\\ \\ comStore\\ \\ " + str (command ["id" ]) + ".bat %1\" \r \n "
83
104
if "icon_path" in command and command ["icon_path" ] != None :
84
105
create_icon (command ["icon_path" ], command ["id" ])
@@ -87,18 +108,18 @@ def create_reg_add(data):
87
108
create_bat (command )
88
109
for group in info ["groups" ]:
89
110
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 "
91
112
result += "\" MUIVerb\" =\" " + groupObj ["name" ] + "\" \r \n "
92
113
coms = ""
93
114
newSub = ""
94
115
for com in groupObj ["coms" ]:
95
116
if coms != "" :
96
117
coms += ";"
97
118
if type (com ) is int :
98
- coms += "pyWin- " + outData ["commandStore" ][com ]["regname" ]
119
+ coms += "pyWin" + outData ["commandStore" ][com ]["regname" ]
99
120
else :
100
121
for key in com :
101
- coms += "pyWin- " + filetype + "-" + key
122
+ coms += "pyWin" + filetype + "-" + key
102
123
newSub += create_sub_commands (filetype , com [key ], key , outData )
103
124
result += "\" SubCommands\" =\" " + coms + "\" \r \n "
104
125
if "icon_path" in groupObj and groupObj ["icon_path" ] != None :
@@ -108,17 +129,76 @@ def create_reg_add(data):
108
129
result += newSub
109
130
for command in outData ["commandStore" ]:
110
131
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 "
112
133
result += "@=\" " + com ["description" ] + "\" \r \n "
113
134
if "icon_path" in com and com ["icon_path" ] != None :
114
135
create_icon (com ["icon_path" ], com ["id" ])
115
136
result += "\" Icon\" =\" " + configLoc .replace ("\\ " , "\\ \\ " ) + "\\ \\ iconStore\\ \\ " + str (com ["id" ]) + ".ico,0\" \r \n "
116
137
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 "
118
139
result += "@=\" cmd /c " + configLoc .replace ("\\ " , "\\ \\ " ) + "\\ \\ comStore\\ \\ " + str (com ["id" ]) + ".bat \\ \" %1\\ \" \" \r \n \r \n "
119
140
create_bat (com )
120
141
return result
121
142
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
+
122
202
def data_to_out (data ):
123
203
res = create_db ()
124
204
for key in data :
@@ -208,26 +288,42 @@ def make_square(im, min_size=72, fill_color=(0, 0, 0, 0)):
208
288
return new_im
209
289
210
290
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 "
212
292
result += "\" MUIVerb\" =\" " + data ["name" ] + "\" \r \n "
213
293
coms = ""
214
294
newSub = ""
215
295
for com in data ["coms" ]:
216
296
if coms != "" :
217
297
coms += ";"
218
298
if type (com ) is int :
219
- coms += "pyWin- " + outData ["commandStore" ][com ]["regname" ]
299
+ coms += "pyWin" + outData ["commandStore" ][com ]["regname" ]
220
300
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" ]
223
303
newSub += create_sub_commands (filetype , com [key ], key , outData )
224
304
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 "
225
308
result += newSub
226
309
return result
227
310
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 )
231
327
232
328
def main ():
233
329
file = open ("C:\\ Users\\ Dillon\\ AppData\\ Roaming\\ pyWinContext\\ config.json" , 'r' )
0 commit comments