From 5d558e7bedeff2e47301fde812a1a7364579b632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 11 Dec 2021 18:59:41 +0100 Subject: [PATCH] imageconverter: deduplicate file opening code paths. --- src/Magnum/Trade/imageconverter.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Magnum/Trade/imageconverter.cpp b/src/Magnum/Trade/imageconverter.cpp index a122d38fc..2f5786abb 100644 --- a/src/Magnum/Trade/imageconverter.cpp +++ b/src/Magnum/Trade/imageconverter.cpp @@ -420,16 +420,17 @@ key=true; configuration subgroups are delimited with /.)") if(args.isSet("verbose")) importer->addFlags(Trade::ImporterFlag::Verbose); Implementation::setOptions(*importer, "AnyImageImporter", args.value("importer-options")); + /* Open input file */ + if(!importer->openFile(input)) { + Error{} << "Cannot open file" << input; + return 3; + } + /* Print image info, if requested. This is always done for just one file, checked above. */ if(args.isSet("info")) { - /* Open the file, but don't fail when an image can't be - opened */ - if(!importer->openFile(input)) { - Error() << "Cannot open file" << input; - return 3; - } - + /* Don't fail when there's no image -- we could be asking for + info on a scene file without images, after all */ if(!importer->image1DCount() && !importer->image2DCount() && !importer->image3DCount()) { Debug{} << "No images found in" << input; return 0; @@ -464,12 +465,6 @@ key=true; configuration subgroups are delimited with /.)") return error ? 1 : 0; } - /* Open input file */ - if(!importer->openFile(input)) { - Error{} << "Cannot open file" << input; - return 3; - } - /* Bail early if there's no image whatsoever. More detailed errors with hints are provided for each dimension below. */ if(!importer->image1DCount() && !importer->image2DCount() && !importer->image3DCount()) {