mirror of
https://github.com/notwa/mm
synced 2025-02-05 05:23:22 -08:00
add a proper argument parser
This commit is contained in:
parent
1d9da41651
commit
7437e47ea4
1 changed files with 35 additions and 26 deletions
61
z64dump.py
61
z64dump.py
|
@ -340,39 +340,48 @@ def create_rom(d, compression=None, nocomplist=None):
|
||||||
fix_rom(f)
|
fix_rom(f)
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
decompress = True
|
import argparse
|
||||||
compression = None
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="z64dump: construct and deconstruct Zelda N64 ROMs")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'path', metavar='ROM or folder', nargs='+',
|
||||||
|
help="ROM to deconstruct, or folder to construct")
|
||||||
|
parser.add_argument(
|
||||||
|
'-f', '--fix', action='store_true',
|
||||||
|
help="only update CIC checksums")
|
||||||
|
parser.add_argument(
|
||||||
|
'-D', '--no-decompress', action='store_true',
|
||||||
|
help="(deconstruction) leave compressed files compressed")
|
||||||
|
parser.add_argument(
|
||||||
|
'-C', '--no-compress', action='store_const', const=None, dest='compression',
|
||||||
|
help="(construction) do not compress files")
|
||||||
|
parser.add_argument(
|
||||||
|
'-y', '--yaz', action='store_const', const='yaz', dest='compression',
|
||||||
|
help="(construction) use yaz (Yaz0) compression")
|
||||||
|
parser.add_argument(
|
||||||
|
'-z', '--zlib', action='store_const', const='zlib', dest='compression',
|
||||||
|
help="(construction) use deflate (zlib) compression")
|
||||||
|
|
||||||
|
a = parser.parse_args(args)
|
||||||
|
|
||||||
nocomplist = None # file indices to skip compression on
|
nocomplist = None # file indices to skip compression on
|
||||||
fix = False
|
|
||||||
|
|
||||||
for arg in args:
|
for path in a.path:
|
||||||
if arg == '-f':
|
if a.fix:
|
||||||
fix = not fix
|
if os.path.isdir(path):
|
||||||
continue
|
lament("only ROM files are fixable:", path)
|
||||||
if arg == '-c':
|
else:
|
||||||
decompress = not decompress
|
with open(path, 'r+b') as f:
|
||||||
continue
|
fix_rom(f)
|
||||||
if arg == '-n':
|
|
||||||
compression = None
|
|
||||||
continue
|
|
||||||
if arg == '-y':
|
|
||||||
compression = 'yaz'
|
|
||||||
continue
|
|
||||||
if arg == '-z':
|
|
||||||
compression = 'zlib'
|
|
||||||
continue
|
|
||||||
|
|
||||||
path = arg
|
|
||||||
if fix:
|
|
||||||
with open(path, 'r+b') as f:
|
|
||||||
fix_rom(f)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# directories are technically files, so check this first
|
# directories are technically files, so check this first
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
create_rom(path, compression, nocomplist)
|
create_rom(path, a.compression, nocomplist)
|
||||||
elif os.path.isfile(path):
|
elif os.path.isfile(path):
|
||||||
dump_rom(path, decompress)
|
dump_rom(path, not a.no_decompress)
|
||||||
else:
|
else:
|
||||||
lament('no-op:', path)
|
lament('no-op:', path)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue