diff options
| author | 2018-12-06 20:28:51 -0500 | |
|---|---|---|
| committer | 2018-12-27 00:18:00 -0500 | |
| commit | 4082c4eda6d8282abf0ba7763ed4fd66ecd176f1 (patch) | |
| tree | bd3f2151f26141be7adc992da235941a426c6092 | |
| parent | loader: Add accessor for game control data (diff) | |
| download | yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.gz yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.tar.xz yuzu-4082c4eda6d8282abf0ba7763ed4fd66ecd176f1.zip | |
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.
| -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 @@ | |||
| 13 | 13 | ||
| 14 | namespace FileSys { | 14 | namespace FileSys { |
| 15 | 15 | ||
| 16 | constexpr const char* SAVE_DATA_SIZE_FILENAME = ".yuzu_save_size"; | ||
| 17 | |||
| 16 | std::string SaveDataDescriptor::DebugInfo() const { | 18 | std::string SaveDataDescriptor::DebugInfo() const { |
| 17 | return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}]", | 19 | return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}]", |
| 18 | static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id); | 20 | 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 | |||
| 132 | } | 134 | } |
| 133 | } | 135 | } |
| 134 | 136 | ||
| 137 | SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id, | ||
| 138 | u128 user_id) const { | ||
| 139 | const auto path = GetFullPath(SaveDataSpaceId::NandUser, type, title_id, user_id, 0); | ||
| 140 | const auto dir = GetOrCreateDirectoryRelative(this->dir, path); | ||
| 141 | |||
| 142 | const auto size_file = dir->GetFile(SAVE_DATA_SIZE_FILENAME); | ||
| 143 | if (size_file == nullptr || size_file->GetSize() < sizeof(SaveDataSize)) | ||
| 144 | return {0, 0}; | ||
| 145 | |||
| 146 | SaveDataSize out; | ||
| 147 | if (size_file->ReadObject(&out) != sizeof(SaveDataSize)) | ||
| 148 | return {0, 0}; | ||
| 149 | return out; | ||
| 150 | } | ||
| 151 | |||
| 152 | void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, | ||
| 153 | SaveDataSize new_value) { | ||
| 154 | const auto path = GetFullPath(SaveDataSpaceId::NandUser, type, title_id, user_id, 0); | ||
| 155 | const auto dir = GetOrCreateDirectoryRelative(this->dir, path); | ||
| 156 | |||
| 157 | const auto size_file = dir->CreateFile(SAVE_DATA_SIZE_FILENAME); | ||
| 158 | if (size_file == nullptr) | ||
| 159 | return; | ||
| 160 | |||
| 161 | size_file->Resize(sizeof(SaveDataSize)); | ||
| 162 | size_file->WriteObject(new_value); | ||
| 163 | } | ||
| 164 | |||
| 135 | } // namespace FileSys | 165 | } // 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 { | |||
| 46 | }; | 46 | }; |
| 47 | static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size."); | 47 | static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size."); |
| 48 | 48 | ||
| 49 | struct SaveDataSize { | ||
| 50 | u64 normal; | ||
| 51 | u64 journal; | ||
| 52 | }; | ||
| 53 | |||
| 49 | /// File system interface to the SaveData archive | 54 | /// File system interface to the SaveData archive |
| 50 | class SaveDataFactory { | 55 | class SaveDataFactory { |
| 51 | public: | 56 | public: |
| @@ -60,6 +65,9 @@ public: | |||
| 60 | static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, | 65 | static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, |
| 61 | u128 user_id, u64 save_id); | 66 | u128 user_id, u64 save_id); |
| 62 | 67 | ||
| 68 | SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const; | ||
| 69 | void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, SaveDataSize new_value); | ||
| 70 | |||
| 63 | private: | 71 | private: |
| 64 | VirtualDir dir; | 72 | VirtualDir dir; |
| 65 | }; | 73 | }; |