From 89841125014b0e6008c3e8d8de14d11b59f6e557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 12 Mar 2017 21:12:19 +0100 Subject: [PATCH] IOS/ES: Move GetStoredContentsFromTMD to NandUtils --- Source/Core/Core/IOS/ES/NandUtils.cpp | 28 ++++++++++++++++++ Source/Core/Core/IOS/ES/NandUtils.h | 6 +++- Source/Core/Core/IOS/ES/TitleInformation.cpp | 31 ++------------------ 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Source/Core/Core/IOS/ES/NandUtils.cpp b/Source/Core/Core/IOS/ES/NandUtils.cpp index 6f4df68a21..b30609a255 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.cpp +++ b/Source/Core/Core/IOS/ES/NandUtils.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -11,8 +12,10 @@ #include "Common/FileUtil.h" #include "Common/Logging/Log.h" #include "Common/NandPaths.h" +#include "Common/StringUtil.h" #include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/NandUtils.h" +#include "DiscIO/NANDContentLoader.h" namespace IOS { @@ -133,5 +136,30 @@ std::vector GetTitlesWithTickets() return title_ids; } + +std::vector GetStoredContentsFromTMD(const TMDReader& tmd) +{ + if (!tmd.IsValid()) + return {}; + + const DiscIO::CSharedContent shared{Common::FROM_SESSION_ROOT}; + const std::vector contents = tmd.GetContents(); + + std::vector stored_contents; + + std::copy_if(contents.begin(), contents.end(), std::back_inserter(stored_contents), + [&tmd, &shared](const auto& content) { + if (content.IsShared()) + { + const std::string path = shared.GetFilenameFromSHA1(content.sha1.data()); + return path != "unk" && File::Exists(path); + } + return File::Exists( + Common::GetTitleContentPath(tmd.GetTitleId(), Common::FROM_SESSION_ROOT) + + StringFromFormat("%08x.app", content.id)); + }); + + return stored_contents; +} } // namespace ES } // namespace IOS diff --git a/Source/Core/Core/IOS/ES/NandUtils.h b/Source/Core/Core/IOS/ES/NandUtils.h index ff681ea7fc..d9df9a74f2 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.h +++ b/Source/Core/Core/IOS/ES/NandUtils.h @@ -7,12 +7,14 @@ #include #include "Common/CommonTypes.h" -#include "Core/IOS/ES/Formats.h" namespace IOS { namespace ES { +struct Content; +class TMDReader; + TMDReader FindImportTMD(u64 title_id); TMDReader FindInstalledTMD(u64 title_id); @@ -22,5 +24,7 @@ std::vector GetInstalledTitles(); std::vector GetTitleImports(); // Get titles for which there is a ticket (in /ticket). std::vector GetTitlesWithTickets(); + +std::vector GetStoredContentsFromTMD(const TMDReader& tmd); } // namespace ES } // namespace IOS diff --git a/Source/Core/Core/IOS/ES/TitleInformation.cpp b/Source/Core/Core/IOS/ES/TitleInformation.cpp index 47f0870973..a608764e31 100644 --- a/Source/Core/Core/IOS/ES/TitleInformation.cpp +++ b/Source/Core/Core/IOS/ES/TitleInformation.cpp @@ -4,10 +4,8 @@ #include "Core/IOS/ES/ES.h" -#include #include #include -#include #include #include @@ -26,31 +24,6 @@ namespace HLE { namespace Device { -static std::vector GetStoredContentsFromTMD(const IOS::ES::TMDReader& tmd) -{ - if (!tmd.IsValid()) - return {}; - - const DiscIO::CSharedContent shared{Common::FROM_SESSION_ROOT}; - const std::vector contents = tmd.GetContents(); - - std::vector stored_contents; - - std::copy_if(contents.begin(), contents.end(), std::back_inserter(stored_contents), - [&tmd, &shared](const auto& content) { - if (content.IsShared()) - { - const std::string path = shared.GetFilenameFromSHA1(content.sha1.data()); - return path != "unk" && File::Exists(path); - } - return File::Exists( - Common::GetTitleContentPath(tmd.GetTitleId(), Common::FROM_SESSION_ROOT) + - StringFromFormat("%08x.app", content.id)); - }); - - return stored_contents; -} - // Used by the GetStoredContents ioctlvs. This assumes that the first output vector // is used for the content count (u32). IPCCommandResult ES::GetStoredContentsCount(const IOS::ES::TMDReader& tmd, @@ -59,7 +32,7 @@ IPCCommandResult ES::GetStoredContentsCount(const IOS::ES::TMDReader& tmd, if (request.io_vectors[0].size != sizeof(u32) || !tmd.IsValid()) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - const u16 num_contents = static_cast(GetStoredContentsFromTMD(tmd).size()); + const u16 num_contents = static_cast(IOS::ES::GetStoredContentsFromTMD(tmd).size()); Memory::Write_U32(num_contents, request.io_vectors[0].address); INFO_LOG(IOS_ES, "GetStoredContentsCount (0x%x): %u content(s) for %016" PRIx64, request.request, @@ -80,7 +53,7 @@ IPCCommandResult ES::GetStoredContents(const IOS::ES::TMDReader& tmd, const IOCt return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); } - const auto contents = GetStoredContentsFromTMD(tmd); + const auto contents = IOS::ES::GetStoredContentsFromTMD(tmd); const u32 max_content_count = Memory::Read_U32(request.in_vectors[1].address); for (u32 i = 0; i < std::min(static_cast(contents.size()), max_content_count); ++i) Memory::Write_U32(contents[i].id, request.io_vectors[0].address + i * sizeof(u32));