From 0ed8d681929f4c7ce12377643d1481b9965105fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 12 Mar 2017 21:05:13 +0100 Subject: [PATCH] IOS/ES: Add functions to get TMDs --- Source/Core/Core/IOS/ES/NandUtils.cpp | 23 +++++++++++++++++++++++ Source/Core/Core/IOS/ES/NandUtils.h | 3 +++ 2 files changed, 26 insertions(+) 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.