2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 21:07:42 +00:00

work on extract tool

This commit is contained in:
Jack Andersen
2015-07-09 19:28:33 -10:00
parent 81d8329f74
commit 45c593b596
6 changed files with 92 additions and 19 deletions

View File

@@ -6,15 +6,32 @@
class ToolExtract final : public ToolBase
{
HECL::Database::IDataSpec::ExtractPassInfo m_einfo;
std::vector<std::unique_ptr<HECL::Database::IDataSpec>> m_dataSpecs;
std::vector<HECL::Database::IDataSpec::ExtractReport> 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);
for (std::vector<HECL::SystemString>::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->canExtract(m_einfo, m_reps))
m_dataSpecs.emplace_back(ds);
else
delete ds;
}
}
@@ -47,8 +64,57 @@ public:
HECL::SystemString toolName() const {return _S("extract");}
static void _recursivePrint(int level, HECL::Database::IDataSpec::ExtractReport& rep)
{
for (int l=0 ; l<level ; ++l)
HECL::Printf(_S(" "));
if (XTERM_COLOR)
HECL::Printf(_S("" CYAN BOLD "%s" NORMAL "\n"), rep.name.c_str());
else
HECL::Printf(_S("%s\n"), rep.name.c_str());
for (int l=0 ; l<level ; ++l)
HECL::Printf(_S(" "));
HECL::Printf(_S(" %s\n"), rep.desc.c_str());
for (HECL::Database::IDataSpec::ExtractReport& child : rep.childOpts)
_recursivePrint(level + 1, child);
}
int run()
{
if (m_dataSpecs.empty())
{
if (XTERM_COLOR)
HECL::Printf(_S("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n"));
else
HECL::Printf(_S("NOTHING TO EXTRACT\n"));
return -1;
}
if (XTERM_COLOR)
HECL::Printf(_S("" GREEN BOLD "ABOUT TO EXTRACT:" NORMAL "\n"));
else
HECL::Printf(_S("ABOUT TO EXTRACT:\n"));
for (HECL::Database::IDataSpec::ExtractReport& rep : m_reps)
_recursivePrint(0, rep);
if (XTERM_COLOR)
HECL::Printf(_S("" BLUE BOLD "Continue?" NORMAL "(Y/N)"));
else
HECL::Printf(_S("Continue? (Y/N)"));
int ch;
while ((ch = getchar()))
{
if (ch == 'n' || ch == 'N')
return 0;
if (ch == 'y' || ch == 'Y')
break;
}
for (std::unique_ptr<HECL::Database::IDataSpec>& ds : m_dataSpecs)
ds->doExtract(*m_info.project, m_einfo);
return 0;
}
};