From 52e5885a475cc0a480709ff88ead2e2fc07b0a48 Mon Sep 17 00:00:00 2001 From: emoose Date: Tue, 23 Jul 2019 17:45:16 +0100 Subject: [PATCH] Allow reading FolderContentPackage thumb from headers.bin file --- src/xenia/kernel/xam/content_package.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/xenia/kernel/xam/content_package.cc b/src/xenia/kernel/xam/content_package.cc index 1f8e2114a..fb64d7c20 100644 --- a/src/xenia/kernel/xam/content_package.cc +++ b/src/xenia/kernel/xam/content_package.cc @@ -97,10 +97,9 @@ bool FolderContentPackage::Mount(std::string root_name) { } X_RESULT FolderContentPackage::GetThumbnail(std::vector* buffer) { - // TODO: grab thumb from headers.bin file if it exists - auto thumb_path = package_path_ / kThumbnailFileName; if (std::filesystem::exists(thumb_path)) { + auto file = xe::filesystem::OpenFile(thumb_path, "rb"); fseek(file, 0, SEEK_END); size_t file_len = ftell(file); @@ -110,7 +109,26 @@ X_RESULT FolderContentPackage::GetThumbnail(std::vector* buffer) { fclose(file); return X_ERROR_SUCCESS; } - return X_ERROR_FILE_NOT_FOUND; + auto result = X_ERROR_FILE_NOT_FOUND; + + // Try reading thumbnail from kStfsHeadersExtension file + auto headers_path = package_path_ / ContentManager::kStfsHeadersExtension; + if (std::filesystem::exists(headers_path)) { + vfs::StfsHeader* header = + new vfs::StfsHeader(); // huge class, alloc on heap + auto map = MappedMemory::Open(headers_path, MappedMemory::Mode::kRead, 0, + vfs::StfsHeader::kHeaderLength); + if (map) { + if (header->Read(map->data())) { + buffer->resize(header->thumbnail_image_size); + memcpy(buffer->data(), header->thumbnail_image, + header->thumbnail_image_size); + result = X_ERROR_SUCCESS; + } + } + delete header; + } + return result; } X_RESULT FolderContentPackage::SetThumbnail(std::vector buffer) {