From d26c6b3212ed36970410814593ee5ec082b1d95a Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Dec 2015 13:51:44 -0500 Subject: HLE/FS: Implemented GetFormatInfo Format information is currently only implemented for the ExtSaveData, SharedExtSaveData and SaveData archives, the information is stored in a file alongside the root folder of the archive. --- src/core/file_sys/archive_extsavedata.cpp | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/archive_extsavedata.cpp') diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 92dad8e6f..e83a6153d 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -82,13 +82,45 @@ ResultVal> ArchiveFactory_ExtSaveData::Open(cons return MakeResult>(std::move(archive)); } -ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path) { +ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { // These folders are always created with the ExtSaveData std::string user_path = GetExtSaveDataPath(mount_point, path) + "user/"; std::string boss_path = GetExtSaveDataPath(mount_point, path) + "boss/"; FileUtil::CreateFullPath(user_path); FileUtil::CreateFullPath(boss_path); - return RESULT_SUCCESS; + + // Write the format metadata + std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; + FileUtil::IOFile file(metadata_path, "wb"); + + if (file.IsOpen()) { + file.WriteBytes(&format_info, sizeof(format_info)); + return RESULT_SUCCESS; + } + + // TODO(Subv): Find the correct error code + return ResultCode(-1); +} + +ResultVal ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path) const { + std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; + FileUtil::IOFile file(metadata_path, "rb"); + + if (file.IsOpen()) { + ArchiveFormatInfo info; + file.ReadBytes(&info, sizeof(info)); + return MakeResult(info); + } + + LOG_ERROR(Service_FS, "Could not open metadata information for archive"); + // TODO(Subv): Verify error code + return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); +} + +void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, u8* icon_data, u32 icon_size) { + std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); + FileUtil::IOFile icon_file(game_path + "icon", "wb+"); + icon_file.WriteBytes(icon_data, icon_size); } } // namespace FileSys -- cgit v1.2.3 From 3aa42627a3a35d8a4fb9acdcced24977d1f269cd Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 16 Jan 2016 17:01:01 -0500 Subject: HLE/FS: Corrected some style concerns. --- src/core/file_sys/archive_extsavedata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/file_sys/archive_extsavedata.cpp') diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index e83a6153d..ca7fd5c5e 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -117,7 +117,7 @@ ResultVal ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); } -void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, u8* icon_data, u32 icon_size) { +void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, u32 icon_size) { std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); FileUtil::IOFile icon_file(game_path + "icon", "wb+"); icon_file.WriteBytes(icon_data, icon_size); -- cgit v1.2.3 From f707026ac50c53716ac697ed439630d7728e9db6 Mon Sep 17 00:00:00 2001 From: Subv Date: Thu, 3 Mar 2016 13:05:50 -0500 Subject: HLE/FS: Change the error code returned when an ExtSaveData archive is not found. This allows Fire Emblem to boot again. --- src/core/file_sys/archive_extsavedata.cpp | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/core/file_sys/archive_extsavedata.cpp') diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index ca7fd5c5e..961264fe5 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -58,7 +58,7 @@ Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { } ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) - : mount_point(GetExtDataContainerPath(mount_location, shared)) { + : shared(shared), mount_point(GetExtDataContainerPath(mount_location, shared)) { LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); } @@ -74,9 +74,15 @@ bool ArchiveFactory_ExtSaveData::Initialize() { ResultVal> ArchiveFactory_ExtSaveData::Open(const Path& path) { std::string fullpath = GetExtSaveDataPath(mount_point, path) + "user/"; if (!FileUtil::Exists(fullpath)) { - // TODO(Subv): Check error code, this one is probably wrong - return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, - ErrorSummary::InvalidState, ErrorLevel::Status); + // TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData. + // ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist. + if (!shared) { + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, + ErrorSummary::InvalidState, ErrorLevel::Status); + } else { + return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, + ErrorSummary::InvalidState, ErrorLevel::Status); + } } auto archive = Common::make_unique(fullpath); return MakeResult>(std::move(archive)); @@ -93,33 +99,33 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, const FileSys::A std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; FileUtil::IOFile file(metadata_path, "wb"); - if (file.IsOpen()) { - file.WriteBytes(&format_info, sizeof(format_info)); - return RESULT_SUCCESS; + if (!file.IsOpen()) { + // TODO(Subv): Find the correct error code + return ResultCode(-1); } - // TODO(Subv): Find the correct error code - return ResultCode(-1); + file.WriteBytes(&format_info, sizeof(format_info)); + return RESULT_SUCCESS; } ResultVal ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path) const { std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; FileUtil::IOFile file(metadata_path, "rb"); - if (file.IsOpen()) { - ArchiveFormatInfo info; - file.ReadBytes(&info, sizeof(info)); - return MakeResult(info); + if (!file.IsOpen()) { + LOG_ERROR(Service_FS, "Could not open metadata information for archive"); + // TODO(Subv): Verify error code + return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); } - LOG_ERROR(Service_FS, "Could not open metadata information for archive"); - // TODO(Subv): Verify error code - return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); + ArchiveFormatInfo info = {}; + file.ReadBytes(&info, sizeof(info)); + return MakeResult(info); } -void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, u32 icon_size) { +void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, size_t icon_size) { std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); - FileUtil::IOFile icon_file(game_path + "icon", "wb+"); + FileUtil::IOFile icon_file(game_path + "icon", "wb"); icon_file.WriteBytes(icon_data, icon_size); } -- cgit v1.2.3