#ifndef CTOOL_EXTRACT #define CTOOL_EXTRACT #include "ToolBase.hpp" #include class ToolExtract final : public ToolBase { HECL::Database::IDataSpec::ExtractPassInfo m_einfo; struct SpecExtractPass { const HECL::Database::DataSpecEntry* m_entry; std::unique_ptr m_instance; SpecExtractPass(const HECL::Database::DataSpecEntry* entry, HECL::Database::IDataSpec* instance) : m_entry(entry), m_instance(instance) {} SpecExtractPass(const SpecExtractPass& other) = delete; SpecExtractPass(SpecExtractPass&& other) = default; }; std::vector m_specPasses; std::vector m_reps; public: ToolExtract(const ToolPassInfo& info) : ToolBase(info) { if (!info.project) LogModule.report(LogVisor::FatalError, "hecl extract must be ran within a project directory"); if (!m_info.args.size()) LogModule.report(LogVisor::FatalError, "hecl extract needs a source path as its first argument"); m_einfo.srcpath = m_info.args[0]; m_einfo.extractArgs.reserve(info.args.size() - 1); m_einfo.force = info.force; for (std::vector::const_iterator it=info.args.begin() + 1; it != info.args.end(); ++it) m_einfo.extractArgs.push_back(*it); for (const HECL::Database::DataSpecEntry* entry : HECL::Database::DATA_SPEC_REGISTRY) { HECL::Database::IDataSpec* ds = entry->m_factory(HECL::Database::TOOL_EXTRACT); if (ds) { if (ds->canExtract(*m_info.project, m_einfo, m_reps)) m_specPasses.emplace_back(entry, ds); else delete ds; } } } static void Help(HelpOutput& help) { help.secHead(_S("NAME")); help.beginWrap(); help.wrap(_S("hecl-extract - Extract objects from supported package/image formats\n")); help.endWrap(); help.secHead(_S("SYNOPSIS")); help.beginWrap(); help.wrap(_S("hecl extract [...]\n")); help.endWrap(); help.secHead(_S("DESCRIPTION")); help.beginWrap(); help.wrap(_S("This command recursively extracts all or part of a dataspec-supported ") _S("package format. Each object is decoded to a working format and added to the project.\n\n")); help.endWrap(); help.secHead(_S("OPTIONS")); help.optionHead(_S("[/...]"), _S("input file")); help.beginWrap(); help.wrap(_S("Specifies the package file or disc image to source data from. ") _S("An optional subnode specifies a named hierarchical-node specific ") _S("to the game architecture (levels/areas).")); help.endWrap(); } HECL::SystemString toolName() const {return _S("extract");} static void _recursivePrint(int level, HECL::Database::IDataSpec::ExtractReport& rep) { for (int l=0 ; lm_name); #else if (XTERM_COLOR) HECL::Printf(_S("" MAGENTA BOLD "Using DataSpec %s:" NORMAL "\n"), ds.m_entry->m_name); else HECL::Printf(_S("Using DataSpec %s:\n"), ds.m_entry->m_name); #endif int lineIdx = 0; ds.m_instance->doExtract(*m_info.project, m_einfo, [&lineIdx](const HECL::SystemChar* message, int lidx, float factor) { #ifndef _WIN32 if (XTERM_COLOR) HECL::Printf(_S("" HIDE_CURSOR "")); #endif if (lidx > lineIdx) { HECL::Printf(_S("\n ")); lineIdx = lidx; } else HECL::Printf(_S(" ")); int width = HECL::ConsoleWidth(); int half = width / 2 - 2; size_t messageLen = HECL::StrLen(message); if (messageLen > half) HECL::Printf(_S("%.*s... "), half-3, message); else { HECL::Printf(_S("%s"), message); for (int i=half-messageLen ; i>=0 ; --i) HECL::Printf(_S(" ")); } #ifndef _WIN32 if (XTERM_COLOR) { size_t blocks = half - 7; size_t filled = blocks * factor; size_t rem = blocks - filled; HECL::Printf(_S("" BOLD "%3d%% ["), (int)(factor * 100.0)); for (int b=0 ; b