Massive libfmt refactor

This commit is contained in:
Jack Andersen 2019-07-19 18:21:57 -10:00
parent d9b6be8446
commit 37792ba116
13 changed files with 103 additions and 118 deletions

View File

@ -41,12 +41,12 @@ auto progFunc = [&](size_t idx, const nod::SystemString& name, size_t bytes)
lastIdx = idx; lastIdx = idx;
/* NOD provides I/O wrappers using wchar_t on Windows; /* NOD provides I/O wrappers using wchar_t on Windows;
* _S() conditionally makes string-literals wide */ * _S() conditionally makes string-literals wide */
nod::Printf(_S("\n")); fmt::print(_S("\n"));
} }
if (bytes != -1) if (bytes != -1)
nod::Printf(_S("\r%s %" PRISize " B"), name.c_str(), bytes); fmt::print(_S("\r{} {} B"), name, bytes);
else else
nod::Printf(_S("\r%s"), name.c_str()); fmt::print(_S("\r{}"), name);
fflush(stdout); fflush(stdout);
}; };

View File

@ -4,13 +4,13 @@
#include "nod/nod.hpp" #include "nod/nod.hpp"
static void printHelp() { static void printHelp() {
fprintf(stderr, fmt::print(stderr, fmt(
"Usage:\n" "Usage:\n"
" nodtool extract [-f] <image-in> [<dir-out>]\n" " nodtool extract [-f] <image-in> [<dir-out>]\n"
" nodtool makegcn <fsroot-in> [<image-out>]\n" " nodtool makegcn <fsroot-in> [<image-out>]\n"
" nodtool makewii <fsroot-in> [<image-out>]\n" " nodtool makewii <fsroot-in> [<image-out>]\n"
" nodtool mergegcn <fsroot-in> <image-in> [<image-out>]\n" " nodtool mergegcn <fsroot-in> <image-in> [<image-out>]\n"
" nodtool mergewii <fsroot-in> <image-in> [<image-out>]\n"); " nodtool mergewii <fsroot-in> <image-in> [<image-out>]\n"));
} }
#if NOD_UCS2 #if NOD_UCS2
@ -40,8 +40,8 @@ int main(int argc, char* argv[])
bool verbose = false; bool verbose = false;
nod::ExtractionContext ctx = {true, [&](std::string_view str, float c) { nod::ExtractionContext ctx = {true, [&](std::string_view str, float c) {
if (verbose) if (verbose)
fprintf(stderr, "Current node: %s, Extraction %g%% Complete\n", str.data(), fmt::print(stderr, fmt("Current node: {}, Extraction {:g}% Complete\n"), str,
c * 100.f); c * 100.f);
}}; }};
const nod::SystemChar* inDir = nullptr; const nod::SystemChar* inDir = nullptr;
const nod::SystemChar* outDir = _SYS_STR("."); const nod::SystemChar* outDir = _SYS_STR(".");
@ -59,11 +59,11 @@ int main(int argc, char* argv[])
} }
auto progFunc = [&](float prog, nod::SystemStringView name, size_t bytes) { auto progFunc = [&](float prog, nod::SystemStringView name, size_t bytes) {
nod::Printf(_SYS_STR("\r ")); fmt::print(fmt(_SYS_STR("\r ")));
if (bytes != SIZE_MAX) if (bytes != SIZE_MAX)
nod::Printf(_SYS_STR("\r%g%% %s %" PRISize " B"), prog * 100.f, name.data(), bytes); fmt::print(fmt(_SYS_STR("\r{:g}% {} {} B")), prog * 100.f, name, bytes);
else else
nod::Printf(_SYS_STR("\r%g%% %s"), prog * 100.f, name.data()); fmt::print(fmt(_SYS_STR("\r{:g}% {}")), prog * 100.f, name);
fflush(stdout); fflush(stdout);
}; };
@ -85,7 +85,7 @@ int main(int argc, char* argv[])
/* Pre-validate path */ /* Pre-validate path */
nod::Sstat theStat; nod::Sstat theStat;
if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) { if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s as directory"), argv[2]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {} as directory")), argv[2]);
return 1; return 1;
} }
@ -104,14 +104,14 @@ int main(int argc, char* argv[])
ret = b.buildFromDirectory(argv[2]); ret = b.buildFromDirectory(argv[2]);
} }
printf("\n"); fmt::print(fmt("\n"));
if (ret != nod::EBuildResult::Success) if (ret != nod::EBuildResult::Success)
return 1; return 1;
} else if (!strcasecmp(argv[1], _SYS_STR("makewii"))) { } else if (!strcasecmp(argv[1], _SYS_STR("makewii"))) {
/* Pre-validate path */ /* Pre-validate path */
nod::Sstat theStat; nod::Sstat theStat;
if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) { if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s as directory"), argv[4]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {} as directory")), argv[4]);
return 1; return 1;
} }
@ -131,29 +131,29 @@ int main(int argc, char* argv[])
ret = b.buildFromDirectory(argv[2]); ret = b.buildFromDirectory(argv[2]);
} }
printf("\n"); fmt::print(fmt("\n"));
if (ret != nod::EBuildResult::Success) if (ret != nod::EBuildResult::Success)
return 1; return 1;
} else if (!strcasecmp(argv[1], _SYS_STR("mergegcn"))) { } else if (!strcasecmp(argv[1], _SYS_STR("mergegcn"))) {
/* Pre-validate paths */ /* Pre-validate paths */
nod::Sstat theStat; nod::Sstat theStat;
if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) { if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s as directory"), argv[2]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {} as directory")), argv[2]);
return 1; return 1;
} }
if (nod::Stat(argv[3], &theStat) || !S_ISREG(theStat.st_mode)) { if (nod::Stat(argv[3], &theStat) || !S_ISREG(theStat.st_mode)) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s as file"), argv[3]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {} as file")), argv[3]);
return 1; return 1;
} }
bool isWii; bool isWii;
std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(argv[3], isWii); std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(argv[3], isWii);
if (!disc) { if (!disc) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to open image %s"), argv[3]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open image {}")), argv[3]);
return 1; return 1;
} }
if (isWii) { if (isWii) {
nod::LogModule.report(logvisor::Error, _SYS_STR("Wii images should be merged with 'mergewii'")); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("Wii images should be merged with 'mergewii'")));
return 1; return 1;
} }
@ -172,29 +172,29 @@ int main(int argc, char* argv[])
ret = b.mergeFromDirectory(argv[2]); ret = b.mergeFromDirectory(argv[2]);
} }
printf("\n"); fmt::print(fmt("\n"));
if (ret != nod::EBuildResult::Success) if (ret != nod::EBuildResult::Success)
return 1; return 1;
} else if (!strcasecmp(argv[1], _SYS_STR("mergewii"))) { } else if (!strcasecmp(argv[1], _SYS_STR("mergewii"))) {
/* Pre-validate paths */ /* Pre-validate paths */
nod::Sstat theStat; nod::Sstat theStat;
if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) { if (nod::Stat(argv[2], &theStat) || !S_ISDIR(theStat.st_mode)) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s as directory"), argv[2]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {} as directory")), argv[2]);
return 1; return 1;
} }
if (nod::Stat(argv[3], &theStat) || !S_ISREG(theStat.st_mode)) { if (nod::Stat(argv[3], &theStat) || !S_ISREG(theStat.st_mode)) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s as file"), argv[3]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {} as file")), argv[3]);
return 1; return 1;
} }
bool isWii; bool isWii;
std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(argv[3], isWii); std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(argv[3], isWii);
if (!disc) { if (!disc) {
nod::LogModule.report(logvisor::Error, _SYS_STR("unable to open image %s"), argv[3]); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open image {}")), argv[3]);
return 1; return 1;
} }
if (!isWii) { if (!isWii) {
nod::LogModule.report(logvisor::Error, _SYS_STR("GameCube images should be merged with 'mergegcn'")); nod::LogModule.report(logvisor::Error, fmt(_SYS_STR("GameCube images should be merged with 'mergegcn'")));
return 1; return 1;
} }
@ -214,7 +214,7 @@ int main(int argc, char* argv[])
ret = b.mergeFromDirectory(argv[2]); ret = b.mergeFromDirectory(argv[2]);
} }
printf("\n"); fmt::print(fmt("\n"));
if (ret != nod::EBuildResult::Success) if (ret != nod::EBuildResult::Success)
return 1; return 1;
} else { } else {
@ -222,6 +222,6 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
nod::LogModule.report(logvisor::Info, _SYS_STR("Success!")); nod::LogModule.report(logvisor::Info, fmt(_SYS_STR("Success!")));
return 0; return 0;
} }

