-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (60 loc) · 1.91 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Binary file exporter/importer for Monster Hunter Frontier.
Files need to be decrypted and decompressed with a tool like ReFrontier.
"""
import argparse
import os
import src
def parse_inputs():
"""Parse console arguments."""
parser = argparse.ArgumentParser(
prog="FrontierTextConverter",
description="Converts strings from Monster Hunter Frontier "
+ "between ReFrontier and other formats.",
)
parser.add_argument(
"input_file", type=str, default="data/mhfdat.bin", nargs="?", help="Input file."
)
parser.add_argument(
"output_file",
type=str,
default="output/minimal.csv",
nargs="?",
help="Output file name.",
)
parser.add_argument(
"--xpath",
type=str,
default="dat/armors/head",
required=False,
help="Which data to get, as an xpath. "
+ "For instance 'dat/armors/head' to read from mhfDAT.bin ARMORS HELMETS",
)
parser.add_argument(
"--refrontier-to-csv",
action="store_true",
help="Convert from ReFrontier format (TSV, Shift-JIS) to CSV format.",
)
parser.add_argument(
"--csv-to-bin",
action="store_true",
help="Convert from a CSV file (UTF-8) to your binary file.",
)
return parser
def main(args):
"""Main function to read everything."""
if not os.path.exists(args.input_file):
raise FileNotFoundError(
f"'{args.input_file}' does not exist. You need to import it first."
)
if args.refrontier_to_csv:
src.refrontier_to_csv(args.input_file, args.output_file)
elif args.csv_to_bin:
src.import_from_csv(args.input_file, args.output_file)
else:
# Default: read and save as CSV
src.extract_from_file(
args.input_file, args.xpath, args.output_file
)
if __name__ == "__main__":
main(parse_inputs().parse_args())