From 71eca05af1b8784b2dc7df9f3fe2f0594424ea0d Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Mon, 13 May 2024 10:54:52 +0200 Subject: [PATCH] Fix PTM ext data creation after Artic Base changes. (#111) --- src/core/file_sys/archive_extsavedata.cpp | 18 ++++++++++++------ src/core/file_sys/archive_extsavedata.h | 4 +++- src/core/hle/service/ptm/ptm.cpp | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 54fc25ee5..4e9ea6ef8 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -289,8 +289,13 @@ ResultVal> ArchiveFactory_ExtSaveData::Open(cons Result ArchiveFactory_ExtSaveData::FormatAsExtData(const Path& path, const FileSys::ArchiveFormatInfo& format_info, u8 unknown, u64 program_id, u64 total_size, - std::span icon) { + std::optional> icon) { if (IsUsingArtic()) { + if (!icon.has_value()) { + LOG_ERROR(Service_FS, "No icon provided while using Artic Base"); + return ResultUnknown; + } + ExtSaveDataArchivePath path_data; std::memcpy(&path_data, path.AsBinary().data(), sizeof(path_data)); @@ -307,7 +312,7 @@ Result ArchiveFactory_ExtSaveData::FormatAsExtData(const Path& path, req.AddParameterU32(format_info.number_directories); req.AddParameterU32(format_info.number_files); req.AddParameterU64(total_size); - req.AddParameterBuffer(icon.data(), icon.size()); + req.AddParameterBuffer(icon->data(), icon->size()); return ArticArchive::RespResult(artic_client->Send(req)); } else { @@ -330,10 +335,11 @@ Result ArchiveFactory_ExtSaveData::FormatAsExtData(const Path& path, file.WriteBytes(&format_info, sizeof(format_info)); - FileUtil::IOFile icon_file(FileSys::GetExtSaveDataPath(GetMountPoint(), path) + "icon", - "wb"); - icon_file.WriteBytes(icon.data(), icon.size()); - + if (icon.has_value()) { + FileUtil::IOFile icon_file(FileSys::GetExtSaveDataPath(GetMountPoint(), path) + "icon", + "wb"); + icon_file.WriteBytes(icon->data(), icon->size()); + } return ResultSuccess; } } diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index e89909ec3..29589d418 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -51,7 +52,8 @@ public: }; Result FormatAsExtData(const Path& path, const FileSys::ArchiveFormatInfo& format_info, - u8 unknown, u64 program_id, u64 total_size, std::span icon); + u8 unknown, u64 program_id, u64 total_size, + std::optional> icon); Result DeleteExtData(Service::FS::MediaType media_type, u8 unknown, u32 high, u32 low); diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index fb3a51b6b..a9851a19b 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -158,7 +158,8 @@ static void WriteGameCoinData(GameCoin gamecoin_data) { // If the archive didn't exist, create the files inside if (archive_result.Code() == FileSys::ResultNotFormatted) { // Format the archive to create the directories - extdata_archive_factory.Format(archive_path, FileSys::ArchiveFormatInfo(), 0, 0, 0); + extdata_archive_factory.FormatAsExtData(archive_path, FileSys::ArchiveFormatInfo(), 0, 0, 0, + std::nullopt); // Open it again to get a valid archive now that the folder exists archive = extdata_archive_factory.Open(archive_path, 0).Unwrap(); // Create the game coin file