2019-12-08 22:43:49 +01:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
from bemani.format import IFS
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
parser = argparse.ArgumentParser(description="A utility to extract IFS files.")
|
|
|
|
parser.add_argument(
|
|
|
|
"file",
|
|
|
|
help="IFS file to extract.",
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-d",
|
|
|
|
"--directory",
|
|
|
|
help="Directory to extract to. Defaults to current directroy.",
|
|
|
|
default="."
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--convert-xml-files",
|
2021-04-14 03:08:13 +02:00
|
|
|
help="Convert xml files that are in binary to readable text.",
|
2019-12-08 22:43:49 +01:00
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--convert-texture-files",
|
2021-04-14 03:08:13 +02:00
|
|
|
help="Convert texture files that are in game-format to PNG files.",
|
2019-12-08 22:43:49 +01:00
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
root = args.directory
|
|
|
|
if root[-1] != '/':
|
|
|
|
root = root + '/'
|
|
|
|
root = os.path.realpath(root)
|
|
|
|
|
|
|
|
fp = open(args.file, 'rb')
|
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
ifs = IFS(data, args.convert_xml_files, args.convert_texture_files)
|
|
|
|
for fn in ifs.filenames:
|
2020-01-07 22:29:07 +01:00
|
|
|
print(f'Extracting {fn} to disk...')
|
2019-12-08 22:43:49 +01:00
|
|
|
realfn = os.path.join(root, fn)
|
|
|
|
dirof = os.path.dirname(realfn)
|
|
|
|
os.makedirs(dirof, exist_ok=True)
|
|
|
|
with open(realfn, 'wb') as fp:
|
|
|
|
fp.write(ifs.read_file(fn))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|