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_savedata.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/core/file_sys/archive_savedata.cpp') diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index 3baee529..8496e06f 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp @@ -6,6 +6,7 @@ #include "common/common_types.h" #include "common/file_util.h" +#include "common/make_unique.h" #include "core/file_sys/archive_savedata.h" #include "core/file_sys/disk_archive.h" @@ -28,26 +29,28 @@ static std::string GetSaveDataPath(const std::string& mount_location, u64 progra return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high, low); } -Archive_SaveData::Archive_SaveData(const std::string& sdmc_directory) - : DiskArchive(GetSaveDataContainerPath(sdmc_directory)) { +ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory) + : mount_point(GetSaveDataContainerPath(sdmc_directory)) { LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str()); } -ResultCode Archive_SaveData::Open(const Path& path) { - if (concrete_mount_point.empty()) - concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_program_id); +ResultVal> ArchiveFactory_SaveData::Open(const Path& path) { + std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_program_id); if (!FileUtil::Exists(concrete_mount_point)) { // When a SaveData archive is created for the first time, it is not yet formatted - // and the save file/directory structure expected by the game has not yet been initialized. - // Returning the NotFormatted error code will signal the game to provision the SaveData archive - // with the files and folders that it expects. + // and the save file/directory structure expected by the game has not yet been initialized. + // Returning the NotFormatted error code will signal the game to provision the SaveData archive + // with the files and folders that it expects. return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); } - return RESULT_SUCCESS; + + auto archive = Common::make_unique(std::move(concrete_mount_point)); + return MakeResult>(std::move(archive)); } -ResultCode Archive_SaveData::Format(const Path& path) const { +ResultCode ArchiveFactory_SaveData::Format(const Path& path) { + std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_program_id); FileUtil::DeleteDirRecursively(concrete_mount_point); FileUtil::CreateFullPath(concrete_mount_point); return RESULT_SUCCESS; -- cgit v1.2.3