mirror of https://github.com/AxioDL/nod.git
Add completion percentage to ExtractionContext's callback
This commit is contained in:
parent
2bc7c4e568
commit
e494dbba9f
|
@ -39,8 +39,8 @@ int main(int argc, char* argv[])
|
||||||
logvisor::RegisterStandardExceptions();
|
logvisor::RegisterStandardExceptions();
|
||||||
logvisor::RegisterConsoleLogger();
|
logvisor::RegisterConsoleLogger();
|
||||||
|
|
||||||
nod::ExtractionContext ctx = { true, true, [&](const std::string& str){
|
nod::ExtractionContext ctx = { true, true, [&](const std::string& str, float c){
|
||||||
fprintf(stderr, "%s\n", str.c_str());
|
fprintf(stderr, "Current node: %s, Extraction %g%% Complete\n", str.c_str(), c);
|
||||||
}};
|
}};
|
||||||
const nod::SystemChar* inDir = nullptr;
|
const nod::SystemChar* inDir = nullptr;
|
||||||
const nod::SystemChar* outDir = _S(".");
|
const nod::SystemChar* outDir = _S(".");
|
||||||
|
|
|
@ -236,6 +236,7 @@ public:
|
||||||
Kind m_kind;
|
Kind m_kind;
|
||||||
uint64_t m_offset;
|
uint64_t m_offset;
|
||||||
public:
|
public:
|
||||||
|
mutable size_t m_curNodeIdx = 0;
|
||||||
IPartition(const DiscBase& parent, Kind kind, uint64_t offset)
|
IPartition(const DiscBase& parent, Kind kind, uint64_t offset)
|
||||||
: m_parent(parent), m_kind(kind), m_offset(offset) {}
|
: m_parent(parent), m_kind(kind), m_offset(offset) {}
|
||||||
virtual uint64_t normalizeOffset(uint64_t anOffset) const {return anOffset;}
|
virtual uint64_t normalizeOffset(uint64_t anOffset) const {return anOffset;}
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct ExtractionContext final
|
||||||
{
|
{
|
||||||
bool verbose : 1;
|
bool verbose : 1;
|
||||||
bool force : 1;
|
bool force : 1;
|
||||||
std::function<void(const std::string&)> progressCB;
|
std::function<void(const std::string&, float)> progressCB;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path);
|
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path);
|
||||||
|
|
|
@ -97,8 +97,9 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
|
||||||
|
|
||||||
if (m_kind == Kind::Directory)
|
if (m_kind == Kind::Directory)
|
||||||
{
|
{
|
||||||
|
++m_parent.m_curNodeIdx;
|
||||||
if (ctx.verbose && ctx.progressCB && !getName().empty())
|
if (ctx.verbose && ctx.progressCB && !getName().empty())
|
||||||
ctx.progressCB(getName());
|
ctx.progressCB(getName(), float(m_parent.m_curNodeIdx * 100.f) / m_parent.getNodeCount());
|
||||||
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
|
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
|
||||||
{
|
{
|
||||||
LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), path.c_str());
|
LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), path.c_str());
|
||||||
|
@ -111,8 +112,9 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
|
||||||
else if (m_kind == Kind::File)
|
else if (m_kind == Kind::File)
|
||||||
{
|
{
|
||||||
Sstat theStat;
|
Sstat theStat;
|
||||||
|
++m_parent.m_curNodeIdx;
|
||||||
if (ctx.verbose && ctx.progressCB)
|
if (ctx.verbose && ctx.progressCB)
|
||||||
ctx.progressCB(getName());
|
ctx.progressCB(getName(), float(m_parent.m_curNodeIdx * 100.f) / m_parent.getNodeCount());
|
||||||
|
|
||||||
if (ctx.force || Stat(path.c_str(), &theStat))
|
if (ctx.force || Stat(path.c_str(), &theStat))
|
||||||
{
|
{
|
||||||
|
@ -129,6 +131,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
|
||||||
bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
|
bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
|
||||||
const ExtractionContext& ctx)
|
const ExtractionContext& ctx)
|
||||||
{
|
{
|
||||||
|
m_curNodeIdx = 0;
|
||||||
Sstat theStat;
|
Sstat theStat;
|
||||||
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
|
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
|
||||||
{
|
{
|
||||||
|
@ -141,7 +144,7 @@ bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
|
||||||
if (ctx.force || Stat(apploaderPath.c_str(), &theStat))
|
if (ctx.force || Stat(apploaderPath.c_str(), &theStat))
|
||||||
{
|
{
|
||||||
if (ctx.verbose && ctx.progressCB)
|
if (ctx.verbose && ctx.progressCB)
|
||||||
ctx.progressCB("apploader.bin");
|
ctx.progressCB("apploader.bin", 0.f);
|
||||||
std::unique_ptr<uint8_t[]> buf = getApploaderBuf();
|
std::unique_ptr<uint8_t[]> buf = getApploaderBuf();
|
||||||
auto ws = NewFileIO(apploaderPath)->beginWriteStream();
|
auto ws = NewFileIO(apploaderPath)->beginWriteStream();
|
||||||
if (!ws)
|
if (!ws)
|
||||||
|
@ -154,7 +157,7 @@ bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
|
||||||
if (ctx.force || Stat(dolPath.c_str(), &theStat))
|
if (ctx.force || Stat(dolPath.c_str(), &theStat))
|
||||||
{
|
{
|
||||||
if (ctx.verbose && ctx.progressCB)
|
if (ctx.verbose && ctx.progressCB)
|
||||||
ctx.progressCB("boot.dol");
|
ctx.progressCB("boot.dol", 0.f);
|
||||||
std::unique_ptr<uint8_t[]> buf = getDOLBuf();
|
std::unique_ptr<uint8_t[]> buf = getDOLBuf();
|
||||||
auto ws = NewFileIO(dolPath)->beginWriteStream();
|
auto ws = NewFileIO(dolPath)->beginWriteStream();
|
||||||
if (!ws)
|
if (!ws)
|
||||||
|
|
Loading…
Reference in New Issue