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

@ -11,7 +11,14 @@ add_executable(hecl main.cpp
ToolRemove.hpp
ToolSpec.hpp
)
target_link_libraries(hecl HECL HECLDatabase
"-Wl,-whole-archive" RetroDataSpec "-Wl,-no-whole-archive"
AthenaCore NOD LogVisor blowfish z lzo2 pthread
list(APPEND DATA_SPEC_LIBS
RetroDataSpec
DNAMP1
DNAMP2
DNAMP3)
target_link_libraries(hecl
"-Wl,-whole-archive" ${DATA_SPEC_LIBS} "-Wl,-no-whole-archive"
HECL HECLDatabase AthenaCore NOD LogVisor blowfish z lzo2 pthread
)

View File

@ -38,6 +38,9 @@ public:
#define RED "\033[0;31m"
#define GREEN "\033[0;32m"
#define YELLOW "\033[0;33m"
#define BLUE "\033[0;34m"
#define MAGENTA "\033[0;35m"
#define CYAN "\033[0;36m"
#define BOLD "\033[1m"
#define NORMAL "\033[0m"

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;
}
};

@ -1 +1 @@
Subproject commit fc6b61a63ee30ad3aa6a6cecb3848732b514e54b
Subproject commit 043af55580d26a8faab8007c73217c26c19c4cf8

View File

@ -70,26 +70,24 @@ public:
*/
struct ExtractPassInfo
{
SystemString srcpath;
ProjectPath subpath;
bool cookedonly;
const SystemString* srcpath;
std::vector<const SystemString*> extractArgs;
};
/**
* @brief Interactive Extract Option
* @brief Extract Report Representation
*
* Constructed by canExtract() to solicit the user for game-specific
* extraction options (i.e. games that are gathered into a trilogy collection)
* Constructed by canExtract() to advise the user of the content about
* to be extracted
*/
struct ExtractOption
struct ExtractReport
{
SystemString name;
SystemString desc;
bool defVal;
std::vector<ExtractOption> childOpts;
std::vector<ExtractReport> childOpts;
};
virtual bool canExtract(const ExtractPassInfo& info, std::vector<ExtractOption>& opts)
virtual bool canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
{(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}
virtual void doExtract(const Project& project, const ExtractPassInfo& info)
{(void)project;(void)info;}

View File

@ -207,20 +207,19 @@ Project::Project(const ProjectRootPath& rootPath)
FILE* bf = HECL::Fopen((m_rootPath.getAbsolutePath() + _S("/.hecl/beacon")).c_str(), _S("a+b"));
struct BeaconStruct
{
FourCC magic;
uint32_t magic;
uint32_t version;
} beacon;
#define DATA_VERSION 1
static const FourCC hecl("HECL");
if (fread(&beacon, 1, sizeof(beacon), bf) != sizeof(beacon))
{
fseek(bf, 0, SEEK_SET);
beacon.magic = hecl;
beacon.magic = SBig('HECL');
beacon.version = SBig(DATA_VERSION);
fwrite(&beacon, 1, sizeof(beacon), bf);
}
fclose(bf);
if (beacon.magic != hecl ||
if (beacon.magic != SBig('HECL') ||
SBig(beacon.version) != DATA_VERSION)
{
LogModule.report(LogVisor::FatalError, "incompatible project version");