Added progress bars to extract system

This commit is contained in:
Jack Andersen 2015-07-20 13:25:16 -10:00
parent 9d3bee522e
commit a4d6e32e48
12 changed files with 116 additions and 18 deletions

View File

@ -8,6 +8,7 @@ set(NOD_LIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/NODLib/include)
add_subdirectory(DataSpec)
add_subdirectory(Runtime)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(include)
add_library(RetroCommon
src/RetroCommon.cpp include/RetroCommon.hpp

View File

@ -58,8 +58,10 @@ ResExtractor PAKBridge::LookupExtractor(const PAK::Entry& entry)
bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
const HECL::ProjectPath& cookedOut,
bool force)
bool force,
std::function<void(float)> progress)
{
size_t count = 0;
for (const std::pair<UniqueID32, PAK::Entry*>& item : m_pak.m_idMap)
{
PAKEntryReadStream s;
@ -82,6 +84,9 @@ bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
fwrite(s.data(), 1, s.length(), fout);
fclose(fout);
}
++count;
progress(count / (float)m_pak.m_idMap.size());
}
return true;
}

View File

@ -24,7 +24,8 @@ public:
HECL::SystemString getLevelString() const;
bool extractResources(const HECL::ProjectPath& dirOut,
const HECL::ProjectPath& cookedOut,
bool force);
bool force,
std::function<void(float)> progress);
};
}

View File

@ -57,8 +57,10 @@ ResExtractor PAKBridge::LookupExtractor(const DNAMP1::PAK::Entry& entry)
bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
const HECL::ProjectPath& cookedOut,
bool force)
bool force,
std::function<void(float)> progress)
{
size_t count = 0;
for (const std::pair<UniqueID32, DNAMP1::PAK::Entry*>& item : m_pak.m_idMap)
{
PAKEntryReadStream s;
@ -81,6 +83,9 @@ bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
fwrite(s.data(), 1, s.length(), fout);
fclose(fout);
}
++count;
progress(count / (float)m_pak.m_idMap.size());
}
return true;
}

View File

@ -24,7 +24,8 @@ public:
HECL::SystemString getLevelString() const;
bool extractResources(const HECL::ProjectPath& dirOut,
const HECL::ProjectPath& cookedOut,
bool force);
bool force,
std::function<void(float)> progress);
};
}

View File

@ -66,8 +66,10 @@ ResExtractor PAKBridge::LookupExtractor(const PAK::Entry& entry)
bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
const HECL::ProjectPath& cookedOut,
bool force)
bool force,
std::function<void(float)> progress)
{
size_t count = 0;
for (const std::pair<UniqueID64, PAK::Entry*>& item : m_pak.m_idMap)
{
PAKEntryReadStream s;
@ -90,6 +92,9 @@ bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
fwrite(s.data(), 1, s.length(), fout);
fclose(fout);
}
++count;
progress(count / (float)m_pak.m_idMap.size());
}
return true;
}

View File

@ -24,7 +24,8 @@ public:
HECL::SystemString getLevelString() const;
bool extractResources(const HECL::ProjectPath& dirOut,
const HECL::ProjectPath& cookedOut,
bool force);
bool force,
std::function<void(float)> progress);
};
}

View File

