Warn if the NRO has no icon instead of crashing

This commit is contained in:
rlaphoenix
2022-11-13 06:12:20 +00:00
parent 7508f9ed14
commit 873e0e8faa
+23 -18
View File
@@ -264,25 +264,30 @@ def build(
else: else:
icon_file_res = nstool.get_icon(path, icon_file) icon_file_res = nstool.get_icon(path, icon_file)
if icon_file_res: if icon_file_res:
log.critical(f"Failed extracting the Icon partition from the NRO, {icon_file_res}") if icon_file_res == "No Icon was extracted from the asset.":
sys.exit(2) log.warning("The NRO does not have an Icon, proceeding without one.")
log.debug("Got the Icon partition") else:
log.debug(base64.b64encode(icon_file.read_bytes()).decode()) log.critical(f"Failed extracting the Icon partition from the NRO, {icon_file_res}")
sys.exit(2)
else:
log.debug("Got the Icon partition")
log.debug(base64.b64encode(icon_file.read_bytes()).decode())
# We must strip every unnecessary metadata or the icon will be a '?' if icon_file.exists():
try: # We must strip every unnecessary metadata or the icon will be a '?'
subprocess.check_output([ try:
Binaries.magick, "mogrify", subprocess.check_output([
"-format", "jpg", Binaries.magick, "mogrify",
"-resize", "256x256", "-format", "jpg",
"-strip", str(icon_file.absolute()) "-resize", "256x256",
]) "-strip", str(icon_file.absolute())
# magick changes the .dat to .jpg, let's undo that ])
icon_file.unlink() # magick changes the .dat to .jpg, let's undo that
shutil.move(icon_file.with_suffix(".jpg"), icon_file) icon_file.unlink()
except subprocess.CalledProcessError as e: shutil.move(icon_file.with_suffix(".jpg"), icon_file)
log.critical(f"Failed to convert and strip the Icon, {e.output} [{e.returncode}]") except subprocess.CalledProcessError as e:
sys.exit(2) log.critical(f"Failed to convert and strip the Icon, {e.output} [{e.returncode}]")
sys.exit(2)
next_nro_path = sdmc next_nro_path = sdmc
next_nro_path_file.write_text(next_nro_path) next_nro_path_file.write_text(next_nro_path)