diff options
Diffstat (limited to 'src/core/file_sys/savedata_factory.cpp')
-rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index 3ad37b28c..6a53b2b10 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -6,7 +6,6 @@ #include "common/common_types.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/file_sys/disk_filesystem.h" #include "core/file_sys/savedata_factory.h" #include "core/hle/kernel/process.h" @@ -17,11 +16,9 @@ std::string SaveDataDescriptor::DebugInfo() { static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id); } -SaveDataFactory::SaveDataFactory(std::string nand_directory) - : nand_directory(std::move(nand_directory)) {} +SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save_directory)) {} -ResultVal<std::unique_ptr<FileSystemBackend>> SaveDataFactory::Open(SaveDataSpaceId space, - SaveDataDescriptor meta) { +ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, SaveDataDescriptor meta) { if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { if (meta.zero_1 != 0) { LOG_WARNING(Service_FS, @@ -56,28 +53,23 @@ ResultVal<std::unique_ptr<FileSystemBackend>> SaveDataFactory::Open(SaveDataSpac // TODO(DarkLordZach): Try to not create when opening, there are dedicated create save methods. // But, user_ids don't match so this works for now. - if (!FileUtil::Exists(save_directory)) { + auto out = dir->GetDirectoryRelative(save_directory); + + if (out == nullptr) { // TODO(bunnei): This is a work-around to always create a save data directory if it does not // already exist. This is a hack, as we do not understand yet how this works on hardware. // Without a save data directory, many games will assert on boot. This should not have any // bad side-effects. - FileUtil::CreateFullPath(save_directory); - } - - // TODO(DarkLordZach): For some reason, CreateFullPath doesn't create the last bit. Should be - // fixed with VFS. - if (!FileUtil::IsDirectory(save_directory)) { - FileUtil::CreateDir(save_directory); + out = dir->CreateDirectoryRelative(save_directory); } // Return an error if the save data doesn't actually exist. - if (!FileUtil::IsDirectory(save_directory)) { + if (out == nullptr) { // TODO(Subv): Find out correct error code. return ResultCode(-1); } - auto archive = std::make_unique<Disk_FileSystem>(save_directory); - return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive)); + return MakeResult<VirtualDir>(std::move(out)); } std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, @@ -87,14 +79,14 @@ std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType typ if (type == SaveDataType::SaveData && title_id == 0) title_id = Core::CurrentProcess()->program_id; - std::string prefix; + std::string out; switch (space) { case SaveDataSpaceId::NandSystem: - prefix = nand_directory + "system/save/"; + out = "/system/save/"; break; case SaveDataSpaceId::NandUser: - prefix = nand_directory + "user/save/"; + out = "/user/save/"; break; default: ASSERT_MSG(false, "Unrecognized SaveDataSpaceId: {:02X}", static_cast<u8>(space)); @@ -102,9 +94,9 @@ std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType typ switch (type) { case SaveDataType::SystemSaveData: - return fmt::format("{}{:016X}/{:016X}{:016X}", prefix, save_id, user_id[1], user_id[0]); + return fmt::format("{}{:016X}/{:016X}{:016X}", out, save_id, user_id[1], user_id[0]); case SaveDataType::SaveData: - return fmt::format("{}{:016X}/{:016X}{:016X}/{:016X}", prefix, 0, user_id[1], user_id[0], + return fmt::format("{}{:016X}/{:016X}{:016X}/{:016X}", out, 0, user_id[1], user_id[0], title_id); default: ASSERT_MSG(false, "Unrecognized SaveDataType: {:02X}", static_cast<u8>(type)); |