2022-06-30 20:17:06 -04:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import pprint
|
|
|
|
import sys
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser("update-env")
|
|
|
|
parser.add_argument("--game", help="The name of the game", type=str)
|
|
|
|
parser.add_argument("--decomp_config", help="The decompiler config file", type=str)
|
2022-08-05 17:39:32 -04:00
|
|
|
parser.add_argument("--info", help="Just print out current settings", action='store_true')
|
2022-06-30 20:17:06 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# TODO - read from defaults
|
|
|
|
file = {
|
|
|
|
"GAME": "jak1",
|
|
|
|
"DECOMP_CONFIG": "jak1_ntsc_black_label.jsonc"
|
|
|
|
}
|
|
|
|
|
|
|
|
env_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), ".env")
|
|
|
|
|
|
|
|
if not os.path.exists(env_path):
|
|
|
|
with open(env_path, 'w') as env_file:
|
|
|
|
for item in file.items():
|
|
|
|
env_file.write("{}={}\n".format(item[0], item[1]))
|
|
|
|
|
|
|
|
with open(env_path, 'r') as env_file:
|
|
|
|
flags = env_file.readlines()
|
|
|
|
for flag in flags:
|
|
|
|
tokens = flag.split("=")
|
|
|
|
if tokens[0] in file:
|
|
|
|
file[tokens[0]] = tokens[1].strip()
|
|
|
|
|
2022-08-05 17:39:32 -04:00
|
|
|
if args.info:
|
|
|
|
print(file)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2022-06-30 20:17:06 -04:00
|
|
|
valid_games = ["jak1", "jak2"]
|
|
|
|
|
|
|
|
decomp_config_map = {
|
|
|
|
"jak1": {
|
|
|
|
"ntscv1": "jak1_ntsc_black_label.jsonc",
|
|
|
|
"ntscv2": "jak1_us2.jsonc",
|
|
|
|
"pal": "jak1_pal.jsonc",
|
|
|
|
"ntscjp": "jak1_jp.jsonc"
|
|
|
|
},
|
|
|
|
"jak2": {
|
|
|
|
"ntscv1": "jak2_ntsc_v1.jsonc"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 20:10:11 -04:00
|
|
|
default_config_map = {
|
|
|
|
"jak1": "jak1_ntsc_black_label.jsonc",
|
|
|
|
"jak2": "jak2_ntsc_v1.jsonc"
|
|
|
|
}
|
|
|
|
|
2022-06-30 20:17:06 -04:00
|
|
|
if args.game:
|
|
|
|
if args.game not in valid_games:
|
|
|
|
print("Unsupported game '{}'".format(args.game))
|
|
|
|
sys.exit(1)
|
2022-07-29 20:10:11 -04:00
|
|
|
curr = file["GAME"]
|
2022-06-30 20:17:06 -04:00
|
|
|
file["GAME"] = args.game
|
2022-07-29 20:10:11 -04:00
|
|
|
if (curr != file["GAME"]) or file["DECOMP_CONFIG"] not in decomp_config_map[file["GAME"]]:
|
|
|
|
file["DECOMP_CONFIG"] = default_config_map[file["GAME"]]
|
2022-06-30 20:17:06 -04:00
|
|
|
if args.decomp_config:
|
|
|
|
if args.decomp_config not in decomp_config_map[file["GAME"]]:
|
|
|
|
print("Unsupported decomp config '{}' for game '{}'".format(args.decomp_config, file["GAME"]))
|
|
|
|
sys.exit(1)
|
|
|
|
file["DECOMP_CONFIG"] = decomp_config_map[file["GAME"]][args.decomp_config]
|
|
|
|
|
|
|
|
with open(env_path, 'w') as env_file:
|
|
|
|
for item in file.items():
|
|
|
|
env_file.write("{}={}\n".format(item[0], item[1]))
|
|
|
|
|
|
|
|
print("Task settings updated")
|
|
|
|
pp = pprint.PrettyPrinter(indent=2)
|
|
|
|
pp.pprint(file)
|