diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index ef1aaebbb0..1ec54c78f1 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -83,6 +83,24 @@ ResultVal SaveDataFactory::Open(SaveDataSpaceId space, SaveDataDescr return MakeResult(std::move(out)); } +VirtualDir SaveDataFactory::GetSaveDataSpaceDirectory(SaveDataSpaceId space) { + return dir->GetDirectoryRelative(GetSaveDataSpaceIdPath(space)); +} + +std::string SaveDataFactory::GetSaveDataSpaceIdPath(SaveDataSpaceId space) { + switch (space) { + case SaveDataSpaceId::NandSystem: + return "/system/"; + case SaveDataSpaceId::NandUser: + return "/user/"; + case SaveDataSpaceId::TemporaryStorage: + return "/temp/"; + default: + ASSERT_MSG(false, "Unrecognized SaveDataSpaceId: {:02X}", static_cast(space)); + return "/unrecognized/"; ///< To prevent corruption when ignoring asserts. + } +} + std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id, u64 save_id) { // According to switchbrew, if a save is of type SaveData and the title id field is 0, it should @@ -90,21 +108,7 @@ std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType typ if (type == SaveDataType::SaveData && title_id == 0) title_id = Core::CurrentProcess()->GetTitleID(); - std::string out; - - switch (space) { - case SaveDataSpaceId::NandSystem: - out = "/system/"; - break; - case SaveDataSpaceId::NandUser: - out = "/user/"; - break; - case SaveDataSpaceId::TemporaryStorage: - out = "/temp/"; - break; - default: - ASSERT_MSG(false, "Unrecognized SaveDataSpaceId: {:02X}", static_cast(space)); - } + std::string out = GetSaveDataSpaceIdPath(space); switch (type) { case SaveDataType::SystemSaveData: diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index d69ef6741c..024a305d33 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -52,6 +52,9 @@ public: ResultVal Open(SaveDataSpaceId space, SaveDataDescriptor meta); + VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space); + + static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space); static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id, u64 save_id); diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index e32a7c48e2..ea8fd965a4 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -309,6 +309,16 @@ ResultVal OpenSaveData(FileSys::SaveDataSpaceId space, return save_data_factory->Open(space, save_struct); } +ResultVal OpenSaveDataSpace(FileSys::SaveDataSpaceId space) { + LOG_TRACE(Service_FS, "Opening Save Data Space for space_id={:01X}", static_cast(space)); + + if (save_data_factory == nullptr) { + return ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound); + } + + return MakeResult(save_data_factory->GetSaveDataSpaceDirectory(space)); +} + ResultVal OpenSDMC() { LOG_TRACE(Service_FS, "Opening SDMC"); diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 6ca5c56369..2cbb70c87c 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -45,6 +45,7 @@ ResultVal OpenRomFS(u64 title_id, FileSys::StorageId stora FileSys::ContentRecordType type); ResultVal OpenSaveData(FileSys::SaveDataSpaceId space, FileSys::SaveDataDescriptor save_struct); +ResultVal OpenSaveDataSpace(FileSys::SaveDataSpaceId space); ResultVal OpenSDMC(); std::unique_ptr GetUnionContents();