Skip to content

Commit

Permalink
Fix PTM ext data creation after Artic Base changes. (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloMK7 committed May 13, 2024
1 parent 24c6ec5 commit 71eca05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/core/file_sys/archive_extsavedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,13 @@ ResultVal<std::unique_ptr<ArchiveBackend>> 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<const u8> icon) {
std::optional<std::span<const u8>> 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));

Expand All @@ -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 {
Expand All @@ -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;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/file_sys/archive_extsavedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <memory>
#include <optional>
#include <span>
#include <string>
#include <boost/serialization/export.hpp>
Expand Down Expand Up @@ -51,7 +52,8 @@ class ArchiveFactory_ExtSaveData final : public ArchiveFactory, public ArticCach
};

Result FormatAsExtData(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
u8 unknown, u64 program_id, u64 total_size, std::span<const u8> icon);
u8 unknown, u64 program_id, u64 total_size,
std::optional<std::span<const u8>> icon);

Result DeleteExtData(Service::FS::MediaType media_type, u8 unknown, u32 high, u32 low);

Expand Down
3 changes: 2 additions & 1 deletion src/core/hle/service/ptm/ptm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71eca05

Please sign in to comment.