working file extractor; removed hard-coded paths

This commit is contained in:
Jack Andersen
2015-06-30 09:38:51 -10:00
parent 293b7c0ce6
commit a1b2a262bf
13 changed files with 194 additions and 100 deletions

View File

@@ -2,34 +2,53 @@
#include <string.h>
#include "NODLib.hpp"
static void printHelp()
{
fprintf(stderr, "Usage:\n"
" nodlib extract [-f] <image-in> [<dir-out>]\n"
" nodlib make <dir-in> [<image-out>]\n");
}
int main(int argc, char* argv[])
{
if (argc < 2)
if (argc < 3)
{
fprintf(stderr, "Usage: nodlib <image-in>\n");
printHelp();
return -1;
}
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(argv[1]);
if (!disc)
return -1;
disc->extractToDirectory("/home/jacko/Desktop/TrilogyDump2");
const NOD::DiscBase::IPartition* dataPart = disc->getDataPartition();
if (dataPart)
const char* inDir = nullptr;
const char* outDir = ".";
bool force = false;
for (int a=2 ; a<argc ; ++a)
{
for (const NOD::DiscBase::IPartition::Node& node : dataPart->getFSTRoot())
{
if (node.getKind() == NOD::DiscBase::IPartition::Node::NODE_FILE)
printf("FILE: %s\n", node.getName().c_str());
else if (node.getKind() == NOD::DiscBase::IPartition::Node::NODE_DIRECTORY)
{
printf("DIR: %s\n", node.getName().c_str());
for (const NOD::DiscBase::IPartition::Node& subnode : node)
printf("SUBFILE: %s\n", subnode.getName().c_str());
}
}
if (argv[a][0] == '-' && argv[a][1] == 'f')
force = true;
else if (!inDir)
inDir = argv[a];
else
outDir = argv[a];
}
if (!strcasecmp(argv[1], "extract"))
{
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(inDir);
if (!disc)
return -1;
NOD::DiscBase::IPartition* dataPart = disc->getDataPartition();
if (!dataPart)
return -1;
dataPart->extractToDirectory(outDir, force);
}
else if (!strcasecmp(argv[1], "make"))
{
}
else
{
printHelp();
return -1;
}
return 0;