From 29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 18 Jul 2018 21:07:11 -0400 Subject: Virtual Filesystem 2: Electric Boogaloo (#676) * Virtual Filesystem * Fix delete bug and documentate * Review fixes + other stuff * Fix puyo regression --- src/core/file_sys/savedata_factory.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/core/file_sys/savedata_factory.cpp') 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(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> SaveDataFactory::Open(SaveDataSpaceId space, - SaveDataDescriptor meta) { +ResultVal 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> 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(save_directory); - return MakeResult>(std::move(archive)); + return MakeResult(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(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(type)); -- cgit v1.2.3