diff --git a/src/common/io_file.h b/src/common/io_file.h index 177bddba..8fed4981 100644 --- a/src/common/io_file.h +++ b/src/common/io_file.h @@ -205,9 +205,9 @@ public: return WriteSpan(string); } - static void WriteBytes(const std::filesystem::path path, std::span data) { + static size_t WriteBytes(const std::filesystem::path path, std::span data) { IOFile out(path, FileAccessMode::Write); - out.Write(data); + return out.Write(data); } private: diff --git a/src/core/file_format/trp.cpp b/src/core/file_format/trp.cpp index 929136bc..2ca88c77 100644 --- a/src/core/file_format/trp.cpp +++ b/src/core/file_format/trp.cpp @@ -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))) { @@ -35,6 +36,7 @@ static void removePadding(std::vector& vec) { bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string titleId) { 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)) { @@ -43,13 +45,16 @@ bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string tit 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( @@ -98,7 +103,14 @@ bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string tit 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); + std::filesystem::path path = trpFilesPath / "Xml" / xml_name; + size_t written = Common::FS::IOFile::WriteBytes(path, XML); + if (written != XML.size()) { + LOG_CRITICAL( + Common_Filesystem, + "Trophy XML {} write failed, wanted to write {} bytes, wrote {}", + fmt::UTF(path.u8string()), XML.size(), written); + } } } } diff --git a/src/core/libraries/np_trophy/np_trophy.cpp b/src/core/libraries/np_trophy/np_trophy.cpp index 0641a2c0..d759b7a2 100644 --- a/src/core/libraries/np_trophy/np_trophy.cpp +++ b/src/core/libraries/np_trophy/np_trophy.cpp @@ -966,7 +966,7 @@ int PS4_SYSV_ABI sceNpTrophyUnlockTrophy(OrbisNpTrophyContext context, OrbisNpTr } } - doc.save_file((trophy_dir.string() + "/trophy00/Xml/TROP.XML").c_str()); + doc.save_file((trophy_dir / "trophy00" / "Xml" / "TROP.XML").native().c_str()); return ORBIS_OK; } diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index 740bd3a1..618f8db4 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -16,12 +16,13 @@ std::optional current_trophy_ui; std::queue trophy_queue; std::mutex queueMtx; -TrophyUI::TrophyUI(std::filesystem::path trophyIconPath, std::string trophyName) +TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::string& trophyName) : trophy_name(trophyName) { if (std::filesystem::exists(trophyIconPath)) { trophy_icon = RefCountedTexture::DecodePngFile(trophyIconPath); } else { - LOG_ERROR(Lib_NpTrophy, "Couldnt load trophy icon at {}", trophyIconPath.string()); + LOG_ERROR(Lib_NpTrophy, "Couldnt load trophy icon at {}", + fmt::UTF(trophyIconPath.u8string())); } AddLayer(this); } @@ -66,7 +67,7 @@ void TrophyUI::Draw() { trophy_timer -= io.DeltaTime; if (trophy_timer <= 0) { - queueMtx.lock(); + std::lock_guard lock(queueMtx); if (!trophy_queue.empty()) { TrophyInfo next_trophy = trophy_queue.front(); trophy_queue.pop(); @@ -74,12 +75,11 @@ void TrophyUI::Draw() { } else { current_trophy_ui.reset(); } - queueMtx.unlock(); } } -void AddTrophyToQueue(std::filesystem::path trophyIconPath, std::string trophyName) { - queueMtx.lock(); +void AddTrophyToQueue(const std::filesystem::path& trophyIconPath, const std::string& trophyName) { + std::lock_guard lock(queueMtx); if (current_trophy_ui.has_value()) { TrophyInfo new_trophy; new_trophy.trophy_icon_path = trophyIconPath; @@ -88,7 +88,6 @@ void AddTrophyToQueue(std::filesystem::path trophyIconPath, std::string trophyNa } else { current_trophy_ui.emplace(trophyIconPath, trophyName); } - queueMtx.unlock(); } } // namespace Libraries::NpTrophy \ No newline at end of file diff --git a/src/core/libraries/np_trophy/trophy_ui.h b/src/core/libraries/np_trophy/trophy_ui.h index 4448c228..ce7a1c63 100644 --- a/src/core/libraries/np_trophy/trophy_ui.h +++ b/src/core/libraries/np_trophy/trophy_ui.h @@ -17,7 +17,7 @@ namespace Libraries::NpTrophy { class TrophyUI final : public ImGui::Layer { public: - TrophyUI(std::filesystem::path trophyIconPath, std::string trophyName); + TrophyUI(const std::filesystem::path& trophyIconPath, const std::string& trophyName); ~TrophyUI() override; void Finish(); @@ -35,6 +35,6 @@ struct TrophyInfo { std::string trophy_name; }; -void AddTrophyToQueue(std::filesystem::path trophyIconPath, std::string trophyName); +void AddTrophyToQueue(const std::filesystem::path& trophyIconPath, const std::string& trophyName); }; // namespace Libraries::NpTrophy \ No newline at end of file diff --git a/src/qt_gui/check_update.cpp b/src/qt_gui/check_update.cpp index b92974ba..023c6e7b 100644 --- a/src/qt_gui/check_update.cpp +++ b/src/qt_gui/check_update.cpp @@ -343,8 +343,8 @@ void CheckUpdate::DownloadUpdate(const QString& url) { return; } - QString userPath = - QString::fromStdString(Common::FS::GetUserPath(Common::FS::PathType::UserDir).string()); + QString userPath; + Common::FS::PathToQString(userPath, Common::FS::GetUserPath(Common::FS::PathType::UserDir)); QString tempDownloadPath = userPath + "/temp_download_update"; QDir dir(tempDownloadPath); if (!dir.exists()) { @@ -371,12 +371,13 @@ void CheckUpdate::DownloadUpdate(const QString& url) { } void CheckUpdate::Install() { - QString userPath = - QString::fromStdString(Common::FS::GetUserPath(Common::FS::PathType::UserDir).string()); + QString userPath; + Common::FS::PathToQString(userPath, Common::FS::GetUserPath(Common::FS::PathType::UserDir)); QString startingUpdate = tr("Starting Update..."); QString tempDirPath = userPath + "/temp_download_update"; - QString rootPath = QString::fromStdString(std::filesystem::current_path().string()); + QString rootPath; + Common::FS::PathToQString(rootPath, std::filesystem::current_path()); QString scriptContent; QString scriptFileName;