From 3f1a3952d707bce7851652ce54701ca14334f314 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 6 Feb 2015 11:53:14 -0200 Subject: FS: Allow multiple instances of the same archive type to be open at once --- src/core/file_sys/archive_savedatacheck.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/core/file_sys/archive_savedatacheck.cpp') diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp index a7a50753..47d8a9d2 100644 --- a/src/core/file_sys/archive_savedatacheck.cpp +++ b/src/core/file_sys/archive_savedatacheck.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "common/file_util.h" +#include "common/make_unique.h" #include "core/file_sys/archive_savedatacheck.h" #include "core/hle/service/fs/archive.h" @@ -21,32 +22,33 @@ static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high mount_point.c_str(), high, low); } -Archive_SaveDataCheck::Archive_SaveDataCheck(const std::string& nand_directory) : +ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) : mount_point(GetSaveDataCheckContainerPath(nand_directory)) { } -ResultCode Archive_SaveDataCheck::Open(const Path& path) { - // TODO(Subv): We should not be overwriting raw_data everytime this function is called, - // but until we use factory classes to create the archives at runtime instead of creating them beforehand - // and allow multiple archives of the same type to be open at the same time without clobbering each other, - // we won't be able to maintain the state of each archive, hence we overwrite it every time it's needed. - // There are a number of problems with this, for example opening a file in this archive, then opening - // this archive again with a different path, will corrupt the previously open file. +ResultVal> ArchiveFactory_SaveDataCheck::Open(const Path& path) { auto vec = path.AsBinary(); const u32* data = reinterpret_cast(vec.data()); std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]); FileUtil::IOFile file(file_path, "rb"); - std::fill(raw_data.begin(), raw_data.end(), 0); - if (!file.IsOpen()) { return ResultCode(-1); // TODO(Subv): Find the right error code } auto size = file.GetSize(); - raw_data.resize(size); - file.ReadBytes(raw_data.data(), size); + auto raw_data = std::make_shared>(size); + file.ReadBytes(raw_data->data(), size); file.Close(); - return RESULT_SUCCESS; + + auto archive = Common::make_unique(std::move(raw_data)); + return MakeResult>(std::move(archive)); +} + +ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path) { + LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive."); + // TODO: Verify error code + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, + ErrorSummary::NotSupported, ErrorLevel::Permanent); } } // namespace FileSys -- cgit v1.2.3