Replace logvisor with spdlog

This commit is contained in:
2025-04-03 21:06:08 -06:00
parent b513a7f4e0
commit 9584303083
23 changed files with 276 additions and 267 deletions

View File

@@ -9,7 +9,9 @@
#include "nod/aes.hpp"
#include "nod/nod.hpp"
#include "nod/sha1.h"
#include "nod/Util.hpp"
#include "Util.hpp"
#include <spdlog/spdlog.h>
namespace nod {
@@ -421,7 +423,7 @@ public:
uint32_t h3;
if (rs->read(&h3, 4) != 4) {
LogModule.report(logvisor::Error, FMT_STRING("unable to read H3 offset apploader"));
spdlog::error("unable to read H3 offset apploader");
return nullptr;
}
h3 = SBig(h3);
@@ -539,7 +541,7 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio, bool& err) : DiscBase(std::move
kind = part.partType;
break;
default:
LogModule.report(logvisor::Error, FMT_STRING("invalid partition type {}"), part.partType);
spdlog::error("invalid partition type {}", static_cast<uint32_t>(part.partType));
err = true;
return;
}
@@ -557,7 +559,7 @@ bool DiscWii::extractDiscHeaderFiles(std::string_view basePath, const Extraction
std::string basePathStr(basePath);
if (Mkdir((basePathStr + "/disc").c_str(), 0755) && errno != EEXIST) {
LogModule.report(logvisor::Error, FMT_STRING("unable to mkdir '{}/disc'"), basePathStr);
spdlog::error("unable to mkdir '{}/disc'", basePathStr);
return false;
}
@@ -675,7 +677,7 @@ public:
}
if (m_fio->write(m_buf, 0x200000) != 0x200000) {
LogModule.report(logvisor::Error, FMT_STRING("unable to write full disc group"));
spdlog::error("unable to write full disc group");
return;
}
}
@@ -684,7 +686,7 @@ public:
PartWriteStream(PartitionBuilderWii& parent, uint64_t baseOffset, uint64_t offset, bool& err)
: m_parent(parent), m_baseOffset(baseOffset), m_offset(offset) {
if (offset % 0x1F0000) {
LogModule.report(logvisor::Error, FMT_STRING("partition write stream MUST begin on 0x1F0000-aligned boundary"));
spdlog::error("partition write stream MUST begin on 0x1F0000-aligned boundary");
err = true;
return;
}
@@ -754,13 +756,13 @@ public:
uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) override {
reqSz = ROUND_UP_32(reqSz);
if (m_curUser + reqSz >= 0x1FB450000) {
LogModule.report(logvisor::Error, FMT_STRING("partition exceeds maximum single-partition capacity"));
spdlog::error("partition exceeds maximum single-partition capacity");
return -1;
}
uint64_t ret = m_curUser;
PartWriteStream& cws = static_cast<PartWriteStream&>(ws);
if (cws.m_offset > ret) {
LogModule.report(logvisor::Error, FMT_STRING("partition overwrite error"));
spdlog::error("partition overwrite error");
return -1;
}
while (cws.m_offset < ret)
@@ -838,7 +840,7 @@ public:
fstSz = ROUND_UP_32(fstSz);
if (fstOff + fstSz >= 0x1F0000) {
LogModule.report(logvisor::Error, FMT_STRING("FST flows into user area (one or the other is too big)"));
spdlog::error("FST flows into user area (one or the other is too big)");
return -1;
}
@@ -854,7 +856,7 @@ public:
size_t fstOffRel = fstOff - 0x2440;
if (xferSz > fstOffRel) {
LogModule.report(logvisor::Error, FMT_STRING("apploader unexpectedly flows into FST"));
spdlog::error("apploader unexpectedly flows into FST");
return -1;
}
for (size_t i = 0; i < fstOffRel - xferSz; ++i)
@@ -938,7 +940,7 @@ public:
std::string ticketIn = basePath + "/ticket.bin";
Sstat theStat;
if (Stat(ticketIn.c_str(), &theStat)) {
LogModule.report(logvisor::Error, FMT_STRING("unable to stat {}"), ticketIn);
spdlog::error("unable to stat {}", ticketIn);
return -1;
}
@@ -946,7 +948,7 @@ public:
std::string tmdIn = basePath + "/tmd.bin";
Sstat tmdStat;
if (Stat(tmdIn.c_str(), &tmdStat)) {
LogModule.report(logvisor::Error, FMT_STRING("unable to stat {}"), tmdIn);
spdlog::error("unable to stat {}", tmdIn);
return -1;
}
@@ -954,7 +956,7 @@ public:
std::string certIn = basePath + "/cert.bin";
Sstat certStat;
if (Stat(certIn.c_str(), &certStat)) {
LogModule.report(logvisor::Error, FMT_STRING("unable to stat {}"), certIn);
spdlog::error("unable to stat {}", certIn);
return -1;
}
@@ -962,7 +964,7 @@ public:
std::string apploaderIn = basePath + "/sys/apploader.img";
Sstat apploaderStat;
if (Stat(apploaderIn.c_str(), &apploaderStat)) {
LogModule.report(logvisor::Error, FMT_STRING("unable to stat {}"), apploaderIn);
spdlog::error("unable to stat {}", apploaderIn);
return -1;
}
@@ -970,7 +972,7 @@ public:
std::string bootIn = basePath + "/sys/boot.bin";
Sstat bootStat;
if (Stat(bootIn.c_str(), &bootStat)) {
LogModule.report(logvisor::Error, FMT_STRING("unable to stat {}"), bootIn);
spdlog::error("unable to stat {}", bootIn);
return -1;
}
@@ -978,7 +980,7 @@ public:
std::string bi2In = basePath + "/sys/bi2.bin";
Sstat bi2Stat;
if (Stat(bi2In.c_str(), &bi2Stat)) {
LogModule.report(logvisor::Error, FMT_STRING("unable to stat {}"), bi2In);
spdlog::error("unable to stat {}", bi2In);
return -1;
}
@@ -1071,7 +1073,7 @@ public:
cws.write(buf, rdSz);
xferSz += rdSz;
if (0x2440 + xferSz >= 0x1F0000) {
LogModule.report(logvisor::Error, FMT_STRING("apploader flows into user area (one or the other is too big)"));
spdlog::error("apploader flows into user area (one or the other is too big)");
return false;
}
m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderIn, xferSz);
@@ -1129,7 +1131,7 @@ public:
cws.write(apploaderBuf.get(), apploaderSz);
xferSz += apploaderSz;
if (0x2440 + xferSz >= 0x1F0000) {
LogModule.report(logvisor::Error, FMT_STRING("apploader flows into user area (one or the other is too big)"));
spdlog::error("apploader flows into user area (one or the other is too big)");
return false;
}
m_parent.m_progressCB(m_parent.getProgressFactor(), apploaderName, xferSz);
@@ -1153,7 +1155,7 @@ EBuildResult DiscBuilderWii::buildFromDirectory(std::string_view dirIn) {
return EBuildResult::Failed;
if (!CheckFreeSpace(m_outPath.c_str(), m_discCapacity)) {
LogModule.report(logvisor::Error, FMT_STRING("not enough free disk space for {}"), m_outPath);
spdlog::error("not enough free disk space for {}", m_outPath);
return EBuildResult::DiskFull;
}
m_progressCB(getProgressFactor(), "Preallocating image", -1);
@@ -1172,7 +1174,7 @@ EBuildResult DiscBuilderWii::buildFromDirectory(std::string_view dirIn) {
if (filledSz == UINT64_MAX)
return EBuildResult::Failed;
else if (filledSz >= uint64_t(m_discCapacity)) {
LogModule.report(logvisor::Error, FMT_STRING("data partition exceeds disc capacity"));
spdlog::error("data partition exceeds disc capacity");
return EBuildResult::Failed;
}
@@ -1246,7 +1248,7 @@ std::optional<uint64_t> DiscBuilderWii::CalculateTotalSizeRequired(std::string_v
*sz += 0x200000;
dualLayer = (sz > 0x118240000);
if (sz > 0x1FB4E0000) {
LogModule.report(logvisor::Error, FMT_STRING("disc capacity exceeded [{} / {}]"), *sz, 0x1FB4E0000);
spdlog::error("disc capacity exceeded [{} / {}]", *sz, 0x1FB4E0000);
return std::nullopt;
}
return sz;
@@ -1267,7 +1269,7 @@ EBuildResult DiscMergerWii::mergeFromDirectory(std::string_view dirIn) {
return EBuildResult::Failed;
if (!CheckFreeSpace(m_builder.m_outPath.c_str(), m_builder.m_discCapacity)) {
LogModule.report(logvisor::Error, FMT_STRING("not enough free disk space for {}"), m_builder.m_outPath);
spdlog::error("not enough free disk space for {}", m_builder.m_outPath);
return EBuildResult::DiskFull;
}
m_builder.m_progressCB(m_builder.getProgressFactor(), "Preallocating image", -1);
@@ -1286,7 +1288,7 @@ EBuildResult DiscMergerWii::mergeFromDirectory(std::string_view dirIn) {
if (filledSz == UINT64_MAX)
return EBuildResult::Failed;
else if (filledSz >= uint64_t(m_builder.m_discCapacity)) {
LogModule.report(logvisor::Error, FMT_STRING("data partition exceeds disc capacity"));
spdlog::error("data partition exceeds disc capacity");
return EBuildResult::Failed;
}
@@ -1353,7 +1355,7 @@ std::optional<uint64_t> DiscMergerWii::CalculateTotalSizeRequired(DiscWii& sourc
*sz += 0x200000;
dualLayer = (sz > 0x118240000);
if (sz > 0x1FB4E0000) {
LogModule.report(logvisor::Error, FMT_STRING("disc capacity exceeded [{} / {}]"), *sz, 0x1FB4E0000);
spdlog::error("disc capacity exceeded [{} / {}]", *sz, 0x1FB4E0000);
return std::nullopt;
}
return sz;