Warn user whenever specified asset type is unrecognized

This commit is contained in:
Jan 2022-04-16 17:13:28 +02:00
parent 2108737f22
commit 6e57834dc6
3 changed files with 51 additions and 4 deletions

View File

@ -216,15 +216,49 @@ class Unlinker::Impl
ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector<bool>(assetTypeCount); ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector<bool>(assetTypeCount);
std::vector<bool> handledSpecifiedAssets(m_args.m_specified_asset_types.size());
for (auto i = 0; i < assetTypeCount; i++) for (auto i = 0; i < assetTypeCount; i++)
{ {
const auto assetTypeName = std::string(context.m_zone->m_pools->GetAssetTypeName(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; ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::INCLUDE;
assert(foundSpecifiedEntry->second < handledSpecifiedAssets.size());
handledSpecifiedAssets[foundSpecifiedEntry->second] = true;
}
else else
ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::EXCLUDE; 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";
}
} }
/** /**

View File

@ -197,6 +197,16 @@ bool UnlinkerArgs::SetModelDumpingMode()
return false; 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) void UnlinkerArgs::ParseCommaSeparatedAssetTypeString(const std::string& input)
{ {
auto currentPos = 0u; 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) 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; currentPos = endPos + 1;
} }
if (currentPos < lowerInput.size()) 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) bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)

View File

@ -3,6 +3,7 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <string> #include <string>
#include <unordered_map>
#include "Utils/Arguments/ArgumentParser.h" #include "Utils/Arguments/ArgumentParser.h"
#include "Zone/Zone.h" #include "Zone/Zone.h"
@ -25,6 +26,7 @@ private:
bool SetImageDumpingMode(); bool SetImageDumpingMode();
bool SetModelDumpingMode(); bool SetModelDumpingMode();
void AddSpecifiedAssetType(std::string value);
void ParseCommaSeparatedAssetTypeString(const std::string& input); void ParseCommaSeparatedAssetTypeString(const std::string& input);
public: public:
@ -48,7 +50,8 @@ public:
std::string m_output_folder; std::string m_output_folder;
bool m_minimal_zone_def; bool m_minimal_zone_def;
std::set<std::string> m_specified_asset_types; std::vector<std::string> m_specified_asset_types;
std::unordered_map<std::string, size_t> m_specified_asset_type_map;
AssetTypeHandling m_asset_type_handling; AssetTypeHandling m_asset_type_handling;
bool m_use_gdt; bool m_use_gdt;