@ -43,7 +43,8 @@ bool SpecBase::canExtract(HECL::Database::Project& project,
return checkFromTrilogyDisc(project, *m_disc.get(), *regstr, info.extractArgs, reps);
}
void SpecBase::doExtract(HECL::Database::Project& project, const ExtractPassInfo& info)
void SpecBase::doExtract(HECL::Database::Project& project, const ExtractPassInfo& info,
FExtractProgress progress)
{
if (m_isWii)
{
@ -51,18 +52,24 @@ void SpecBase::doExtract(HECL::Database::Project& project, const ExtractPassInfo
const HECL::SystemString& target = project.getProjectRootPath().getAbsolutePath();
NOD::DiscBase::IPartition* update = m_disc->getUpdatePartition();
if (update)
{
progress(_S("Update Partition"), 0, 0.0);
update->getFSTRoot().extractToDirectory(target, info.force);
progress(_S("Update Partition"), 0, 1.0);
}
if (!m_standalone)
{
progress(_S("Trilogy Files"), 1, 0.0);
NOD::DiscBase::IPartition* data = m_disc->getDataPartition();
const NOD::DiscBase::IPartition::Node& root = data->getFSTRoot();
for (const NOD::DiscBase::IPartition::Node& child : root)
if (child.getKind() == NOD::DiscBase::IPartition::Node::NODE_FILE)
child.extractToDirectory(target, info.force);
progress(_S("Trilogy Files"), 1, 1.0);
}
}
extractFromDisc(project, *m_disc.get(), info.force);
extractFromDisc(project, *m_disc.get(), info.force, progress);
}
bool SpecBase::canCook(const HECL::Database::Project& project, const CookTaskInfo& info)

View File

@ -13,7 +13,7 @@ struct SpecBase : HECL::Database::IDataSpec
{
bool canExtract(HECL::Database::Project& project, const ExtractPassInfo& info,
std::vector<ExtractReport>& reps);
void doExtract(HECL::Database::Project& project, const ExtractPassInfo& info);
void doExtract(HECL::Database::Project& project, const ExtractPassInfo& info, FExtractProgress progress);
bool canCook(const HECL::Database::Project& project, const CookTaskInfo& info);
void doCook(const HECL::Database::Project& project, const CookTaskInfo& info);
@ -34,7 +34,8 @@ struct SpecBase : HECL::Database::IDataSpec
const HECL::SystemString& regstr,
const std::vector<HECL::SystemString>& args,
std::vector<ExtractReport>& reps)=0;
virtual bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase& disc, bool force)=0;
virtual bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase& disc, bool force,
FExtractProgress progress)=0;
virtual bool checkFromProject(HECL::Database::Project& proj)=0;
virtual bool readFromProject(HECL::Database::Project& proj)=0;

View File

