From e494dbba9f29634ccbd2b9af203b86d11d5466d5 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 21 May 2017 03:26:22 -0700 Subject: [PATCH] Add completion percentage to ExtractionContext's callback --- driver/main.cpp | 4 ++-- include/nod/DiscBase.hpp | 1 + include/nod/nod.hpp | 2 +- lib/DiscBase.cpp | 11 +++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index 8436d44..a916854 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -39,8 +39,8 @@ int main(int argc, char* argv[]) logvisor::RegisterStandardExceptions(); logvisor::RegisterConsoleLogger(); - nod::ExtractionContext ctx = { true, true, [&](const std::string& str){ - fprintf(stderr, "%s\n", str.c_str()); + nod::ExtractionContext ctx = { true, true, [&](const std::string& str, float c){ + fprintf(stderr, "Current node: %s, Extraction %g%% Complete\n", str.c_str(), c); }}; const nod::SystemChar* inDir = nullptr; const nod::SystemChar* outDir = _S("."); diff --git a/include/nod/DiscBase.hpp b/include/nod/DiscBase.hpp index ed94f2e..2bc7780 100644 --- a/include/nod/DiscBase.hpp +++ b/include/nod/DiscBase.hpp @@ -236,6 +236,7 @@ public: Kind m_kind; uint64_t m_offset; public: + mutable size_t m_curNodeIdx = 0; IPartition(const DiscBase& parent, Kind kind, uint64_t offset) : m_parent(parent), m_kind(kind), m_offset(offset) {} virtual uint64_t normalizeOffset(uint64_t anOffset) const {return anOffset;} diff --git a/include/nod/nod.hpp b/include/nod/nod.hpp index f2afb2b..ad94c60 100644 --- a/include/nod/nod.hpp +++ b/include/nod/nod.hpp @@ -15,7 +15,7 @@ struct ExtractionContext final { bool verbose : 1; bool force : 1; - std::function progressCB; + std::function progressCB; }; std::unique_ptr OpenDiscFromImage(const SystemChar* path); diff --git a/lib/DiscBase.cpp b/lib/DiscBase.cpp index 241eeec..be79386 100644 --- a/lib/DiscBase.cpp +++ b/lib/DiscBase.cpp @@ -97,8 +97,9 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath if (m_kind == Kind::Directory) { + ++m_parent.m_curNodeIdx; 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) { 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) { Sstat theStat; + ++m_parent.m_curNodeIdx; 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)) { @@ -129,6 +131,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath bool DiscBase::IPartition::extractToDirectory(const SystemString& path, const ExtractionContext& ctx) { + m_curNodeIdx = 0; Sstat theStat; 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.verbose && ctx.progressCB) - ctx.progressCB("apploader.bin"); + ctx.progressCB("apploader.bin", 0.f); std::unique_ptr buf = getApploaderBuf(); auto ws = NewFileIO(apploaderPath)->beginWriteStream(); if (!ws) @@ -154,7 +157,7 @@ bool DiscBase::IPartition::extractToDirectory(const SystemString& path, if (ctx.force || Stat(dolPath.c_str(), &theStat)) { if (ctx.verbose && ctx.progressCB) - ctx.progressCB("boot.dol"); + ctx.progressCB("boot.dol", 0.f); std::unique_ptr buf = getDOLBuf(); auto ws = NewFileIO(dolPath)->beginWriteStream(); if (!ws)