View File

@ -22,11 +22,11 @@ public:
uint64_t thisSz = nod::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
uint64_t readSz = discio.read(buf, thisSz); uint64_t readSz = discio.read(buf, thisSz);
if (thisSz != readSz) { if (thisSz != readSz) {
LogModule.report(logvisor::Error, "unable to read enough from disc"); LogModule.report(logvisor::Error, fmt("unable to read enough from disc"));
return read; return read;
} }
if (write(buf, readSz) != readSz) { if (write(buf, readSz) != readSz) {
LogModule.report(logvisor::Error, "unable to write in file"); LogModule.report(logvisor::Error, fmt("unable to write in file"));
return read; return read;
} }
length -= thisSz; length -= thisSz;
@ -42,11 +42,11 @@ public:
uint64_t thisSz = nod::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
uint64_t readSz = discio.read(buf, thisSz); uint64_t readSz = discio.read(buf, thisSz);
if (thisSz != readSz) { if (thisSz != readSz) {
LogModule.report(logvisor::Error, "unable to read enough from disc"); LogModule.report(logvisor::Error, fmt("unable to read enough from disc"));
return read; return read;
} }
if (write(buf, readSz) != readSz) { if (write(buf, readSz) != readSz) {
LogModule.report(logvisor::Error, "unable to write in file"); LogModule.report(logvisor::Error, fmt("unable to write in file"));
return read; return read;
} }
length -= thisSz; length -= thisSz;

View File

@ -261,7 +261,7 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
&ov); &ov);
#else #else
if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB)) if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB))
LogModule.report(logvisor::Error, "flock %s: %s", path, strerror(errno)); LogModule.report(logvisor::Error, fmt("flock {}: {}"), path, strerror(errno));
#endif #endif
} }
@ -295,39 +295,24 @@ static inline bool CheckFreeSpace(const SystemChar* path, size_t reqSz) {
wchar_t* end; wchar_t* end;
DWORD ret = GetFullPathNameW(path, 1024, buf, &end); DWORD ret = GetFullPathNameW(path, 1024, buf, &end);
if (!ret || ret > 1024) { if (!ret || ret > 1024) {
LogModule.report(logvisor::Error, _SYS_STR("GetFullPathNameW %s"), path); LogModule.report(logvisor::Error, fmt(_SYS_STR("GetFullPathNameW {}")), path);
return false; return false;
} }
if (end) if (end)
end[0] = L'\0'; end[0] = L'\0';
if (!GetDiskFreeSpaceExW(buf, &freeBytes, nullptr, nullptr)) { if (!GetDiskFreeSpaceExW(buf, &freeBytes, nullptr, nullptr)) {
LogModule.report(logvisor::Error, _SYS_STR("GetDiskFreeSpaceExW %s: %d"), path, GetLastError()); LogModule.report(logvisor::Error, fmt(_SYS_STR("GetDiskFreeSpaceExW {}: {}")), path, GetLastError());
return false; return false;
} }
return reqSz < freeBytes.QuadPart; return reqSz < freeBytes.QuadPart;
#else #else
struct statvfs svfs; struct statvfs svfs;
if (statvfs(path, &svfs)) { if (statvfs(path, &svfs)) {
LogModule.report(logvisor::Error, "statvfs %s: %s", path, strerror(errno)); LogModule.report(logvisor::Error, fmt("statvfs {}: {}"), path, strerror(errno));
return false; return false;
} }
return reqSz < svfs.f_frsize * svfs.f_bavail; return reqSz < svfs.f_frsize * svfs.f_bavail;
#endif #endif
} }
#if __GNUC__
__attribute__((__format__(__printf__, 1, 2)))
#endif
static inline void
Printf(const SystemChar* fmt, ...) {
va_list args;
va_start(args, fmt);
#if NOD_UCS2
vwprintf(fmt, args);
#else
vprintf(fmt, args);
#endif
va_end(args);
}
} // namespace nod } // namespace nod

View File

