diff --git a/README.rst b/README.rst index 8968a5e..f2ffb69 100644 --- a/README.rst +++ b/README.rst @@ -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. diff --git a/rsrcfork/__main__.py b/rsrcfork/__main__.py index 773bc65..742ac45 100644 --- a/rsrcfork/__main__.py +++ b/rsrcfork/__main__.py @@ -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: