diff options
author | Zach Hilman <zachhilman@gmail.com> | 2019-04-10 18:30:49 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2019-09-21 22:43:10 +0200 |
commit | 49c44e3faebe5912b71532a118f3bcd71bf73b4d (patch) | |
tree | 756cb5b8cfbc715a87b74e266ba7e75b2b072270 /src | |
parent | patch_manager: Add short-circuit edge-case to GetPatchVersionNames (diff) | |
download | yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.tar yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.tar.gz yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.tar.bz2 yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.tar.lz yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.tar.xz yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.tar.zst yuzu-49c44e3faebe5912b71532a118f3bcd71bf73b4d.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 65 | ||||
-rw-r--r-- | src/core/file_sys/savedata_factory.h | 1 |
2 files changed, 40 insertions, 26 deletions
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<u8>(type), title_id, user_id[1], user_id[0], save_id, - static_cast<u8>(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<VirtualDir> 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<VirtualDir> 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<u8>(type), title_id, user_id[1], user_id[0], save_id, + static_cast<u8>(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<VirtualDir> 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<VirtualDir>(std::move(out)); +} + +ResultVal<VirtualDir> 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<VirtualDir> Create(SaveDataSpaceId space, const SaveDataDescriptor& meta); ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataDescriptor& meta); VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; |