diff --git a/Source/Core/Core/IOS/ES/NandUtils.cpp b/Source/Core/Core/IOS/ES/NandUtils.cpp index 15a313c94d..6f4df68a21 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.cpp +++ b/Source/Core/Core/IOS/ES/NandUtils.cpp @@ -18,6 +18,29 @@ namespace IOS { namespace ES { +static TMDReader FindTMD(u64 title_id, const std::string& tmd_path) +{ + File::IOFile file(tmd_path, "rb"); + if (!file) + return {}; + + std::vector tmd_bytes(file.GetSize()); + if (!file.ReadBytes(tmd_bytes.data(), tmd_bytes.size())) + return {}; + + return TMDReader{std::move(tmd_bytes)}; +} + +TMDReader FindImportTMD(u64 title_id) +{ + return FindTMD(title_id, Common::GetImportTitlePath(title_id) + "/content/title.tmd"); +} + +TMDReader FindInstalledTMD(u64 title_id) +{ + return FindTMD(title_id, Common::GetTMDFileName(title_id, Common::FROM_SESSION_ROOT)); +} + static bool IsValidPartOfTitleID(const std::string& string) { if (string.length() != 8) diff --git a/Source/Core/Core/IOS/ES/NandUtils.h b/Source/Core/Core/IOS/ES/NandUtils.h index 0cd9363290..ff681ea7fc 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.h +++ b/Source/Core/Core/IOS/ES/NandUtils.h @@ -13,6 +13,9 @@ namespace IOS { namespace ES { +TMDReader FindImportTMD(u64 title_id); +TMDReader FindInstalledTMD(u64 title_id); + // Get installed titles (in /title) without checking for TMDs at all. std::vector GetInstalledTitles(); // Get titles which are being imported (in /import) without checking for TMDs at all.