2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-30 08:11:49 +00:00

Include and exclude asset type dumping configured by command line args

This commit is contained in:
Jan
2021-10-11 18:47:53 +02:00
parent e70cbaa4ce
commit 868bd070d0
21 changed files with 476 additions and 576 deletions

View File

@ -210,6 +210,23 @@ class Unlinker::Impl
return true;
}
void UpdateAssetIncludesAndExcludes(const AssetDumpingContext& context) const
{
const auto assetTypeCount = context.m_zone->m_pools->GetAssetTypeCount();
ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector<bool>(assetTypeCount);
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())
ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::INCLUDE;
else
ObjWriting::Configuration.AssetTypesToHandleBitfield[i] = m_args.m_asset_type_handling == UnlinkerArgs::AssetTypeHandling::EXCLUDE;
}
}
/**
* \brief Performs the tasks specified by the command line arguments on the specified zone.
* \param zone The zone to handle.
@ -249,6 +266,7 @@ class Unlinker::Impl
context.m_gdt = std::move(gdt);
}
UpdateAssetIncludesAndExcludes(context);
ObjWriting::DumpZone(context);
if (m_args.m_use_gdt)

View File

@ -79,6 +79,22 @@ const CommandLineOption* const OPTION_GDT =
.WithDescription("Dumps assets in a GDT whenever possible.")
.Build();
const CommandLineOption* const OPTION_EXCLUDE_ASSETS =
CommandLineOption::Builder::Create()
.WithLongName("exclude-assets")
.WithDescription("Specify all asset types that should be excluded.")
.WithParameter("assetTypeList")
.Reusable()
.Build();
const CommandLineOption* const OPTION_INCLUDE_ASSETS =
CommandLineOption::Builder::Create()
.WithLongName("include-assets")
.WithDescription("Specify all asset types that should be included.")
.WithParameter("assetTypeList")
.Reusable()
.Build();
const CommandLineOption* const COMMAND_LINE_OPTIONS[]
{
OPTION_HELP,
@ -90,7 +106,9 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]
OPTION_SEARCH_PATH,
OPTION_IMAGE_FORMAT,
OPTION_MODEL_FORMAT,
OPTION_GDT
OPTION_GDT,
OPTION_EXCLUDE_ASSETS,
OPTION_INCLUDE_ASSETS
};
UnlinkerArgs::UnlinkerArgs()
@ -98,6 +116,7 @@ UnlinkerArgs::UnlinkerArgs()
m_zone_pattern(R"(\?zone\?)"),
m_task(ProcessingTask::DUMP),
m_minimal_zone_def(false),
m_asset_type_handling(AssetTypeHandling::EXCLUDE),
m_use_gdt(false),
m_verbose(false)
{
@ -171,6 +190,25 @@ bool UnlinkerArgs::SetModelDumpingMode()
return false;
}
void UnlinkerArgs::ParseCommaSeparatedAssetTypeString(const std::string& input)
{
auto currentPos = 0u;
size_t endPos;
std::string lowerInput(input);
for (auto& c : lowerInput)
c = static_cast<char>(tolower(c));
while (currentPos < lowerInput.size() && (endPos = lowerInput.find_first_of(',', currentPos)) != std::string::npos)
{
m_specified_asset_types.emplace(lowerInput, currentPos, endPos - currentPos);
currentPos = endPos + 1;
}
if (currentPos < lowerInput.size())
m_specified_asset_types.emplace(lowerInput, currentPos, lowerInput.size() - currentPos);
}
bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
{
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
@ -246,6 +284,27 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
// --gdt
m_use_gdt = m_argument_parser.IsOptionSpecified(OPTION_GDT);
// --exclude-assets
// --include-assets
if (m_argument_parser.IsOptionSpecified(OPTION_EXCLUDE_ASSETS) && m_argument_parser.IsOptionSpecified(OPTION_INCLUDE_ASSETS))
{
std::cout << "You can only asset types to either exclude or include, not both\n";
return false;
}
if (m_argument_parser.IsOptionSpecified(OPTION_EXCLUDE_ASSETS))
{
m_asset_type_handling = AssetTypeHandling::EXCLUDE;
for (const auto& exclude : m_argument_parser.GetParametersForOption(OPTION_EXCLUDE_ASSETS))
ParseCommaSeparatedAssetTypeString(exclude);
}
else if (m_argument_parser.IsOptionSpecified(OPTION_INCLUDE_ASSETS))
{
m_asset_type_handling = AssetTypeHandling::INCLUDE;
for (const auto& include : m_argument_parser.GetParametersForOption(OPTION_INCLUDE_ASSETS))
ParseCommaSeparatedAssetTypeString(include);
}
return true;
}

View File

@ -2,6 +2,7 @@
#include <regex>
#include <set>
#include <vector>
#include <string>
#include "Utils/Arguments/ArgumentParser.h"
#include "Zone/Zone.h"
@ -24,6 +25,8 @@ private:
bool SetImageDumpingMode();
bool SetModelDumpingMode();
void ParseCommaSeparatedAssetTypeString(const std::string& input);
public:
enum class ProcessingTask
{
@ -31,6 +34,12 @@ public:
LIST
};
enum class AssetTypeHandling
{
EXCLUDE,
INCLUDE
};
std::vector<std::string> m_zones_to_load;
std::vector<std::string> m_zones_to_unlink;
std::set<std::string> m_user_search_paths;
@ -39,6 +48,9 @@ public:
std::string m_output_folder;
bool m_minimal_zone_def;
std::set<std::string> m_specified_asset_types;
AssetTypeHandling m_asset_type_handling;
bool m_use_gdt;
bool m_verbose;