Initial extractor automation

This commit is contained in:
Jack Andersen
2015-06-29 20:46:19 -10:00
parent ec8db1694b
commit 293b7c0ce6
13 changed files with 271 additions and 90 deletions

View File

@@ -1,4 +1,6 @@
#include <sys/stat.h>
#include "DiscBase.hpp"
#include "IFileIO.hpp"
namespace NOD
{
@@ -26,7 +28,7 @@ void DiscBase::IPartition::parseFST(IPartReadStream& s)
for (uint32_t n=0 ; n<nodeCount ; ++n)
{
const FSTNode& node = nodes[n];
m_nodes.emplace_back(*this, node, n ? names + node.getNameOffset() : "<root>");
m_nodes.emplace_back(*this, node, n ? names + node.getNameOffset() : "");
}
/* Setup dir-child iterators */
@@ -43,4 +45,27 @@ void DiscBase::IPartition::parseFST(IPartReadStream& s)
}
}
void DiscBase::IPartition::Node::extractToDirectory(const std::string& basePath, bool force)
{
std::string path = basePath + "/" + getName();
if (m_kind == NODE_DIRECTORY)
{
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
throw std::runtime_error("unable to mkdir '" + path + "'");
for (DiscBase::IPartition::Node& subnode : *this)
subnode.extractToDirectory(path);
}
else if (m_kind == NODE_FILE)
{
struct stat theStat;
if (force || stat(path.c_str(), &theStat))
{
m_hddFile = NewFileIO(path);
std::unique_ptr<IPartReadStream> rs = beginReadStream();
std::unique_ptr<IFileIO::IWriteStream> ws = m_hddFile->beginWriteStream();
ws->copyFromDisc(*rs.get(), m_discLength);
}
}
}
}