From 49c44e3faebe5912b71532a118f3bcd71bf73b4d Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Wed, 10 Apr 2019 12:30:49 -0400 Subject: savedata_factory: Implement savedata creation and don't create dir on open Matches hardware behavior and eliminates some nasty behavior we were doing that wasn't hw-accurate at all. --- src/core/file_sys/savedata_factory.cpp | 65 ++++++++++++++++++++-------------- src/core/file_sys/savedata_factory.h | 1 + 2 files changed, 40 insertions(+), 26 deletions(-) (limited to 'src/core') diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index 7974b031d..c63815332 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -15,22 +15,8 @@ namespace FileSys { constexpr char SAVE_DATA_SIZE_FILENAME[] = ".yuzu_save_size"; -std::string SaveDataDescriptor::DebugInfo() const { - return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, " - "rank={}, index={}]", - static_cast(type), title_id, user_id[1], user_id[0], save_id, - static_cast(rank), index); -} - -SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save_directory)) { - // Delete all temporary storages - // On hardware, it is expected that temporary storage be empty at first use. - dir->DeleteSubdirectoryRecursive("temp"); -} - -SaveDataFactory::~SaveDataFactory() = default; - -ResultVal SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataDescriptor& meta) { +namespace { +void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { if (meta.zero_1 != 0) { LOG_WARNING(Service_FS, @@ -65,23 +51,50 @@ ResultVal SaveDataFactory::Open(SaveDataSpaceId space, const SaveDat "non-zero ({:016X}{:016X})", meta.user_id[1], meta.user_id[0]); } +} +} // Anonymous namespace - std::string save_directory = - GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); +std::string SaveDataDescriptor::DebugInfo() const { + return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, " + "save_id={:016X}, " + "rank={}, index={}]", + static_cast(type), title_id, user_id[1], user_id[0], save_id, + static_cast(rank), index); +} - // 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. +SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save_directory)) { + // Delete all temporary storages + // On hardware, it is expected that temporary storage be empty at first use. + dir->DeleteSubdirectoryRecursive("temp"); +} - auto out = dir->GetDirectoryRelative(save_directory); +SaveDataFactory::~SaveDataFactory() = default; + +ResultVal SaveDataFactory::Create(SaveDataSpaceId space, + const SaveDataDescriptor& meta) { + PrintSaveDataDescriptorWarnings(meta); + + const auto save_directory = + GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); + + auto out = dir->CreateDirectoryRelative(save_directory); + // Return an error if the save data doesn't actually exist. 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. - out = dir->CreateDirectoryRelative(save_directory); + // TODO(DarkLordZach): Find out correct error code. + return ResultCode(-1); } + return MakeResult(std::move(out)); +} + +ResultVal SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataDescriptor& meta) { + + const auto save_directory = + GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); + + auto out = dir->GetDirectoryRelative(save_directory); + // Return an error if the save data doesn't actually exist. if (out == nullptr) { // TODO(Subv): Find out correct error code. diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index b73654571..738038ee0 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -64,6 +64,7 @@ public: explicit SaveDataFactory(VirtualDir dir); ~SaveDataFactory(); + ResultVal Create(SaveDataSpaceId space, const SaveDataDescriptor& meta); ResultVal Open(SaveDataSpaceId space, const SaveDataDescriptor& meta); VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; -- cgit v1.2.3