@ -101,7 +101,7 @@ Node::Node(const IPartition& parent, const FSTNode& node, std::string_view name)
std::unique_ptr<IPartReadStream> Node::beginReadStream(uint64_t offset) const { std::unique_ptr<IPartReadStream> Node::beginReadStream(uint64_t offset) const {
if (m_kind != Kind::File) { if (m_kind != Kind::File) {
LogModule.report(logvisor::Error, "unable to stream a non-file %s", m_name.c_str()); LogModule.report(logvisor::Error, fmt("unable to stream a non-file {}"), m_name);
return std::unique_ptr<IPartReadStream>(); return std::unique_ptr<IPartReadStream>();
} }
return m_parent.beginReadStream(m_discOffset + offset); return m_parent.beginReadStream(m_discOffset + offset);
@ -109,7 +109,7 @@ std::unique_ptr<IPartReadStream> Node::beginReadStream(uint64_t offset) const {
std::unique_ptr<uint8_t[]> Node::getBuf() const { std::unique_ptr<uint8_t[]> Node::getBuf() const {
if (m_kind != Kind::File) { if (m_kind != Kind::File) {
LogModule.report(logvisor::Error, "unable to buffer a non-file %s", m_name.c_str()); LogModule.report(logvisor::Error, fmt("unable to buffer a non-file {}"), m_name);
return std::unique_ptr<uint8_t[]>(); return std::unique_ptr<uint8_t[]>();
} }
uint8_t* buf = new uint8_t[m_discLength]; uint8_t* buf = new uint8_t[m_discLength];
@ -126,7 +126,7 @@ bool Node::extractToDirectory(SystemStringView basePath, const ExtractionContext
if (ctx.progressCB && !getName().empty()) if (ctx.progressCB && !getName().empty())
ctx.progressCB(getName(), m_parent.m_curNodeIdx / float(m_parent.getNodeCount())); ctx.progressCB(getName(), m_parent.m_curNodeIdx / float(m_parent.getNodeCount()));
if (Mkdir(path.c_str(), 0755) && errno != EEXIST) { if (Mkdir(path.c_str(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, _SYS_STR("unable to mkdir '%s'"), path.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to mkdir '{}'")), path);
return false; return false;
} }
for (Node& subnode : *this) for (Node& subnode : *this)
@ -155,14 +155,14 @@ bool Node::extractToDirectory(SystemStringView basePath, const ExtractionContext
bool IPartition::extractToDirectory(SystemStringView path, const ExtractionContext& ctx) { bool IPartition::extractToDirectory(SystemStringView path, const ExtractionContext& ctx) {
m_curNodeIdx = 0; m_curNodeIdx = 0;
if (Mkdir(path.data(), 0755) && errno != EEXIST) { if (Mkdir(path.data(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, _SYS_STR("unable to mkdir '%s'"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to mkdir '{}'")), path);
return false; return false;
} }
SystemString basePath = m_isWii ? SystemString(path) + _SYS_STR("/") + getKindString(m_kind) : SystemString(path); SystemString basePath = m_isWii ? SystemString(path) + _SYS_STR("/") + getKindString(m_kind) : SystemString(path);
if (m_isWii) { if (m_isWii) {
if (Mkdir(basePath.c_str(), 0755) && errno != EEXIST) { if (Mkdir(basePath.c_str(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, _SYS_STR("unable to mkdir '%s'"), basePath.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to mkdir '{}'")), basePath);
return false; return false;
} }
} }
@ -181,7 +181,7 @@ bool IPartition::extractToDirectory(SystemStringView path, const ExtractionConte
/* Extract Filesystem */ /* Extract Filesystem */
SystemString fsPath = basePath + _SYS_STR("/files"); SystemString fsPath = basePath + _SYS_STR("/files");
if (Mkdir(fsPath.c_str(), 0755) && errno != EEXIST) { if (Mkdir(fsPath.c_str(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, _SYS_STR("unable to mkdir '%s'"), fsPath.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to mkdir '{}'")), fsPath);
return false; return false;
} }
@ -191,7 +191,7 @@ bool IPartition::extractToDirectory(SystemStringView path, const ExtractionConte
bool IPartition::extractSysFiles(SystemStringView basePath, const ExtractionContext& ctx) const { bool IPartition::extractSysFiles(SystemStringView basePath, const ExtractionContext& ctx) const {
SystemString basePathStr(basePath); SystemString basePathStr(basePath);
if (Mkdir((basePathStr + _SYS_STR("/sys")).c_str(), 0755) && errno != EEXIST) { if (Mkdir((basePathStr + _SYS_STR("/sys")).c_str(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, _SYS_STR("unable to mkdir '%s/sys'"), basePath.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to mkdir '{}/sys'")), basePath);
return false; return false;
} }
@ -703,7 +703,7 @@ bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(uint64_t
bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream& ws, SystemStringView dirIn) { bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream& ws, SystemStringView dirIn) {
if (dirIn.empty()) { if (dirIn.empty()) {
LogModule.report(logvisor::Error, _SYS_STR("all arguments must be supplied to buildFromDirectory()")); LogModule.report(logvisor::Error, fmt(_SYS_STR("all arguments must be supplied to buildFromDirectory()")));
return false; return false;
} }
@ -728,7 +728,7 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream&
{ {
Sstat dolStat; Sstat dolStat;
if (Stat(dolIn.c_str(), &dolStat)) { if (Stat(dolIn.c_str(), &dolStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), dolIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), dolIn);
return false; return false;
} }
size_t fileSz = ROUND_UP_32(dolStat.st_size); size_t fileSz = ROUND_UP_32(dolStat.st_size);
@ -769,7 +769,7 @@ uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(SystemSt
Sstat dolStat; Sstat dolStat;
if (Stat(dolIn.c_str(), &dolStat)) { if (Stat(dolIn.c_str(), &dolStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), dolIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), dolIn);
return UINT64_MAX; return UINT64_MAX;
} }
uint64_t totalSz = ROUND_UP_32(dolStat.st_size); uint64_t totalSz = ROUND_UP_32(dolStat.st_size);
@ -781,7 +781,7 @@ uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(SystemSt
bool DiscBuilderBase::PartitionBuilderBase::mergeFromDirectory(IPartWriteStream& ws, const IPartition* partIn, bool DiscBuilderBase::PartitionBuilderBase::mergeFromDirectory(IPartWriteStream& ws, const IPartition* partIn,
SystemStringView dirIn) { SystemStringView dirIn) {
if (dirIn.empty()) { if (dirIn.empty()) {
LogModule.report(logvisor::Error, _SYS_STR("all arguments must be supplied to mergeFromDirectory()")); LogModule.report(logvisor::Error, fmt(_SYS_STR("all arguments must be supplied to mergeFromDirectory()")));
return false; return false;
} }

View File

@ -155,7 +155,7 @@ public:
m_curUser -= reqSz; m_curUser -= reqSz;
m_curUser &= 0xfffffffffffffff0; m_curUser &= 0xfffffffffffffff0;
if (m_curUser < 0x30000) { if (m_curUser < 0x30000) {
LogModule.report(logvisor::Error, "user area low mark reached"); LogModule.report(logvisor::Error, fmt("user area low mark reached"));
return -1; return -1;
} }
static_cast<PartWriteStream&>(ws).seek(m_curUser); static_cast<PartWriteStream&>(ws).seek(m_curUser);
@ -195,7 +195,7 @@ public:
fstSz = ROUND_UP_32(fstSz); fstSz = ROUND_UP_32(fstSz);
if (fstOff + fstSz >= m_curUser) { if (fstOff + fstSz >= m_curUser) {
LogModule.report(logvisor::Error, "FST flows into user area (one or the other is too big)"); LogModule.report(logvisor::Error, fmt("FST flows into user area (one or the other is too big)"));
return false; return false;
} }
@ -224,7 +224,7 @@ public:
SystemString apploaderIn = dirStr + _SYS_STR("/sys/apploader.img"); SystemString apploaderIn = dirStr + _SYS_STR("/sys/apploader.img");
Sstat apploaderStat; Sstat apploaderStat;
if (Stat(apploaderIn.c_str(), &apploaderStat)) { if (Stat(apploaderIn.c_str(), &apploaderStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), apploaderIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), apploaderIn);
return false; return false;
} }
@ -232,7 +232,7 @@ public:
SystemString bootIn = dirStr + _SYS_STR("/sys/boot.bin"); SystemString bootIn = dirStr + _SYS_STR("/sys/boot.bin");
Sstat bootStat; Sstat bootStat;
if (Stat(bootIn.c_str(), &bootStat)) { if (Stat(bootIn.c_str(), &bootStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), bootIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), bootIn);
return false; return false;
} }
@ -240,7 +240,7 @@ public:
SystemString bi2In = dirStr + _SYS_STR("/sys/bi2.bin"); SystemString bi2In = dirStr + _SYS_STR("/sys/bi2.bin");
Sstat bi2Stat; Sstat bi2Stat;
if (Stat(bi2In.c_str(), &bi2Stat)) { if (Stat(bi2In.c_str(), &bi2Stat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), bi2In.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), bi2In);
return false; return false;
} }
@ -282,7 +282,7 @@ public:
ws.write(buf, rdSz); ws.write(buf, rdSz);
xferSz += rdSz; xferSz += rdSz;
if (0x2440 + xferSz >= m_curUser) { if (0x2440 + xferSz >= m_curUser) {
LogModule.report(logvisor::Error, "apploader flows into user area (one or the other is too big)"); LogModule.report(logvisor::Error, fmt("apploader flows into user area (one or the other is too big)"));
return false; return false;
} }
m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderIn, xferSz); m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderIn, xferSz);
@ -324,7 +324,7 @@ public:
ws.write(apploaderBuf.get(), apploaderSz); ws.write(apploaderBuf.get(), apploaderSz);
xferSz += apploaderSz; xferSz += apploaderSz;
if (0x2440 + xferSz >= m_curUser) { if (0x2440 + xferSz >= m_curUser) {
LogModule.report(logvisor::Error, "apploader flows into user area (one or the other is too big)"); LogModule.report(logvisor::Error, fmt("apploader flows into user area (one or the other is too big)"));
return false; return false;
} }
m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderName, xferSz); m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderName, xferSz);
@ -338,7 +338,7 @@ EBuildResult DiscBuilderGCN::buildFromDirectory(SystemStringView dirIn) {
if (!m_fileIO->beginWriteStream()) if (!m_fileIO->beginWriteStream())
return EBuildResult::Failed; return EBuildResult::Failed;
if (!CheckFreeSpace(m_outPath.c_str(), 0x57058000)) { if (!CheckFreeSpace(m_outPath.c_str(), 0x57058000)) {
LogModule.report(logvisor::Error, _SYS_STR("not enough free disk space for %s"), m_outPath.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("not enough free disk space for {}")), m_outPath);
return EBuildResult::DiskFull; return EBuildResult::DiskFull;
} }
m_progressCB(getProgressFactor(), _SYS_STR("Preallocating image"), -1); m_progressCB(getProgressFactor(), _SYS_STR("Preallocating image"), -1);
@ -362,7 +362,7 @@ uint64_t DiscBuilderGCN::CalculateTotalSizeRequired(SystemStringView dirIn) {
return UINT64_MAX; return UINT64_MAX;
sz += 0x30000; sz += 0x30000;
if (sz > 0x57058000) { if (sz > 0x57058000) {
LogModule.report(logvisor::Error, _SYS_STR("disc capacity exceeded [%" PRIu64 " / %" PRIu64 "]"), sz, 0x57058000); LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x57058000);
return UINT64_MAX; return UINT64_MAX;
} }
return sz; return sz;
@ -381,7 +381,7 @@ EBuildResult DiscMergerGCN::mergeFromDirectory(SystemStringView dirIn) {
if (!m_builder.getFileIO().beginWriteStream()) if (!m_builder.getFileIO().beginWriteStream())
return EBuildResult::Failed; return EBuildResult::Failed;
if (!CheckFreeSpace(m_builder.m_outPath.c_str(), 0x57058000)) { if (!CheckFreeSpace(m_builder.m_outPath.c_str(), 0x57058000)) {
LogModule.report(logvisor::Error, _SYS_STR("not enough free disk space for %s"), m_builder.m_outPath.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("not enough free disk space for {}")), m_builder.m_outPath);
return EBuildResult::DiskFull; return EBuildResult::DiskFull;
} }
m_builder.m_progressCB(m_builder.getProgressFactor(), _SYS_STR("Preallocating image"), -1); m_builder.m_progressCB(m_builder.getProgressFactor(), _SYS_STR("Preallocating image"), -1);
@ -407,7 +407,7 @@ uint64_t DiscMergerGCN::CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemSt
return UINT64_MAX; return UINT64_MAX;
sz += 0x30000; sz += 0x30000;
if (sz > 0x57058000) { if (sz > 0x57058000) {
LogModule.report(logvisor::Error, _SYS_STR("disc capacity exceeded [%" PRIu64 " / %" PRIu64 "]"), sz, 0x57058000); LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x57058000);
return -1; return -1;
} }
return sz; return sz;

View File

@ -71,7 +71,7 @@ class DiscIOWBFS : public IDiscIO {
off *= 512ULL; off *= 512ULL;
rs.seek(off, SEEK_SET); rs.seek(off, SEEK_SET);
if (rs.read(buf, count * 512ULL) != count * 512ULL) { if (rs.read(buf, count * 512ULL) != count * 512ULL) {
LogModule.report(logvisor::Error, "error reading disc"); LogModule.report(logvisor::Error, fmt("error reading disc"));
return 1; return 1;
} }
return 0; return 0;
@ -88,7 +88,7 @@ public:
WBFS* p = &wbfs; WBFS* p = &wbfs;
WBFSHead tmpHead; WBFSHead tmpHead;
if (rs->read(&tmpHead, sizeof(tmpHead)) != sizeof(tmpHead)) { if (rs->read(&tmpHead, sizeof(tmpHead)) != sizeof(tmpHead)) {
LogModule.report(logvisor::Error, "unable to read WBFS head"); LogModule.report(logvisor::Error, fmt("unable to read WBFS head"));
return; return;
} }
unsigned hd_sector_size = 1 << tmpHead.hd_sec_sz_s; unsigned hd_sector_size = 1 << tmpHead.hd_sec_sz_s;
@ -98,7 +98,7 @@ public:
WBFSHead* head = (WBFSHead*)wbfsHead.get(); WBFSHead* head = (WBFSHead*)wbfsHead.get();
rs->seek(0, SEEK_SET); rs->seek(0, SEEK_SET);
if (rs->read(head, hd_sector_size) != hd_sector_size) { if (rs->read(head, hd_sector_size) != hd_sector_size) {
LogModule.report(logvisor::Error, "unable to read WBFS head"); LogModule.report(logvisor::Error, fmt("unable to read WBFS head"));
return; return;
} }
@ -111,11 +111,11 @@ public:
if (_wbfsReadSector(*rs, p->part_lba, 1, head)) if (_wbfsReadSector(*rs, p->part_lba, 1, head))
return; return;
if (hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size)) { if (hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size)) {
LogModule.report(logvisor::Error, "hd sector size doesn't match"); LogModule.report(logvisor::Error, fmt("hd sector size doesn't match"));
return; return;
} }
if (num_hd_sector && head->n_hd_sec != SBig(num_hd_sector)) { if (num_hd_sector && head->n_hd_sec != SBig(num_hd_sector)) {
LogModule.report(logvisor::Error, "hd num sector doesn't match"); LogModule.report(logvisor::Error, fmt("hd num sector doesn't match"));
return; return;
} }
p->hd_sec_sz = 1 << head->hd_sec_sz_s; p->hd_sec_sz = 1 << head->hd_sec_sz_s;
@ -143,7 +143,7 @@ public:
if (head->disc_table[0]) { if (head->disc_table[0]) {
wbfsDiscInfo.reset(new uint8_t[p->disc_info_sz]); wbfsDiscInfo.reset(new uint8_t[p->disc_info_sz]);
if (!wbfsDiscInfo) { if (!wbfsDiscInfo) {
LogModule.report(logvisor::Error, "allocating memory"); LogModule.report(logvisor::Error, fmt("allocating memory"));
return; return;
} }
if (_wbfsReadSector(*rs, p->part_lba + 1, disc_info_sz_lba, wbfsDiscInfo.get())) if (_wbfsReadSector(*rs, p->part_lba + 1, disc_info_sz_lba, wbfsDiscInfo.get()))

View File

@ -407,7 +407,7 @@ public:
uint32_t h3; uint32_t h3;
if (rs->read(&h3, 4) != 4) { if (rs->read(&h3, 4) != 4) {
LogModule.report(logvisor::Error, _SYS_STR("unable to read H3 offset apploader")); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to read H3 offset apploader")));
return {}; return {};
} }
h3 = SBig(h3); h3 = SBig(h3);
@ -524,7 +524,7 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio, bool& err) : DiscBase(std::move
kind = part.partType; kind = part.partType;
break; break;
default: default:
LogModule.report(logvisor::Error, "invalid partition type %d", part.partType); LogModule.report(logvisor::Error, fmt("invalid partition type {}"), part.partType);
err = true; err = true;
return; return;
} }
@ -542,7 +542,7 @@ bool DiscWii::extractDiscHeaderFiles(SystemStringView basePath, const Extraction
SystemString basePathStr(basePath); SystemString basePathStr(basePath);
if (Mkdir((basePathStr + _SYS_STR("/disc")).c_str(), 0755) && errno != EEXIST) { if (Mkdir((basePathStr + _SYS_STR("/disc")).c_str(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, _SYS_STR("unable to mkdir '%s/disc'"), basePathStr.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to mkdir '{}/disc'")), basePathStr);
return false; return false;
} }
@ -660,7 +660,7 @@ public:
} }
if (m_fio->write(m_buf, 0x200000) != 0x200000) { if (m_fio->write(m_buf, 0x200000) != 0x200000) {
LogModule.report(logvisor::Error, "unable to write full disc group"); LogModule.report(logvisor::Error, fmt("unable to write full disc group"));
return; return;
} }
} }
@ -669,7 +669,7 @@ public:
PartWriteStream(PartitionBuilderWii& parent, uint64_t baseOffset, uint64_t offset, bool& err) PartWriteStream(PartitionBuilderWii& parent, uint64_t baseOffset, uint64_t offset, bool& err)
: m_parent(parent), m_baseOffset(baseOffset), m_offset(offset) { : m_parent(parent), m_baseOffset(baseOffset), m_offset(offset) {
if (offset % 0x1F0000) { if (offset % 0x1F0000) {
LogModule.report(logvisor::Error, "partition write stream MUST begin on 0x1F0000-aligned boundary"); LogModule.report(logvisor::Error, fmt("partition write stream MUST begin on 0x1F0000-aligned boundary"));
err = true; err = true;
return; return;
} }
@ -739,13 +739,13 @@ public:
uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) { uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) {
reqSz = ROUND_UP_32(reqSz); reqSz = ROUND_UP_32(reqSz);
if (m_curUser + reqSz >= 0x1FB450000) { if (m_curUser + reqSz >= 0x1FB450000) {
LogModule.report(logvisor::Error, "partition exceeds maximum single-partition capacity"); LogModule.report(logvisor::Error, fmt("partition exceeds maximum single-partition capacity"));
return -1; return -1;
} }
uint64_t ret = m_curUser; uint64_t ret = m_curUser;
PartWriteStream& cws = static_cast<PartWriteStream&>(ws); PartWriteStream& cws = static_cast<PartWriteStream&>(ws);
if (cws.m_offset > ret) { if (cws.m_offset > ret) {
LogModule.report(logvisor::Error, "partition overwrite error"); LogModule.report(logvisor::Error, fmt("partition overwrite error"));
return -1; return -1;
} }
while (cws.m_offset < ret) while (cws.m_offset < ret)
@ -821,7 +821,7 @@ public:
fstSz = ROUND_UP_32(fstSz); fstSz = ROUND_UP_32(fstSz);
if (fstOff + fstSz >= 0x1F0000) { if (fstOff + fstSz >= 0x1F0000) {
LogModule.report(logvisor::Error, "FST flows into user area (one or the other is too big)"); LogModule.report(logvisor::Error, fmt("FST flows into user area (one or the other is too big)"));
return -1; return -1;
} }
@ -837,7 +837,7 @@ public:
size_t fstOffRel = fstOff - 0x2440; size_t fstOffRel = fstOff - 0x2440;
if (xferSz > fstOffRel) { if (xferSz > fstOffRel) {
LogModule.report(logvisor::Error, "apploader unexpectedly flows into FST"); LogModule.report(logvisor::Error, fmt("apploader unexpectedly flows into FST"));
return -1; return -1;
} }
for (size_t i = 0; i < fstOffRel - xferSz; ++i) for (size_t i = 0; i < fstOffRel - xferSz; ++i)
@ -921,7 +921,7 @@ public:
SystemString ticketIn = basePath + _SYS_STR("/ticket.bin"); SystemString ticketIn = basePath + _SYS_STR("/ticket.bin");
Sstat theStat; Sstat theStat;
if (Stat(ticketIn.c_str(), &theStat)) { if (Stat(ticketIn.c_str(), &theStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), ticketIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), ticketIn);
return -1; return -1;
} }
@ -929,7 +929,7 @@ public:
SystemString tmdIn = basePath + _SYS_STR("/tmd.bin"); SystemString tmdIn = basePath + _SYS_STR("/tmd.bin");
Sstat tmdStat; Sstat tmdStat;
if (Stat(tmdIn.c_str(), &tmdStat)) { if (Stat(tmdIn.c_str(), &tmdStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), tmdIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), tmdIn);
return -1; return -1;
} }
@ -937,7 +937,7 @@ public:
SystemString certIn = basePath + _SYS_STR("/cert.bin"); SystemString certIn = basePath + _SYS_STR("/cert.bin");
Sstat certStat; Sstat certStat;
if (Stat(certIn.c_str(), &certStat)) { if (Stat(certIn.c_str(), &certStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), certIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), certIn);
return -1; return -1;
} }
@ -945,7 +945,7 @@ public:
SystemString apploaderIn = basePath + _SYS_STR("/sys/apploader.img"); SystemString apploaderIn = basePath + _SYS_STR("/sys/apploader.img");
Sstat apploaderStat; Sstat apploaderStat;
if (Stat(apploaderIn.c_str(), &apploaderStat)) { if (Stat(apploaderIn.c_str(), &apploaderStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), apploaderIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), apploaderIn);
return -1; return -1;
} }
@ -953,7 +953,7 @@ public:
SystemString bootIn = basePath + _SYS_STR("/sys/boot.bin"); SystemString bootIn = basePath + _SYS_STR("/sys/boot.bin");
Sstat bootStat; Sstat bootStat;
if (Stat(bootIn.c_str(), &bootStat)) { if (Stat(bootIn.c_str(), &bootStat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), bootIn.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), bootIn);
return -1; return -1;
} }
@ -961,7 +961,7 @@ public:
SystemString bi2In = basePath + _SYS_STR("/sys/bi2.bin"); SystemString bi2In = basePath + _SYS_STR("/sys/bi2.bin");
Sstat bi2Stat; Sstat bi2Stat;
if (Stat(bi2In.c_str(), &bi2Stat)) { if (Stat(bi2In.c_str(), &bi2Stat)) {
LogModule.report(logvisor::Error, _SYS_STR("unable to stat %s"), bi2In.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), bi2In);
return -1; return -1;
} }
@ -1054,7 +1054,7 @@ public:
cws.write(buf, rdSz); cws.write(buf, rdSz);
xferSz += rdSz; xferSz += rdSz;
if (0x2440 + xferSz >= 0x1F0000) { if (0x2440 + xferSz >= 0x1F0000) {
LogModule.report(logvisor::Error, "apploader flows into user area (one or the other is too big)"); LogModule.report(logvisor::Error, fmt("apploader flows into user area (one or the other is too big)"));
return false; return false;
} }
m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderIn, xferSz); m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderIn, xferSz);
@ -1112,7 +1112,7 @@ public:
cws.write(apploaderBuf.get(), apploaderSz); cws.write(apploaderBuf.get(), apploaderSz);
xferSz += apploaderSz; xferSz += apploaderSz;
if (0x2440 + xferSz >= 0x1F0000) { if (0x2440 + xferSz >= 0x1F0000) {
LogModule.report(logvisor::Error, "apploader flows into user area (one or the other is too big)"); LogModule.report(logvisor::Error, fmt("apploader flows into user area (one or the other is too big)"));
return false; return false;
} }
m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderName, xferSz); m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderName, xferSz);
@ -1136,7 +1136,7 @@ EBuildResult DiscBuilderWii::buildFromDirectory(SystemStringView dirIn) {
return EBuildResult::Failed; return EBuildResult::Failed;
if (!CheckFreeSpace(m_outPath.c_str(), m_discCapacity)) { if (!CheckFreeSpace(m_outPath.c_str(), m_discCapacity)) {
LogModule.report(logvisor::Error, _SYS_STR("not enough free disk space for %s"), m_outPath.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("not enough free disk space for {}")), m_outPath);
return EBuildResult::DiskFull; return EBuildResult::DiskFull;
} }
m_progressCB(getProgressFactor(), _SYS_STR("Preallocating image"), -1); m_progressCB(getProgressFactor(), _SYS_STR("Preallocating image"), -1);
@ -1155,7 +1155,7 @@ EBuildResult DiscBuilderWii::buildFromDirectory(SystemStringView dirIn) {
if (filledSz == UINT64_MAX) if (filledSz == UINT64_MAX)
return EBuildResult::Failed; return EBuildResult::Failed;
else if (filledSz >= uint64_t(m_discCapacity)) { else if (filledSz >= uint64_t(m_discCapacity)) {
LogModule.report(logvisor::Error, "data partition exceeds disc capacity"); LogModule.report(logvisor::Error, fmt("data partition exceeds disc capacity"));
return EBuildResult::Failed; return EBuildResult::Failed;
} }
@ -1229,7 +1229,7 @@ uint64_t DiscBuilderWii::CalculateTotalSizeRequired(SystemStringView dirIn, bool
sz += 0x200000; sz += 0x200000;
dualLayer = (sz > 0x118240000); dualLayer = (sz > 0x118240000);
if (sz > 0x1FB4E0000) { if (sz > 0x1FB4E0000) {
LogModule.report(logvisor::Error, _SYS_STR("disc capacity exceeded [%" PRIu64 " / %" PRIu64 "]"), sz, 0x1FB4E0000); LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x1FB4E0000);
return UINT64_MAX; return UINT64_MAX;
} }
return sz; return sz;
@ -1251,7 +1251,7 @@ EBuildResult DiscMergerWii::mergeFromDirectory(SystemStringView dirIn) {
return EBuildResult::Failed; return EBuildResult::Failed;
if (!CheckFreeSpace(m_builder.m_outPath.c_str(), m_builder.m_discCapacity)) { if (!CheckFreeSpace(m_builder.m_outPath.c_str(), m_builder.m_discCapacity)) {
LogModule.report(logvisor::Error, _SYS_STR("not enough free disk space for %s"), m_builder.m_outPath.c_str()); LogModule.report(logvisor::Error, fmt(_SYS_STR("not enough free disk space for {}")), m_builder.m_outPath);
return EBuildResult::DiskFull; return EBuildResult::DiskFull;
} }
m_builder.m_progressCB(m_builder.getProgressFactor(), _SYS_STR("Preallocating image"), -1); m_builder.m_progressCB(m_builder.getProgressFactor(), _SYS_STR("Preallocating image"), -1);
@ -1270,7 +1270,7 @@ EBuildResult DiscMergerWii::mergeFromDirectory(SystemStringView dirIn) {
if (filledSz == UINT64_MAX) if (filledSz == UINT64_MAX)
return EBuildResult::Failed; return EBuildResult::Failed;
else if (filledSz >= uint64_t(m_builder.m_discCapacity)) { else if (filledSz >= uint64_t(m_builder.m_discCapacity)) {
LogModule.report(logvisor::Error, "data partition exceeds disc capacity"); LogModule.report(logvisor::Error, fmt("data partition exceeds disc capacity"));
return EBuildResult::Failed; return EBuildResult::Failed;
} }
@ -1337,7 +1337,7 @@ uint64_t DiscMergerWii::CalculateTotalSizeRequired(DiscWii& sourceDisc, SystemSt
sz += 0x200000; sz += 0x200000;
dualLayer = (sz > 0x118240000); dualLayer = (sz > 0x118240000);
if (sz > 0x1FB4E0000) { if (sz > 0x1FB4E0000) {
LogModule.report(logvisor::Error, _SYS_STR("disc capacity exceeded [%" PRIu64 " / %" PRIu64 "]"), sz, 0x1FB4E0000); LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x1FB4E0000);
return UINT64_MAX; return UINT64_MAX;
} }
return sz; return sz;

View File

@ -37,7 +37,7 @@ public:
WriteStream(SystemStringView path, int64_t maxWriteSize, bool& err) : m_maxWriteSize(maxWriteSize) { WriteStream(SystemStringView path, int64_t maxWriteSize, bool& err) : m_maxWriteSize(maxWriteSize) {
fp = Fopen(path.data(), _SYS_STR("wb")); fp = Fopen(path.data(), _SYS_STR("wb"));
if (!fp) { if (!fp) {
LogModule.report(logvisor::Error, _SYS_STR("unable to open '%s' for writing"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '{}' for writing")), path);
err = true; err = true;
} }
} }
@ -53,14 +53,14 @@ public:
FSeek(fp, offset, SEEK_SET); FSeek(fp, offset, SEEK_SET);
return; return;
FailLoc: FailLoc:
LogModule.report(logvisor::Error, _SYS_STR("unable to open '%s' for writing"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '{}' for writing")), path);
err = true; err = true;
} }
~WriteStream() { fclose(fp); } ~WriteStream() { fclose(fp); }
uint64_t write(const void* buf, uint64_t length) { uint64_t write(const void* buf, uint64_t length) {
if (m_maxWriteSize >= 0) { if (m_maxWriteSize >= 0) {
if (FTell(fp) + length > m_maxWriteSize) { if (FTell(fp) + length > m_maxWriteSize) {
LogModule.report(logvisor::Error, _SYS_STR("write operation exceeds file's %" PRIi64 "-byte limit"), LogModule.report(logvisor::Error, fmt(_SYS_STR("write operation exceeds file's {}-byte limit")),
m_maxWriteSize); m_maxWriteSize);
return 0; return 0;
} }
@ -89,7 +89,7 @@ public:
fp = Fopen(path.data(), _SYS_STR("rb")); fp = Fopen(path.data(), _SYS_STR("rb"));
if (!fp) { if (!fp) {
err = true; err = true;
LogModule.report(logvisor::Error, _SYS_STR("unable to open '%s' for reading"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '{}' for reading")), path);
} }
} }
ReadStream(SystemStringView path, uint64_t offset, bool& err) : ReadStream(path, err) { ReadStream(SystemStringView path, uint64_t offset, bool& err) : ReadStream(path, err) {
@ -107,11 +107,11 @@ public:
while (length) { while (length) {
uint64_t thisSz = nod::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
if (read(buf, thisSz) != thisSz) { if (read(buf, thisSz) != thisSz) {
LogModule.report(logvisor::Error, "unable to read enough from file"); LogModule.report(logvisor::Error, fmt("unable to read enough from file"));
return written; return written;
} }
if (discio.write(buf, thisSz) != thisSz) { if (discio.write(buf, thisSz) != thisSz) {
LogModule.report(logvisor::Error, "unable to write enough to disc"); LogModule.report(logvisor::Error, fmt("unable to write enough to disc"));
return written; return written;
} }
length -= thisSz; length -= thisSz;

View File

@ -55,7 +55,7 @@ public:
fp = CreateFile2(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_ALWAYS, nullptr); fp = CreateFile2(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_ALWAYS, nullptr);
#endif #endif
if (fp == INVALID_HANDLE_VALUE) { if (fp == INVALID_HANDLE_VALUE) {
LogModule.report(logvisor::Error, _SYS_STR("unable to open '%s' for writing"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '%s' for writing")), path.data());
err = true; err = true;
} }
} }
@ -68,7 +68,7 @@ public:
fp = CreateFile2(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, OPEN_ALWAYS, nullptr); fp = CreateFile2(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE, OPEN_ALWAYS, nullptr);
#endif #endif
if (fp == INVALID_HANDLE_VALUE) { if (fp == INVALID_HANDLE_VALUE) {
LogModule.report(logvisor::Error, _SYS_STR("unable to open '%s' for writing"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '%s' for writing")), path.data());
err = true; err = true;
return; return;
} }
@ -83,7 +83,7 @@ public:
LARGE_INTEGER res; LARGE_INTEGER res;
SetFilePointerEx(fp, li, &res, FILE_CURRENT); SetFilePointerEx(fp, li, &res, FILE_CURRENT);
if (res.QuadPart + int64_t(length) > m_maxWriteSize) { if (res.QuadPart + int64_t(length) > m_maxWriteSize) {
LogModule.report(logvisor::Error, _SYS_STR("write operation exceeds file's %" PRIi64 "-byte limit"), LogModule.report(logvisor::Error, fmt(_SYS_STR("write operation exceeds file's %" PRIi64 "-byte limit")),
m_maxWriteSize); m_maxWriteSize);
return 0; return 0;
} }
@ -120,7 +120,7 @@ public:
#endif #endif
if (fp == INVALID_HANDLE_VALUE) { if (fp == INVALID_HANDLE_VALUE) {
err = true; err = true;
LogModule.report(logvisor::Error, _SYS_STR("unable to open '%s' for reading"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '%s' for reading")), path.data());
} }
} }
ReadStream(SystemStringView path, uint64_t offset, bool& err) : ReadStream(path, err) { ReadStream(SystemStringView path, uint64_t offset, bool& err) : ReadStream(path, err) {
@ -153,11 +153,11 @@ public:
while (length) { while (length) {
uint64_t thisSz = nod::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
if (read(buf, thisSz) != thisSz) { if (read(buf, thisSz) != thisSz) {
LogModule.report(logvisor::Error, "unable to read enough from file"); LogModule.report(logvisor::Error, fmt("unable to read enough from file"));
return written; return written;
} }
if (discio.write(buf, thisSz) != thisSz) { if (discio.write(buf, thisSz) != thisSz) {
LogModule.report(logvisor::Error, "unable to write enough to disc"); LogModule.report(logvisor::Error, fmt("unable to write enough to disc"));
return written; return written;
} }
length -= thisSz; length -= thisSz;

View File

@ -26,12 +26,12 @@ namespace nod {
static const uint8_t InCo[4] = {0xB, 0xD, 0x9, 0xE}; /* Inverse Coefficients */ static const uint8_t InCo[4] = {0xB, 0xD, 0x9, 0xE}; /* Inverse Coefficients */
static inline uint32_t pack(const uint8_t* b) { static uint32_t pack(const uint8_t* b) {
/* pack bytes into a 32-bit Word */ /* pack bytes into a 32-bit Word */
return ((uint32_t)b[3] << 24) | ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | (uint32_t)b[0]; return ((uint32_t)b[3] << 24) | ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | (uint32_t)b[0];
} }
static inline void unpack(uint32_t a, uint8_t* b) { static void unpack(uint32_t a, uint8_t* b) {
/* unpack bytes from a word */ /* unpack bytes from a word */
b[0] = (uint8_t)a; b[0] = (uint8_t)a;
b[1] = (uint8_t)(a >> 8); b[1] = (uint8_t)(a >> 8);
@ -39,7 +39,7 @@ static inline void unpack(uint32_t a, uint8_t* b) {
b[3] = (uint8_t)(a >> 24); b[3] = (uint8_t)(a >> 24);
} }
static inline uint8_t xtime(uint8_t a) { return ((a << 1) ^ (((a >> 7) & 1) * 0x11B)); } constexpr uint8_t xtime(uint8_t a) { return ((a << 1) ^ (((a >> 7) & 1) * 0x11B)); }
static const struct SoftwareAESTables { static const struct SoftwareAESTables {
uint8_t fbsub[256]; uint8_t fbsub[256];

View File

@ -13,7 +13,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path, bool& isWii)
/* Temporary file handle to determine image type */ /* Temporary file handle to determine image type */
std::unique_ptr<IFileIO> fio = NewFileIO(path); std::unique_ptr<IFileIO> fio = NewFileIO(path);
if (!fio->exists()) { if (!fio->exists()) {
LogModule.report(logvisor::Error, _SYS_STR("Unable to open '%s'"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}'")), path);
return {}; return {};
} }
std::unique_ptr<IFileIO::IReadStream> rs = fio->beginReadStream(); std::unique_ptr<IFileIO::IReadStream> rs = fio->beginReadStream();
@ -24,7 +24,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path, bool& isWii)
std::unique_ptr<IDiscIO> discIO; std::unique_ptr<IDiscIO> discIO;
uint32_t magic = 0; uint32_t magic = 0;
if (rs->read(&magic, 4) != 4) { if (rs->read(&magic, 4) != 4) {
LogModule.report(logvisor::Error, _SYS_STR("Unable to read magic from '%s'"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("Unable to read magic from '{}'")), path);
return {}; return {};
} }
@ -47,7 +47,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path, bool& isWii)
} }
if (!discIO) { if (!discIO) {
LogModule.report(logvisor::Error, _SYS_STR("'%s' is not a valid image"), path.data()); LogModule.report(logvisor::Error, fmt(_SYS_STR("'{}' is not a valid image")), path);
return {}; return {};
} }

@ -1 +1 @@
Subproject commit a0ef17d895ba655ade171f76a984663639a1d390 Subproject commit 3bedd268e86fa8c4e83eb5dd45755732a32acdcd