diff options
| author | Zach Hilman <zachhilman@gmail.com> | 2018-12-06 20:28:51 -0500 |
|---|---|---|
| committer | Zach Hilman <zachhilman@gmail.com> | 2018-12-27 00:18:00 -0500 |
| commit | 4082c4eda6d8282abf0ba7763ed4fd66ecd176f1 (patch) | |
| tree | bd3f2151f26141be7adc992da235941a426c6092 /src/core/file_sys/savedata_factory.cpp | |
| parent | 0756f29a2c99070a6c676b39d797015d140ad7ac (diff) | |
savedata_factory: Partially implement IVFC save sizes using files
This stores a file in the save directory called '.yuzu_save_size' which stores the two save sizes (normal area and journaled area) sequentially as u64s.
Diffstat (limited to 'src/core/file_sys/savedata_factory.cpp')
| -rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 30 |
1 files changed, 30 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 |
