diff --git a/src/cli/action_convert.cpp b/src/cli/action_convert.cpp index c5707be..693530b 100644 --- a/src/cli/action_convert.cpp +++ b/src/cli/action_convert.cpp @@ -46,6 +46,7 @@ namespace opts static int width, height; static int nomips; static int toDX; + static int quiet; } // namespace opts static bool get_version_from_str(const std::string& str, int& major, int& minor); @@ -226,6 +227,15 @@ const OptionList& ActionConvert::get_options() const { .value(false) .type(OptType::Bool) .help("Treat the incoming normal map as an OpenGL normal map")); + + opts::quiet = opts.add( + ActionOption() + .long_opt("--quiet") + .short_opt("-q") + .value(false) + .type(OptType::Bool) + .help("Silence output messages that aren't errors") + ); }; return opts; } @@ -398,12 +408,14 @@ bool ActionConvert::process_file( } // Report file sizes - if (initialSize != 0) { - fmt::print( - "{} ({} bytes) -> {} ({} bytes)\n", srcFile.string(), initialSize, outFile.string(), vtfFile->GetSize()); - } - else { - fmt::print("{} -> {} ({} bytes)\n", srcFile.string(), outFile.string(), vtfFile->GetSize()); + if (!opts.get(opts::quiet)) { + if (initialSize != 0) { + fmt::print( + "{} ({} KiB) -> {} ({} KiB)\n", srcFile.string(), initialSize / 1024, outFile.string(), vtfFile->GetSize() / 1024); + } + else { + fmt::print("{} -> {} ({} KiB)\n", srcFile.string(), outFile.string(), vtfFile->GetSize() / 1024); + } } return true; @@ -524,7 +536,7 @@ bool ActionConvert::add_image_data( // Hack for VTFLib; Ensure we have an alpha channel because that's well supported in that horrible code if (image->channels() < 4 && image->type() != imglib::ChannelType::UInt8) { if (!image->convert(image->type(), 4)) { - std::cerr << fmt::format("Failed to convert {}\n", imageSrc.c_str()); + std::cerr << fmt::format("Failed to convert {}\n", imageSrc.string()); return false; } } diff --git a/src/cli/action_extract.cpp b/src/cli/action_extract.cpp index 0511e81..3057af5 100644 --- a/src/cli/action_extract.cpp +++ b/src/cli/action_extract.cpp @@ -24,6 +24,7 @@ namespace opts static int mip; static int recursive; static int noalpha; + static int quiet; } // namespace opts std::string ActionExtract::get_help() const { @@ -82,6 +83,15 @@ const OptionList& ActionExtract::get_options() const { .type(OptType::Bool) .value(false) .help("Exclude alpha channel from converted image")); + + opts::quiet = opts.add( + ActionOption() + .short_opt("-q") + .long_opt("--quiet") + .type(OptType::Bool) + .value(false) + .help("Silence output messages that aren't errors") + ); }; return opts; } @@ -152,7 +162,8 @@ bool ActionExtract::extract_file( outFile = vtfPath.parent_path() / vtfPath.filename().replace_extension(ext); } - fmt::print("{} -> {}\n", vtfPath.string(), outFile.string()); + if (!opts.get(opts::quiet)) + fmt::print("{} -> {}\n", vtfPath.string(), outFile.string()); // Validate mipmap selection if (mip > file_->GetMipmapCount()) { diff --git a/src/cli/action_pack.cpp b/src/cli/action_pack.cpp index 4f0fcc6..0f7d699 100644 --- a/src/cli/action_pack.cpp +++ b/src/cli/action_pack.cpp @@ -30,6 +30,7 @@ namespace opts static int width, height, mips; static int mconst, rconst, aoconst, hconst; static int toDX; + static int quiet; } // namespace opts std::string ActionPack::get_help() const { @@ -176,6 +177,15 @@ const OptionList& ActionPack::get_options() const { .value(false) .type(OptType::Bool) .help("Treat the incoming normal map as a OpenGL normal map")); + + opts::quiet = opts.add( + ActionOption() + .long_opt("--quiet") + .short_opt("-q") + .value(false) + .type(OptType::Bool) + .help("Silence output messages that aren't errors") + ); }; return opts; } @@ -467,8 +477,8 @@ bool ActionPack::pack_normal( success = save_vtf(outpath, outImage, opts, true); - if (success) - std::cout << fmt::format("Finished processing {}\n", outpath.string()); + if (success && !opts.get(opts::quiet)) + std::cout << fmt::format("Finished {} ({} KiB)\n", outpath.string(), file_->GetSize() / 1024); return success; }