@ -196,24 +196,35 @@ struct SpecMP1 : SpecBase
return true;
}
bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase&, bool force)
bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase&, bool force,
FExtractProgress progress)
{
if (!doMP1)
return true;
HECL::ProjectPath mp1WorkPath(project.getProjectRootPath(), "MP1");
mp1WorkPath.makeDir();
progress(_S("MP1 Root"), 2, 0.0);
int prog = 0;
for (const NOD::DiscBase::IPartition::Node* node : m_nonPaks)
{
node->extractToDirectory(mp1WorkPath.getAbsolutePath(), force);
progress(_S("MP1 Root"), 2, prog++ / (float)m_nonPaks.size());
}
progress(_S("MP1 Root"), 2, 1.0);
const HECL::ProjectPath& cookPath = project.getProjectCookedPath(SpecEntMP1);
cookPath.makeDir();
HECL::ProjectPath mp1CookPath(cookPath, "MP1");
mp1CookPath.makeDir();
int compIdx = 3;
prog = 0;
for (DNAMP1::PAKBridge& pak : m_paks)
{
const std::string& name = pak.getName();
HECL::SystemStringView sysName(name);
std::string::const_iterator extit = name.end() - 4;
std::string baseName(name.begin(), extit);
@ -221,7 +232,14 @@ struct SpecMP1 : SpecBase
pakWorkPath.makeDir();
HECL::ProjectPath pakCookPath(mp1CookPath, baseName);
pakCookPath.makeDir();
pak.extractResources(pakWorkPath, pakCookPath, force);
progress(sysName.sys_str().c_str(), compIdx, 0.0);
pak.extractResources(pakWorkPath, pakCookPath, force,
[&progress, &sysName, &compIdx](float factor)
{
progress(sysName.sys_str().c_str(), compIdx, factor);
});
progress(sysName.sys_str().c_str(), compIdx++, 1.0);
}
return true;

View File

@ -194,24 +194,35 @@ struct SpecMP2 : SpecBase
return true;
}
bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase&, bool force)
bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase&, bool force,
FExtractProgress progress)
{
if (!doMP2)
return true;
HECL::ProjectPath mp2WorkPath(project.getProjectRootPath(), "MP2");
mp2WorkPath.makeDir();
progress(_S("MP2 Root"), 2, 0.0);
int prog = 0;
for (const NOD::DiscBase::IPartition::Node* node : m_nonPaks)
{
node->extractToDirectory(mp2WorkPath.getAbsolutePath(), force);
progress(_S("MP2 Root"), 2, prog++ / (float)m_nonPaks.size());
}
progress(_S("MP2 Root"), 2, 1.0);
const HECL::ProjectPath& cookPath = project.getProjectCookedPath(SpecEntMP2);
cookPath.makeDir();
HECL::ProjectPath mp2CookPath(cookPath, "MP2");
mp2CookPath.makeDir();
int compIdx = 3;
prog = 0;
for (DNAMP2::PAKBridge& pak : m_paks)
{
const std::string& name = pak.getName();
HECL::SystemStringView sysName(name);
std::string::const_iterator extit = name.end() - 4;
std::string baseName(name.begin(), extit);
@ -219,7 +230,14 @@ struct SpecMP2 : SpecBase
pakWorkPath.makeDir();
HECL::ProjectPath pakCookPath(mp2CookPath, baseName);
pakCookPath.makeDir();
pak.extractResources(pakWorkPath, pakCookPath, force);
progress(sysName.sys_str().c_str(), compIdx, 0.0);
pak.extractResources(pakWorkPath, pakCookPath, force,
[&progress, &sysName, &compIdx](float factor)
{
progress(sysName.sys_str().c_str(), compIdx, factor);
});
progress(sysName.sys_str().c_str(), compIdx++, 1.0);
}
return true;

View File

@ -287,23 +287,35 @@ struct SpecMP3 : SpecBase
return true;
}
bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase&, bool force)
bool extractFromDisc(HECL::Database::Project& project, NOD::DiscBase&, bool force,
FExtractProgress progress)
{
int compIdx = 2;
int prog;
if (doMP3)
{
HECL::ProjectPath mp3WorkPath(project.getProjectRootPath(), "MP3");
mp3WorkPath.makeDir();
progress(_S("MP3 Root"), compIdx, 0.0);
prog = 0;
for (const NOD::DiscBase::IPartition::Node* node : m_nonPaks)
{
node->extractToDirectory(mp3WorkPath.getAbsolutePath(), force);
progress(_S("MP3 Root"), compIdx, prog++ / (float)m_nonPaks.size());
}
progress(_S("MP3 Root"), compIdx++, 1.0);
const HECL::ProjectPath& cookPath = project.getProjectCookedPath(SpecEntMP3);
cookPath.makeDir();
HECL::ProjectPath mp3CookPath(cookPath, "MP3");
mp3CookPath.makeDir();
prog = 0;
for (DNAMP3::PAKBridge& pak : m_paks)
{
const std::string& name = pak.getName();
HECL::SystemStringView sysName(name);
std::string::const_iterator extit = name.end() - 4;
std::string baseName(name.begin(), extit);
@ -311,7 +323,14 @@ struct SpecMP3 : SpecBase
pakWorkPath.makeDir();
HECL::ProjectPath pakCookPath(mp3CookPath, baseName);
pakCookPath.makeDir();
pak.extractResources(pakWorkPath, pakCookPath, force);
progress(sysName.sys_str().c_str(), compIdx, 0.0);
pak.extractResources(pakWorkPath, pakCookPath, force,
[&progress, &sysName, &compIdx](float factor)
{
progress(sysName.sys_str().c_str(), compIdx, factor);
});
progress(sysName.sys_str().c_str(), compIdx++, 1.0);
}
}
@ -319,17 +338,26 @@ struct SpecMP3 : SpecBase
{
HECL::ProjectPath feWorkPath(project.getProjectRootPath(), "fe");
feWorkPath.makeDir();
for (const NOD::DiscBase::IPartition::Node* node : m_feNonPaks)
progress(_S("fe Root"), compIdx, 0.0);
int prog = 0;
for (const NOD::DiscBase::IPartition::Node* node : m_nonPaks)
{
node->extractToDirectory(feWorkPath.getAbsolutePath(), force);
progress(_S("fe Root"), compIdx, prog++ / (float)m_nonPaks.size());
}
progress(_S("fe Root"), compIdx++, 1.0);
const HECL::ProjectPath& cookPath = project.getProjectCookedPath(SpecEntMP3);
cookPath.makeDir();
HECL::ProjectPath feCookPath(cookPath, "fe");
feCookPath.makeDir();
prog = 0;
for (DNAMP3::PAKBridge& pak : m_fePaks)
{
const std::string& name = pak.getName();
HECL::SystemStringView sysName(name);
std::string::const_iterator extit = name.end() - 4;
std::string baseName(name.begin(), extit);
@ -337,7 +365,14 @@ struct SpecMP3 : SpecBase
pakWorkPath.makeDir();
HECL::ProjectPath pakCookPath(feCookPath, baseName);
pakCookPath.makeDir();
pak.extractResources(pakWorkPath, pakCookPath, force);
progress(sysName.sys_str().c_str(), compIdx, 0.0);
pak.extractResources(pakWorkPath, pakCookPath, force,
[&progress, &sysName, &compIdx](float factor)
{
progress(sysName.sys_str().c_str(), compIdx, factor);
});
progress(sysName.sys_str().c_str(), compIdx++, 1.0);
}
}