Improve errors when filter doesn't match required number of resources

This commit is contained in:
dgelessus 2019-08-31 14:48:01 +02:00
parent acdbbc89b2
commit c4fe09dbf0
2 changed files with 14 additions and 2 deletions

View File

@ -144,6 +144,8 @@ Version 1.2.0 (next version)
* This fixes reading certain system files with resource data in their data fork (such as HIToolbox.rsrc in HIToolbox.framework, or .dfont fonts) on recent macOS versions (at least macOS 10.14, possibly earlier). Although these files have no resource fork, recent macOS versions will successfully open the resource fork and return garbage data for it. This behavior is now detected and handled by using the data fork instead.
* Added an explanatory message when a resource filter on the command line doesn't match any resources in the resource file. Previously there would either be no output or a confusing error, depending on the selected ``--format``.
* Improved error messages when attempting to read multiple resources using ``--format=hex`` or ``--format=raw``.
* Fixed reading from non-seekable streams not working for some resource files.
* Removed the ``allow_seek`` parameter of ``ResourceFork.__init__`` and the ``--read-mode`` command line option. They are no longer necessary, and were already practically useless before due to non-seekable stream reading being broken.

View File

@ -233,8 +233,18 @@ def main():
for reses in rf.values():
resources.extend(reses.values())
if ns.format in ("hex", "raw") and len(resources) != 1:
print(f"Format {ns.format} only supports exactly one resource, but found {len(resources)}", file=sys.stderr)
if not resources:
if ns.format == "dump":
print("No resources matched the filter")
elif ns.format in ("hex", "raw"):
print("No resources matched the filter", file=sys.stderr)
sys.exit(1)
elif ns.format == "derez":
print("/* No resources matched the filter */")
else:
raise AssertionError(f"Unhandled output format: {ns.format}")
elif ns.format in ("hex", "raw") and len(resources) != 1:
print(f"Format {ns.format} can only output a single resource, but the filter matched {len(resources)} resources", file=sys.stderr)
sys.exit(1)
for res in resources: