From 932eeefff0f5c8eed6673a3f1ae164cbeebe4e62 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Thu, 5 Jul 2018 20:34:55 -0700 Subject: [PATCH 1/8] am: Correct definition of ContentInfo. --- src/core/hle/service/am/am.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 66a38544b..89aa07ceb 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -49,12 +49,16 @@ struct TitleInfo { static_assert(sizeof(TitleInfo) == 0x18, "Title info structure size is wrong"); +constexpr u8 OWNERSHIP_DOWNLOADED = 0x01; +constexpr u8 OWNERSHIP_OWNED = 0x02; + struct ContentInfo { u16_le index; u16_le type; u32_le content_id; u64_le size; - u64_le romfs_size; + u8 ownership; + INSERT_PADDING_BYTES(0x7); }; static_assert(sizeof(ContentInfo) == 0x18, "Content info structure size is wrong"); @@ -520,17 +524,17 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { for (size_t i = 0; i < content_count; i++) { std::shared_ptr romfs_file; u64 romfs_offset = 0; - u64 romfs_size = 0; - - FileSys::NCCHContainer ncch_container(GetTitleContentPath(media_type, title_id, i)); - ncch_container.ReadRomFS(romfs_file, romfs_offset, romfs_size); ContentInfo content_info = {}; content_info.index = static_cast(i); content_info.type = tmd.GetContentTypeByIndex(content_requested[i]); content_info.content_id = tmd.GetContentIDByIndex(content_requested[i]); content_info.size = tmd.GetContentSizeByIndex(content_requested[i]); - content_info.romfs_size = romfs_size; + content_info.ownership = OWNERSHIP_OWNED; // TODO: Pull this from the ticket. + + if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, content_requested[i]))) { + content_info.ownership |= OWNERSHIP_DOWNLOADED; + } content_info_out.Write(&content_info, write_offset, sizeof(ContentInfo)); write_offset += sizeof(ContentInfo); @@ -574,17 +578,17 @@ void Module::Interface::ListDLCContentInfos(Kernel::HLERequestContext& ctx) { for (u32 i = start_index; i < copied; i++) { std::shared_ptr romfs_file; u64 romfs_offset = 0; - u64 romfs_size = 0; - - FileSys::NCCHContainer ncch_container(GetTitleContentPath(media_type, title_id, i)); - ncch_container.ReadRomFS(romfs_file, romfs_offset, romfs_size); ContentInfo content_info = {}; content_info.index = static_cast(i); content_info.type = tmd.GetContentTypeByIndex(i); content_info.content_id = tmd.GetContentIDByIndex(i); content_info.size = tmd.GetContentSizeByIndex(i); - content_info.romfs_size = romfs_size; + content_info.ownership = OWNERSHIP_OWNED; // TODO: Pull this from the ticket. + + if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, i))) { + content_info.ownership |= OWNERSHIP_DOWNLOADED; + } content_info_out.Write(&content_info, write_offset, sizeof(ContentInfo)); write_offset += sizeof(ContentInfo); From 630a1311cadef318a891193ca3288ffb10d92dd5 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 6 Jul 2018 00:44:22 -0700 Subject: [PATCH 2/8] am: Properly handle operations involving content indices. --- src/core/file_sys/archive_ncch.cpp | 2 +- src/core/file_sys/cia_container.cpp | 2 +- src/core/file_sys/title_metadata.cpp | 14 ++++++++++++++ src/core/file_sys/title_metadata.h | 5 +++++ src/core/hle/service/am/am.cpp | 28 +++++++++++++++++++++------- src/core/hle/service/am/am.h | 2 +- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 10a344366..b52957d3f 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -63,7 +63,7 @@ ResultVal> NCCHArchive::OpenFile(const Path& path, std::memcpy(&openfile_path, binary.data(), sizeof(NCCHFilePath)); std::string file_path = - Service::AM::GetTitleContentPath(media_type, title_id, openfile_path.content_index); + Service::AM::GetTitleContentPath(media_type, title_id, openfile_path.content_index, false, true); auto ncch_container = NCCHContainer(file_path); Loader::ResultStatus result; diff --git a/src/core/file_sys/cia_container.cpp b/src/core/file_sys/cia_container.cpp index 69abbff23..f4bce8b02 100644 --- a/src/core/file_sys/cia_container.cpp +++ b/src/core/file_sys/cia_container.cpp @@ -201,7 +201,7 @@ u64 CIAContainer::GetTotalContentSize() const { u64 CIAContainer::GetContentSize(u16 index) const { // If the content doesn't exist in the CIA, it doesn't have a size. - if (!cia_header.isContentPresent(index)) + if (!cia_header.isContentPresent(cia_tmd.GetContentIndexByIndex(index))) return 0; return cia_tmd.GetContentSizeByIndex(index); diff --git a/src/core/file_sys/title_metadata.cpp b/src/core/file_sys/title_metadata.cpp index 8e0b6b30f..4122d5f8d 100644 --- a/src/core/file_sys/title_metadata.cpp +++ b/src/core/file_sys/title_metadata.cpp @@ -86,6 +86,7 @@ Loader::ResultStatus TitleMetadata::Load(const std::vector file_data, size_t memcpy(&chunk, &file_data[offset + body_end + (i * sizeof(ContentChunk))], sizeof(ContentChunk)); tmd_chunks.push_back(chunk); + content_index_to_index[chunk.index] = tmd_chunks.size() - 1; } return Loader::ResultStatus::Success; @@ -180,6 +181,10 @@ u32 TitleMetadata::GetContentIDByIndex(u16 index) const { return tmd_chunks[index].id; } +u16 TitleMetadata::GetContentIndexByIndex(u16 index) const { + return tmd_chunks[index].index; +} + u16 TitleMetadata::GetContentTypeByIndex(u16 index) const { return tmd_chunks[index].type; } @@ -188,6 +193,14 @@ u64 TitleMetadata::GetContentSizeByIndex(u16 index) const { return tmd_chunks[index].size; } +bool TitleMetadata::ContentIndexExists(u16 contentIndex) const { + return content_index_to_index.find(contentIndex) != content_index_to_index.end(); +} + +u16 TitleMetadata::ContentIndexToIndex(u16 contentIndex) const { + return content_index_to_index.at(contentIndex); +} + void TitleMetadata::SetTitleID(u64 title_id) { tmd_body.title_id = title_id; } @@ -206,6 +219,7 @@ void TitleMetadata::SetSystemVersion(u64 version) { void TitleMetadata::AddContentChunk(const ContentChunk& chunk) { tmd_chunks.push_back(chunk); + content_index_to_index[chunk.index] = tmd_chunks.size() - 1; } void TitleMetadata::Print() const { diff --git a/src/core/file_sys/title_metadata.h b/src/core/file_sys/title_metadata.h index 1d2302e0e..d9d32a5fe 100644 --- a/src/core/file_sys/title_metadata.h +++ b/src/core/file_sys/title_metadata.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "common/common_types.h" @@ -106,8 +107,11 @@ public: u32 GetManualContentID() const; u32 GetDLPContentID() const; u32 GetContentIDByIndex(u16 index) const; + u16 GetContentIndexByIndex(u16 index) const; u16 GetContentTypeByIndex(u16 index) const; u64 GetContentSizeByIndex(u16 index) const; + bool ContentIndexExists(u16 contentIndex) const; + u16 ContentIndexToIndex(u16 contentIndex) const; void SetTitleID(u64 title_id); void SetTitleType(u32 type); @@ -122,6 +126,7 @@ private: u32_be signature_type; std::vector tmd_signature; std::vector tmd_chunks; + std::map content_index_to_index; }; } // namespace FileSys diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 89aa07ceb..ef38540ec 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -384,7 +384,7 @@ std::string GetTitleMetadataPath(Service::FS::MediaType media_type, u64 tid, boo } std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 index, - bool update) { + bool update, bool contentIndex) { std::string content_path = GetTitlePath(media_type, tid) + "content/"; if (media_type == Service::FS::MediaType::GameCard) { @@ -399,6 +399,10 @@ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 u32 content_id = 0; FileSys::TitleMetadata tmd; if (tmd.Load(tmd_path) == Loader::ResultStatus::Success) { + if(contentIndex && tmd.ContentIndexExists(index)) { + index = tmd.ContentIndexToIndex(index); + } + content_id = tmd.GetContentIDByIndex(index); // TODO(shinyquagsire23): how does DLC actually get this folder on hardware? @@ -525,14 +529,24 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { std::shared_ptr romfs_file; u64 romfs_offset = 0; + if (!tmd.ContentIndexExists(content_requested[i])) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); + rb.Push(-1); // TODO: Find the right error code + rb.PushMappedBuffer(content_requested_in); + rb.PushMappedBuffer(content_info_out); + return; + } + + u16 index = tmd.ContentIndexToIndex(content_requested[i]); + ContentInfo content_info = {}; content_info.index = static_cast(i); - content_info.type = tmd.GetContentTypeByIndex(content_requested[i]); - content_info.content_id = tmd.GetContentIDByIndex(content_requested[i]); - content_info.size = tmd.GetContentSizeByIndex(content_requested[i]); + content_info.type = tmd.GetContentTypeByIndex(index); + content_info.content_id = tmd.GetContentIDByIndex(index); + content_info.size = tmd.GetContentSizeByIndex(index); content_info.ownership = OWNERSHIP_OWNED; // TODO: Pull this from the ticket. - if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, content_requested[i]))) { + if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, index))) { content_info.ownership |= OWNERSHIP_DOWNLOADED; } @@ -917,7 +931,7 @@ void Module::Interface::CheckContentRights(Kernel::HLERequestContext& ctx) { // TODO(shinyquagsire23): Read tickets for this instead? bool has_rights = - FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index)); + FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index, false, true)); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); // No error @@ -933,7 +947,7 @@ void Module::Interface::CheckContentRightsIgnorePlatform(Kernel::HLERequestConte // TODO(shinyquagsire23): Read tickets for this instead? bool has_rights = - FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index)); + FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index, false, true)); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); // No error diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 40414b6d6..53d8ea3a7 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -124,7 +124,7 @@ std::string GetTitleMetadataPath(Service::FS::MediaType media_type, u64 tid, boo * @returns string path to the .app file */ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 index = 0, - bool update = false); + bool update = false, bool contentIndex = false); /** * Get the folder for a title's installed content. From c1ef7a753a0e93abdb9787aa0179921daffe06e1 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 6 Jul 2018 10:47:50 -0700 Subject: [PATCH 3/8] am: Add contentIndex to documentation for GetTitleContentPath. --- src/core/hle/service/am/am.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 53d8ea3a7..7663f8c4f 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -121,6 +121,7 @@ std::string GetTitleMetadataPath(Service::FS::MediaType media_type, u64 tid, boo * @param tid the title ID to get * @param index the content index to get * @param update set true if the incoming TMD should be used instead of the current TMD + * @param contentIndex set true if the supplied index is a 3DS content index value instead of a raw index. * @returns string path to the .app file */ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 index = 0, From 142c2b6cfe716e27ecdb4d4d5bc77e374a2b1293 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 6 Jul 2018 10:49:13 -0700 Subject: [PATCH 4/8] am: Correct content index bounds in ListDLCContentInfos. --- src/core/hle/service/am/am.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index ef38540ec..e20587b6a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -589,7 +589,7 @@ void Module::Interface::ListDLCContentInfos(Kernel::HLERequestContext& ctx) { if (tmd.Load(tmd_path) == Loader::ResultStatus::Success) { copied = std::min(content_count, static_cast(tmd.GetContentCount())); std::size_t write_offset = 0; - for (u32 i = start_index; i < copied; i++) { + for (u32 i = start_index; i < start_index + copied; i++) { std::shared_ptr romfs_file; u64 romfs_offset = 0; From 680c6e694db6f41ad886b9000348c831677494ee Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 6 Jul 2018 11:00:57 -0700 Subject: [PATCH 5/8] am: Correct reported DLC content indices. --- src/core/hle/service/am/am.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index e20587b6a..7f947dd59 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -540,7 +540,7 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { u16 index = tmd.ContentIndexToIndex(content_requested[i]); ContentInfo content_info = {}; - content_info.index = static_cast(i); + content_info.index = content_requested[i]; content_info.type = tmd.GetContentTypeByIndex(index); content_info.content_id = tmd.GetContentIDByIndex(index); content_info.size = tmd.GetContentSizeByIndex(index); @@ -594,7 +594,7 @@ void Module::Interface::ListDLCContentInfos(Kernel::HLERequestContext& ctx) { u64 romfs_offset = 0; ContentInfo content_info = {}; - content_info.index = static_cast(i); + content_info.index = tmd.GetContentIndexByIndex(i); content_info.type = tmd.GetContentTypeByIndex(i); content_info.content_id = tmd.GetContentIDByIndex(i); content_info.size = tmd.GetContentSizeByIndex(i); From d67f119589191e8699db5fd0981d1b48580b1969 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 6 Jul 2018 14:16:15 -0700 Subject: [PATCH 6/8] am: Address review comments. --- src/core/file_sys/title_metadata.h | 4 ++-- src/core/hle/service/am/am.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/file_sys/title_metadata.h b/src/core/file_sys/title_metadata.h index d9d32a5fe..11a93349a 100644 --- a/src/core/file_sys/title_metadata.h +++ b/src/core/file_sys/title_metadata.h @@ -5,8 +5,8 @@ #pragma once #include -#include #include +#include #include #include "common/common_types.h" #include "common/swap.h" @@ -126,7 +126,7 @@ private: u32_be signature_type; std::vector tmd_signature; std::vector tmd_chunks; - std::map content_index_to_index; + std::unordered_map content_index_to_index; }; } // namespace FileSys diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 7f947dd59..f962bd7a4 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -399,8 +399,12 @@ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 u32 content_id = 0; FileSys::TitleMetadata tmd; if (tmd.Load(tmd_path) == Loader::ResultStatus::Success) { - if(contentIndex && tmd.ContentIndexExists(index)) { - index = tmd.ContentIndexToIndex(index); + if(contentIndex) { + if(tmd.ContentIndexExists(index)) { + index = tmd.ContentIndexToIndex(index); + } else { + LOG_ERROR(Service_AM, "Attempted to get path for non-existent content index {:04x}.", index); + } } content_id = tmd.GetContentIDByIndex(index); @@ -530,6 +534,8 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { u64 romfs_offset = 0; if (!tmd.ContentIndexExists(content_requested[i])) { + LOG_ERROR(Service_AM, "Attempted to get info for non-existent content index {:04x}.", content_requested[i]); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); rb.Push(-1); // TODO: Find the right error code rb.PushMappedBuffer(content_requested_in); From ba350794492bbe2db6486a06e3d2d51a5a2de56a Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 6 Jul 2018 17:15:30 -0700 Subject: [PATCH 7/8] am: Revert changes to content index handling. --- src/core/file_sys/archive_ncch.cpp | 2 +- src/core/file_sys/cia_container.cpp | 2 +- src/core/file_sys/title_metadata.cpp | 14 ------------ src/core/file_sys/title_metadata.h | 5 ----- src/core/hle/service/am/am.cpp | 32 +++++++++++----------------- src/core/hle/service/am/am.h | 3 +-- 6 files changed, 16 insertions(+), 42 deletions(-) diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index b52957d3f..10a344366 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -63,7 +63,7 @@ ResultVal> NCCHArchive::OpenFile(const Path& path, std::memcpy(&openfile_path, binary.data(), sizeof(NCCHFilePath)); std::string file_path = - Service::AM::GetTitleContentPath(media_type, title_id, openfile_path.content_index, false, true); + Service::AM::GetTitleContentPath(media_type, title_id, openfile_path.content_index); auto ncch_container = NCCHContainer(file_path); Loader::ResultStatus result; diff --git a/src/core/file_sys/cia_container.cpp b/src/core/file_sys/cia_container.cpp index f4bce8b02..69abbff23 100644 --- a/src/core/file_sys/cia_container.cpp +++ b/src/core/file_sys/cia_container.cpp @@ -201,7 +201,7 @@ u64 CIAContainer::GetTotalContentSize() const { u64 CIAContainer::GetContentSize(u16 index) const { // If the content doesn't exist in the CIA, it doesn't have a size. - if (!cia_header.isContentPresent(cia_tmd.GetContentIndexByIndex(index))) + if (!cia_header.isContentPresent(index)) return 0; return cia_tmd.GetContentSizeByIndex(index); diff --git a/src/core/file_sys/title_metadata.cpp b/src/core/file_sys/title_metadata.cpp index 4122d5f8d..8e0b6b30f 100644 --- a/src/core/file_sys/title_metadata.cpp +++ b/src/core/file_sys/title_metadata.cpp @@ -86,7 +86,6 @@ Loader::ResultStatus TitleMetadata::Load(const std::vector file_data, size_t memcpy(&chunk, &file_data[offset + body_end + (i * sizeof(ContentChunk))], sizeof(ContentChunk)); tmd_chunks.push_back(chunk); - content_index_to_index[chunk.index] = tmd_chunks.size() - 1; } return Loader::ResultStatus::Success; @@ -181,10 +180,6 @@ u32 TitleMetadata::GetContentIDByIndex(u16 index) const { return tmd_chunks[index].id; } -u16 TitleMetadata::GetContentIndexByIndex(u16 index) const { - return tmd_chunks[index].index; -} - u16 TitleMetadata::GetContentTypeByIndex(u16 index) const { return tmd_chunks[index].type; } @@ -193,14 +188,6 @@ u64 TitleMetadata::GetContentSizeByIndex(u16 index) const { return tmd_chunks[index].size; } -bool TitleMetadata::ContentIndexExists(u16 contentIndex) const { - return content_index_to_index.find(contentIndex) != content_index_to_index.end(); -} - -u16 TitleMetadata::ContentIndexToIndex(u16 contentIndex) const { - return content_index_to_index.at(contentIndex); -} - void TitleMetadata::SetTitleID(u64 title_id) { tmd_body.title_id = title_id; } @@ -219,7 +206,6 @@ void TitleMetadata::SetSystemVersion(u64 version) { void TitleMetadata::AddContentChunk(const ContentChunk& chunk) { tmd_chunks.push_back(chunk); - content_index_to_index[chunk.index] = tmd_chunks.size() - 1; } void TitleMetadata::Print() const { diff --git a/src/core/file_sys/title_metadata.h b/src/core/file_sys/title_metadata.h index 11a93349a..1d2302e0e 100644 --- a/src/core/file_sys/title_metadata.h +++ b/src/core/file_sys/title_metadata.h @@ -6,7 +6,6 @@ #include #include -#include #include #include "common/common_types.h" #include "common/swap.h" @@ -107,11 +106,8 @@ public: u32 GetManualContentID() const; u32 GetDLPContentID() const; u32 GetContentIDByIndex(u16 index) const; - u16 GetContentIndexByIndex(u16 index) const; u16 GetContentTypeByIndex(u16 index) const; u64 GetContentSizeByIndex(u16 index) const; - bool ContentIndexExists(u16 contentIndex) const; - u16 ContentIndexToIndex(u16 contentIndex) const; void SetTitleID(u64 title_id); void SetTitleType(u32 type); @@ -126,7 +122,6 @@ private: u32_be signature_type; std::vector tmd_signature; std::vector tmd_chunks; - std::unordered_map content_index_to_index; }; } // namespace FileSys diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index f962bd7a4..e22cbace4 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -384,7 +384,7 @@ std::string GetTitleMetadataPath(Service::FS::MediaType media_type, u64 tid, boo } std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 index, - bool update, bool contentIndex) { + bool update) { std::string content_path = GetTitlePath(media_type, tid) + "content/"; if (media_type == Service::FS::MediaType::GameCard) { @@ -399,16 +399,12 @@ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 u32 content_id = 0; FileSys::TitleMetadata tmd; if (tmd.Load(tmd_path) == Loader::ResultStatus::Success) { - if(contentIndex) { - if(tmd.ContentIndexExists(index)) { - index = tmd.ContentIndexToIndex(index); - } else { - LOG_ERROR(Service_AM, "Attempted to get path for non-existent content index {:04x}.", index); - } + if(index < tmd.GetContentCount()) { + content_id = tmd.GetContentIDByIndex(index); + } else { + LOG_ERROR(Service_AM, "Attempted to get path for non-existent content index {:04x}.", index); } - content_id = tmd.GetContentIDByIndex(index); - // TODO(shinyquagsire23): how does DLC actually get this folder on hardware? // For now, check if the second (index 1) content has the optional flag set, for most // apps this is usually the manual and not set optional, DLC has it set optional. @@ -533,7 +529,7 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { std::shared_ptr romfs_file; u64 romfs_offset = 0; - if (!tmd.ContentIndexExists(content_requested[i])) { + if (content_requested[i] >= tmd.GetContentCount()) { LOG_ERROR(Service_AM, "Attempted to get info for non-existent content index {:04x}.", content_requested[i]); IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); @@ -543,16 +539,14 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { return; } - u16 index = tmd.ContentIndexToIndex(content_requested[i]); - ContentInfo content_info = {}; content_info.index = content_requested[i]; - content_info.type = tmd.GetContentTypeByIndex(index); - content_info.content_id = tmd.GetContentIDByIndex(index); - content_info.size = tmd.GetContentSizeByIndex(index); + content_info.type = tmd.GetContentTypeByIndex(content_requested[i]); + content_info.content_id = tmd.GetContentIDByIndex(content_requested[i]); + content_info.size = tmd.GetContentSizeByIndex(content_requested[i]); content_info.ownership = OWNERSHIP_OWNED; // TODO: Pull this from the ticket. - if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, index))) { + if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, content_requested[i]))) { content_info.ownership |= OWNERSHIP_DOWNLOADED; } @@ -600,7 +594,7 @@ void Module::Interface::ListDLCContentInfos(Kernel::HLERequestContext& ctx) { u64 romfs_offset = 0; ContentInfo content_info = {}; - content_info.index = tmd.GetContentIndexByIndex(i); + content_info.index = static_cast(i); content_info.type = tmd.GetContentTypeByIndex(i); content_info.content_id = tmd.GetContentIDByIndex(i); content_info.size = tmd.GetContentSizeByIndex(i); @@ -937,7 +931,7 @@ void Module::Interface::CheckContentRights(Kernel::HLERequestContext& ctx) { // TODO(shinyquagsire23): Read tickets for this instead? bool has_rights = - FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index, false, true)); + FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index)); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); // No error @@ -953,7 +947,7 @@ void Module::Interface::CheckContentRightsIgnorePlatform(Kernel::HLERequestConte // TODO(shinyquagsire23): Read tickets for this instead? bool has_rights = - FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index, false, true)); + FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index)); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); // No error diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 7663f8c4f..40414b6d6 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -121,11 +121,10 @@ std::string GetTitleMetadataPath(Service::FS::MediaType media_type, u64 tid, boo * @param tid the title ID to get * @param index the content index to get * @param update set true if the incoming TMD should be used instead of the current TMD - * @param contentIndex set true if the supplied index is a 3DS content index value instead of a raw index. * @returns string path to the .app file */ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 index = 0, - bool update = false, bool contentIndex = false); + bool update = false); /** * Get the folder for a title's installed content. From 56488a969dea2020d26dd0436f848bfbb86e627a Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Mon, 9 Jul 2018 15:51:56 -0700 Subject: [PATCH 8/8] am: Run clang-format and attribute TODOs. --- src/core/hle/service/am/am.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index e22cbace4..252585e01 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -399,10 +399,11 @@ std::string GetTitleContentPath(Service::FS::MediaType media_type, u64 tid, u16 u32 content_id = 0; FileSys::TitleMetadata tmd; if (tmd.Load(tmd_path) == Loader::ResultStatus::Success) { - if(index < tmd.GetContentCount()) { + if (index < tmd.GetContentCount()) { content_id = tmd.GetContentIDByIndex(index); } else { - LOG_ERROR(Service_AM, "Attempted to get path for non-existent content index {:04x}.", index); + LOG_ERROR(Service_AM, "Attempted to get path for non-existent content index {:04x}.", + index); } // TODO(shinyquagsire23): how does DLC actually get this folder on hardware? @@ -530,10 +531,12 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { u64 romfs_offset = 0; if (content_requested[i] >= tmd.GetContentCount()) { - LOG_ERROR(Service_AM, "Attempted to get info for non-existent content index {:04x}.", content_requested[i]); + LOG_ERROR(Service_AM, + "Attempted to get info for non-existent content index {:04x}.", + content_requested[i]); IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); - rb.Push(-1); // TODO: Find the right error code + rb.Push(-1); // TODO(Steveice10): Find the right error code rb.PushMappedBuffer(content_requested_in); rb.PushMappedBuffer(content_info_out); return; @@ -544,7 +547,8 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) { content_info.type = tmd.GetContentTypeByIndex(content_requested[i]); content_info.content_id = tmd.GetContentIDByIndex(content_requested[i]); content_info.size = tmd.GetContentSizeByIndex(content_requested[i]); - content_info.ownership = OWNERSHIP_OWNED; // TODO: Pull this from the ticket. + content_info.ownership = + OWNERSHIP_OWNED; // TODO(Steveice10): Pull this from the ticket. if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, content_requested[i]))) { content_info.ownership |= OWNERSHIP_DOWNLOADED; @@ -598,7 +602,8 @@ void Module::Interface::ListDLCContentInfos(Kernel::HLERequestContext& ctx) { content_info.type = tmd.GetContentTypeByIndex(i); content_info.content_id = tmd.GetContentIDByIndex(i); content_info.size = tmd.GetContentSizeByIndex(i); - content_info.ownership = OWNERSHIP_OWNED; // TODO: Pull this from the ticket. + content_info.ownership = + OWNERSHIP_OWNED; // TODO(Steveice10): Pull this from the ticket. if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, i))) { content_info.ownership |= OWNERSHIP_DOWNLOADED;