mirror of
https://github.com/NinjaCheetah/WiiPy.git
synced 2026-02-17 02:25:39 -05:00
Rewrote error output to be much clearer, no longer raises Python exceptions
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
import pathlib
|
||||
import libWiiPy
|
||||
from modules.core import fatal_error
|
||||
|
||||
|
||||
def handle_ash_compress(args):
|
||||
@@ -21,7 +22,7 @@ def handle_ash_decompress(args):
|
||||
dist_tree_bits = args.dist_bits
|
||||
|
||||
if not input_path.exists():
|
||||
raise FileNotFoundError(input_path)
|
||||
fatal_error(f"The specified ASH file \"{input_path}\" does not exist!")
|
||||
|
||||
ash_data = input_path.read_bytes()
|
||||
# Decompress ASH file using the provided symbol/distance tree widths.
|
||||
|
||||
@@ -7,6 +7,7 @@ import shutil
|
||||
import tempfile
|
||||
import zipfile
|
||||
import libWiiPy
|
||||
from modules.core import fatal_error
|
||||
|
||||
|
||||
def handle_apply_mym(args):
|
||||
@@ -15,9 +16,9 @@ def handle_apply_mym(args):
|
||||
output_path = pathlib.Path(args.output)
|
||||
|
||||
if not mym_path.exists():
|
||||
raise FileNotFoundError(mym_path)
|
||||
fatal_error(f"The specified MYM file \"{mym_path}\" does not exist!")
|
||||
if not base_path.exists():
|
||||
raise FileNotFoundError(base_path)
|
||||
fatal_error(f"The specified base file \"{base_path}\" does not exist!")
|
||||
if output_path.suffix != ".csm":
|
||||
output_path = output_path.with_suffix(".csm")
|
||||
|
||||
@@ -29,21 +30,18 @@ def handle_apply_mym(args):
|
||||
with zipfile.ZipFile(mym_path) as mym:
|
||||
mym.extractall(tmp_path.joinpath("mym_out"))
|
||||
except zipfile.BadZipfile:
|
||||
print("Error: The provided MYM theme is not valid!")
|
||||
exit(1)
|
||||
fatal_error("The provided MYM theme is not valid!")
|
||||
mym_tmp_path = pathlib.Path(tmp_path.joinpath("mym_out"))
|
||||
# Extract the asset archive into the temp directory.
|
||||
try:
|
||||
libWiiPy.archive.extract_u8(base_path.read_bytes(), str(tmp_path.joinpath("base_out")))
|
||||
except ValueError:
|
||||
print("Error: The provided base assets are not valid!")
|
||||
exit(1)
|
||||
fatal_error("The provided base assets are not valid!")
|
||||
base_temp_path = pathlib.Path(tmp_path.joinpath("base_out"))
|
||||
# Parse the mym.ini file in the root of the extracted MYM file.
|
||||
mym_ini = configparser.ConfigParser()
|
||||
if not mym_tmp_path.joinpath("mym.ini").exists():
|
||||
print("Error: mym.ini could not be found! The provided theme is not valid.")
|
||||
exit(1)
|
||||
fatal_error("mym.ini could not be found in the theme! The provided theme is not valid.")
|
||||
mym_ini.read(mym_tmp_path.joinpath("mym.ini"))
|
||||
# Iterate over every key in the ini file and apply the theme based the source and target of each key.
|
||||
for section in mym_ini.sections():
|
||||
@@ -53,9 +51,8 @@ def handle_apply_mym(args):
|
||||
source_file = source_file.joinpath(piece)
|
||||
# Check that this source file is actually valid, and error out if it isn't.
|
||||
if not source_file.exists():
|
||||
print(f"Error: A source file specified in mym.ini, \"{mym_ini[section]['source']}\", does not exist! "
|
||||
f"The provided theme is not valid.")
|
||||
exit(1)
|
||||
fatal_error(f"A source file specified in mym.ini, \"{mym_ini[section]['source']}\", does not exist! "
|
||||
f"The provided theme is not valid.")
|
||||
# Build the target path the same way.
|
||||
target_file = base_temp_path
|
||||
for piece in mym_ini[section]["file"].replace("\\", "/").split("/"):
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import pathlib
|
||||
import libWiiPy
|
||||
from modules.core import fatal_error
|
||||
|
||||
|
||||
def handle_u8_pack(args):
|
||||
@@ -12,8 +13,7 @@ def handle_u8_pack(args):
|
||||
try:
|
||||
u8_data = libWiiPy.archive.pack_u8(input_path)
|
||||
except ValueError:
|
||||
print("Error: Specified input file/folder does not exist!")
|
||||
return
|
||||
fatal_error(f"The specified input file/folder \"{input_path}\" does not exist!")
|
||||
|
||||
out_file = open(output_path, "wb")
|
||||
out_file.write(u8_data)
|
||||
@@ -27,7 +27,7 @@ def handle_u8_unpack(args):
|
||||
output_path = pathlib.Path(args.output)
|
||||
|
||||
if not input_path.exists():
|
||||
raise FileNotFoundError(args.input)
|
||||
fatal_error(f"The specified input file \"{input_path}\" does not exist!")
|
||||
|
||||
u8_data = open(input_path, "rb").read()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user