Add --shellopen, --yes arguments.
This is quickly becoming a general-purpose reg editor.
This commit is contained in:
parent
672c7de76f
commit
7d1720094e
1 changed files with 24 additions and 2 deletions
|
@ -23,6 +23,9 @@ ico_file:
|
||||||
--name:
|
--name:
|
||||||
A human-friendly name string which will show on Explorer under the "Type"
|
A human-friendly name string which will show on Explorer under the "Type"
|
||||||
column and in the properties dialog.
|
column and in the properties dialog.
|
||||||
|
|
||||||
|
--shellopen:
|
||||||
|
A command-line string to use as the shell\open\command
|
||||||
'''
|
'''
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
@ -32,7 +35,13 @@ from voussoirkit import betterhelp
|
||||||
from voussoirkit import interactive
|
from voussoirkit import interactive
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
|
|
||||||
def extension_registry(ico_file, extension=None, human_name=None):
|
def extension_registry(
|
||||||
|
ico_file,
|
||||||
|
extension=None,
|
||||||
|
human_name=None,
|
||||||
|
shellopen=None,
|
||||||
|
autoyes=False,
|
||||||
|
):
|
||||||
if ico_file.extension != 'ico':
|
if ico_file.extension != 'ico':
|
||||||
raise ValueError('Must provide a .ico file.')
|
raise ValueError('Must provide a .ico file.')
|
||||||
|
|
||||||
|
@ -52,9 +61,14 @@ def extension_registry(ico_file, extension=None, human_name=None):
|
||||||
if human_name:
|
if human_name:
|
||||||
prompt.append(f'Set {hash_ex} = {human_name}')
|
prompt.append(f'Set {hash_ex} = {human_name}')
|
||||||
|
|
||||||
|
if shellopen:
|
||||||
|
prompt.append(f'Set {hash_ex}\\shell\\open\\command = {shellopen}')
|
||||||
|
|
||||||
prompt = '\n'.join(prompt)
|
prompt = '\n'.join(prompt)
|
||||||
|
|
||||||
if not interactive.getpermission(prompt):
|
print(prompt)
|
||||||
|
|
||||||
|
if not autoyes and not interactive.getpermission('Okay?'):
|
||||||
return
|
return
|
||||||
|
|
||||||
dot_key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, dot_ex)
|
dot_key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, dot_ex)
|
||||||
|
@ -64,6 +78,10 @@ def extension_registry(ico_file, extension=None, human_name=None):
|
||||||
if human_name:
|
if human_name:
|
||||||
winreg.SetValueEx(hash_key, '', 0, winreg.REG_SZ, human_name)
|
winreg.SetValueEx(hash_key, '', 0, winreg.REG_SZ, human_name)
|
||||||
|
|
||||||
|
if shellopen:
|
||||||
|
command = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, f'{hash_ex}\\shell\\open\\command')
|
||||||
|
winreg.SetValueEx(command, '', 0, winreg.REG_SZ, shellopen)
|
||||||
|
|
||||||
icon_key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, f'{hash_ex}\\DefaultIcon')
|
icon_key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, f'{hash_ex}\\DefaultIcon')
|
||||||
winreg.SetValueEx(icon_key, '', 0, winreg.REG_SZ, ico_file.absolute_path)
|
winreg.SetValueEx(icon_key, '', 0, winreg.REG_SZ, ico_file.absolute_path)
|
||||||
|
|
||||||
|
@ -74,6 +92,8 @@ def extension_registry_argparse(args):
|
||||||
ico_file=pathclass.Path(args.ico_file),
|
ico_file=pathclass.Path(args.ico_file),
|
||||||
extension=args.extension,
|
extension=args.extension,
|
||||||
human_name=args.name,
|
human_name=args.name,
|
||||||
|
shellopen=args.shellopen,
|
||||||
|
autoyes=args.autoyes,
|
||||||
)
|
)
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
@ -82,6 +102,8 @@ def main(argv):
|
||||||
parser.add_argument('ico_file')
|
parser.add_argument('ico_file')
|
||||||
parser.add_argument('--extension', default=None)
|
parser.add_argument('--extension', default=None)
|
||||||
parser.add_argument('--name', default=None)
|
parser.add_argument('--name', default=None)
|
||||||
|
parser.add_argument('--shellopen', default=None)
|
||||||
|
parser.add_argument('--yes', dest='autoyes', action='store_true')
|
||||||
parser.set_defaults(func=extension_registry_argparse)
|
parser.set_defaults(func=extension_registry_argparse)
|
||||||
|
|
||||||
return betterhelp.single_main(argv, parser, __doc__)
|
return betterhelp.single_main(argv, parser, __doc__)
|
||||||
|
|
Loading…
Reference in a new issue