From 6e57834dc6e7fd577cb42414b4813a80b6515cd1 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 16 Apr 2022 17:13:28 +0200 Subject: [PATCH] Warn user whenever specified asset type is unrecognized --- src/Unlinker/Unlinker.cpp | 36 ++++++++++++++++++++++++++++++++++- src/Unlinker/UnlinkerArgs.cpp | 14 ++++++++++++-- src/Unlinker/UnlinkerArgs.h | 5 ++++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/Unlinker/Unlinker.cpp b/src/Unlinker/Unlinker.cpp index a3d315a7..9b286467 100644 --- a/src/Unlinker/Unlinker.cpp +++ b/src/Unlinker/Unlinker.cpp @@ -216,15 +216,49 @@ class Unlinker::Impl ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector(assetTypeCount); + std::vector handledSpecifiedAssets(m_args.m_specified_asset_types.size()); for (auto i = 0; i < assetTypeCount; i++) { const auto assetTypeName = std::string(context.m_zone->m_pools->GetAssetTypeName(i)); - if (m_args.m_specified_asset_types.find(assetTypeName) != m_args.m_specified_asset_types.end()) + const auto foundSpecifiedEntry = m_args.m_specified_asset_type_map.find(assetTypeName); + if (foundSpecifiedEntry != m_args.m_specified_asset_type_map.end()) + { ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::INCLUDE; + assert(foundSpecifiedEntry->second < handledSpecifiedAssets.size()); + handledSpecifiedAssets[foundSpecifiedEntry->second] = true; + } else ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::EXCLUDE; } + + auto anySpecifiedValueInvalid = false; + for (auto i = 0u; i < handledSpecifiedAssets.size(); i++) + { + if (!handledSpecifiedAssets[i]) + { + std::cerr << "Unknown asset type \"" << m_args.m_specified_asset_types[i] << "\"\n"; + anySpecifiedValueInvalid = true; + } + } + + if (anySpecifiedValueInvalid) + { + std::cerr << "Valid asset types are:\n"; + + auto first = true; + for (auto i = 0; i < assetTypeCount; i++) + { + const auto assetTypeName = std::string(context.m_zone->m_pools->GetAssetTypeName(i)); + + if (first) + first = false; + else + std::cerr << ", "; + std::cerr << assetTypeName; + } + std::cerr << "\n"; + } } /** diff --git a/src/Unlinker/UnlinkerArgs.cpp b/src/Unlinker/UnlinkerArgs.cpp index 38062b81..558b7bc6 100644 --- a/src/Unlinker/UnlinkerArgs.cpp +++ b/src/Unlinker/UnlinkerArgs.cpp @@ -197,6 +197,16 @@ bool UnlinkerArgs::SetModelDumpingMode() return false; } +void UnlinkerArgs::AddSpecifiedAssetType(std::string value) +{ + const auto alreadySpecifiedAssetType = m_specified_asset_type_map.find(value); + if (alreadySpecifiedAssetType == m_specified_asset_type_map.end()) + { + m_specified_asset_type_map.emplace(std::make_pair(value, m_specified_asset_types.size())); + m_specified_asset_types.emplace_back(std::move(value)); + } +} + void UnlinkerArgs::ParseCommaSeparatedAssetTypeString(const std::string& input) { auto currentPos = 0u; @@ -208,12 +218,12 @@ void UnlinkerArgs::ParseCommaSeparatedAssetTypeString(const std::string& input) while (currentPos < lowerInput.size() && (endPos = lowerInput.find_first_of(',', currentPos)) != std::string::npos) { - m_specified_asset_types.emplace(lowerInput, currentPos, endPos - currentPos); + AddSpecifiedAssetType(std::string(lowerInput, currentPos, endPos - currentPos)); currentPos = endPos + 1; } if (currentPos < lowerInput.size()) - m_specified_asset_types.emplace(lowerInput, currentPos, lowerInput.size() - currentPos); + AddSpecifiedAssetType(std::string(lowerInput, currentPos, lowerInput.size() - currentPos)); } bool UnlinkerArgs::ParseArgs(const int argc, const char** argv) diff --git a/src/Unlinker/UnlinkerArgs.h b/src/Unlinker/UnlinkerArgs.h index f02166b4..3bc272ca 100644 --- a/src/Unlinker/UnlinkerArgs.h +++ b/src/Unlinker/UnlinkerArgs.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "Utils/Arguments/ArgumentParser.h" #include "Zone/Zone.h" @@ -25,6 +26,7 @@ private: bool SetImageDumpingMode(); bool SetModelDumpingMode(); + void AddSpecifiedAssetType(std::string value); void ParseCommaSeparatedAssetTypeString(const std::string& input); public: @@ -48,7 +50,8 @@ public: std::string m_output_folder; bool m_minimal_zone_def; - std::set m_specified_asset_types; + std::vector m_specified_asset_types; + std::unordered_map m_specified_asset_type_map; AssetTypeHandling m_asset_type_handling; bool m_use_gdt;