diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-12-07 02:28:51 +0100 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-12-27 06:18:00 +0100 |
commit | 4082c4eda6d8282abf0ba7763ed4fd66ecd176f1 (patch) | |
tree | bd3f2151f26141be7adc992da235941a426c6092 | |
parent | loader: Add accessor for game control data (diff) | |
download | yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.gz yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.bz2 yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.lz yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.xz yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.zst yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 30 | ||||
-rw-r--r-- | src/core/file_sys/savedata_factory.h | 8 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index d63b7f19b..54f5b698a 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -13,6 +13,8 @@ namespace FileSys { +constexpr const 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}]", static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id); @@ -132,4 +134,32 @@ std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType typ } } +SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id, + u128 user_id) const { + const auto path = GetFullPath(SaveDataSpaceId::NandUser, type, title_id, user_id, 0); + const auto dir = GetOrCreateDirectoryRelative(this->dir, path); + + const auto size_file = dir->GetFile(SAVE_DATA_SIZE_FILENAME); + if (size_file == nullptr || size_file->GetSize() < sizeof(SaveDataSize)) + return {0, 0}; + + SaveDataSize out; + if (size_file->ReadObject(&out) != sizeof(SaveDataSize)) + return {0, 0}; + return out; +} + +void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, + SaveDataSize new_value) { + const auto path = GetFullPath(SaveDataSpaceId::NandUser, type, title_id, user_id, 0); + const auto dir = GetOrCreateDirectoryRelative(this->dir, path); + + const auto size_file = dir->CreateFile(SAVE_DATA_SIZE_FILENAME); + if (size_file == nullptr) + return; + + size_file->Resize(sizeof(SaveDataSize)); + size_file->WriteObject(new_value); +} + } // namespace FileSys diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index bd4919610..3a1caf292 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -46,6 +46,11 @@ struct SaveDataDescriptor { }; static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size."); +struct SaveDataSize { + u64 normal; + u64 journal; +}; + /// File system interface to the SaveData archive class SaveDataFactory { public: @@ -60,6 +65,9 @@ public: static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id, u64 save_id); + SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const; + void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, SaveDataSize new_value); + private: VirtualDir dir; }; |