Add some more logging

This commit is contained in:
offtkp 2024-10-02 03:56:59 +03:00
parent 62077b654f
commit b58b9a251f
2 changed files with 15 additions and 4 deletions

View file

@ -205,9 +205,9 @@ public:
return WriteSpan(string);
}
static void WriteBytes(const std::filesystem::path path, std::span<const u8> data) {
static size_t WriteBytes(const std::filesystem::path path, std::span<const u8> data) {
IOFile out(path, FileAccessMode::Write);
out.Write(data);
return out.Write(data);
}
private:

View file

@ -12,6 +12,7 @@ void TRP::GetNPcommID(const std::filesystem::path& trophyPath, int index) {
std::filesystem::path trpPath = trophyPath / "sce_sys/npbind.dat";
Common::FS::IOFile npbindFile(trpPath, Common::FS::FileAccessMode::Read);
if (!npbindFile.IsOpen()) {
LOG_CRITICAL(Common_Filesystem, "Failed to open npbind.dat file");
return;
}
if (!npbindFile.Seek(0x84 + (index * 0x180))) {
@ -36,6 +37,7 @@ bool TRP::Extract(const std::filesystem::path& trophyPath) {
std::filesystem::path title = trophyPath.filename();
std::filesystem::path gameSysDir = trophyPath / "sce_sys/trophy/";
if (!std::filesystem::exists(gameSysDir)) {
LOG_CRITICAL(Common_Filesystem, "Game sce_sys directory doesn't exist");
return false;
}
for (int index = 0; const auto& it : std::filesystem::directory_iterator(gameSysDir)) {
@ -44,13 +46,16 @@ bool TRP::Extract(const std::filesystem::path& trophyPath) {
Common::FS::IOFile file(it.path(), Common::FS::FileAccessMode::Read);
if (!file.IsOpen()) {
LOG_CRITICAL(Common_Filesystem, "Unable to open trophy file for read");
return false;
}
TrpHeader header;
file.Read(header);
if (header.magic != 0xDCA24D00)
if (header.magic != 0xDCA24D00) {
LOG_CRITICAL(Common_Filesystem, "Wrong trophy magic number");
return false;
}
s64 seekPos = sizeof(TrpHeader);
std::filesystem::path trpFilesPath(
@ -99,7 +104,13 @@ bool TRP::Extract(const std::filesystem::path& trophyPath) {
size_t pos = xml_name.find("ESFM");
if (pos != std::string::npos)
xml_name.replace(pos, xml_name.length(), "XML");
Common::FS::IOFile::WriteBytes(trpFilesPath / "Xml" / xml_name, XML);
size_t written =
Common::FS::IOFile::WriteBytes(trpFilesPath / "Xml" / xml_name, XML);
if (written != XML.size()) {
LOG_CRITICAL(Common_Filesystem,
"Trophy XML write failed, wanted to write {} bytes, wrote {}",
XML.size(), written);
}
}
}
}