diff options
| author | 2015-02-24 18:02:40 -0500 | |
|---|---|---|
| committer | 2015-02-25 19:37:10 -0500 | |
| commit | 9db5c9b6dc7b01a0a69179707823f27f42b9cdd9 (patch) | |
| tree | 8f5c1e9de1e90b2db1f636224e5b7c4b62d69213 /src/core/file_sys | |
| parent | Merge pull request #595 from linkmauve/new-3ds-input (diff) | |
| download | yuzu-9db5c9b6dc7b01a0a69179707823f27f42b9cdd9.tar.gz yuzu-9db5c9b6dc7b01a0a69179707823f27f42b9cdd9.tar.xz yuzu-9db5c9b6dc7b01a0a69179707823f27f42b9cdd9.zip | |
Archives: Properly implemented the SystemSaveData archive.
Ported to the new factory pattern we have for archives.
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/archive_systemsavedata.cpp | 33 | ||||
| -rw-r--r-- | src/core/file_sys/archive_systemsavedata.h | 14 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index c2a5d641a..25c94cd26 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp | |||
| @@ -6,9 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| 9 | #include "common/make_unique.h" | ||
| 9 | 10 | ||
| 10 | #include "core/file_sys/archive_systemsavedata.h" | 11 | #include "core/file_sys/archive_systemsavedata.h" |
| 11 | #include "core/file_sys/disk_archive.h" | ||
| 12 | #include "core/hle/service/fs/archive.h" | 12 | #include "core/hle/service/fs/archive.h" |
| 13 | #include "core/settings.h" | 13 | #include "core/settings.h" |
| 14 | 14 | ||
| @@ -17,9 +17,11 @@ | |||
| 17 | 17 | ||
| 18 | namespace FileSys { | 18 | namespace FileSys { |
| 19 | 19 | ||
| 20 | static std::string GetSystemSaveDataPath(const std::string& mount_point, u64 save_id) { | 20 | static std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) { |
| 21 | u32 save_high = static_cast<u32>((save_id >> 32) & 0xFFFFFFFF); | 21 | std::vector<u8> vec_data = path.AsBinary(); |
| 22 | u32 save_low = static_cast<u32>(save_id & 0xFFFFFFFF); | 22 | const u32* data = reinterpret_cast<const u32*>(vec_data.data()); |
| 23 | u32 save_low = data[1]; | ||
| 24 | u32 save_high = data[0]; | ||
| 23 | return Common::StringFromFormat("%s%08X/%08X/", mount_point.c_str(), save_low, save_high); | 25 | return Common::StringFromFormat("%s%08X/%08X/", mount_point.c_str(), save_low, save_high); |
| 24 | } | 26 | } |
| 25 | 27 | ||
| @@ -27,18 +29,25 @@ static std::string GetSystemSaveDataContainerPath(const std::string& mount_point | |||
| 27 | return Common::StringFromFormat("%sdata/%s/sysdata/", mount_point.c_str(), SYSTEM_ID.c_str()); | 29 | return Common::StringFromFormat("%sdata/%s/sysdata/", mount_point.c_str(), SYSTEM_ID.c_str()); |
| 28 | } | 30 | } |
| 29 | 31 | ||
| 30 | Archive_SystemSaveData::Archive_SystemSaveData(const std::string& mount_point, u64 save_id) | 32 | ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) |
| 31 | : DiskArchive(GetSystemSaveDataPath(GetSystemSaveDataContainerPath(mount_point), save_id)) { | 33 | : base_path(GetSystemSaveDataContainerPath(nand_path)) { |
| 32 | LOG_INFO(Service_FS, "Directory %s set as SystemSaveData.", this->mount_point.c_str()); | ||
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | bool Archive_SystemSaveData::Initialize() { | 36 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path) { |
| 36 | if (!FileUtil::CreateFullPath(mount_point)) { | 37 | std::string fullpath = GetSystemSaveDataPath(base_path, path); |
| 37 | LOG_ERROR(Service_FS, "Unable to create SystemSaveData path."); | 38 | if (!FileUtil::Exists(fullpath)) { |
| 38 | return false; | 39 | // TODO(Subv): Check error code, this one is probably wrong |
| 40 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | ||
| 41 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 39 | } | 42 | } |
| 43 | auto archive = Common::make_unique<DiskArchive>(fullpath); | ||
| 44 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | ||
| 45 | } | ||
| 40 | 46 | ||
| 41 | return true; | 47 | ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path) { |
| 48 | std::string fullpath = GetSystemSaveDataPath(base_path, path); | ||
| 49 | FileUtil::CreateFullPath(fullpath); | ||
| 50 | return RESULT_SUCCESS; | ||
| 42 | } | 51 | } |
| 43 | 52 | ||
| 44 | } // namespace FileSys | 53 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h index c8f5845ca..556a2a488 100644 --- a/src/core/file_sys/archive_systemsavedata.h +++ b/src/core/file_sys/archive_systemsavedata.h | |||
| @@ -15,17 +15,17 @@ | |||
| 15 | namespace FileSys { | 15 | namespace FileSys { |
| 16 | 16 | ||
| 17 | /// File system interface to the SystemSaveData archive | 17 | /// File system interface to the SystemSaveData archive |
| 18 | class Archive_SystemSaveData final : public DiskArchive { | 18 | class ArchiveFactory_SystemSaveData final : public ArchiveFactory { |
| 19 | public: | 19 | public: |
| 20 | Archive_SystemSaveData(const std::string& mount_point, u64 save_id); | 20 | ArchiveFactory_SystemSaveData(const std::string& mount_point); |
| 21 | 21 | ||
| 22 | /** | 22 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 23 | * Initialize the archive. | 23 | ResultCode Format(const Path& path) override; |
| 24 | * @return true if it initialized successfully | ||
| 25 | */ | ||
| 26 | bool Initialize(); | ||
| 27 | 24 | ||
| 28 | std::string GetName() const override { return "SystemSaveData"; } | 25 | std::string GetName() const override { return "SystemSaveData"; } |
| 26 | |||
| 27 | private: | ||
| 28 | std::string base_path; | ||
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | } // namespace FileSys | 31 | } // namespace FileSys |