diff options
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/archive_extsavedata.cpp | 21 | ||||
| -rw-r--r-- | src/core/file_sys/archive_extsavedata.h | 10 | ||||
| -rw-r--r-- | src/core/file_sys/archive_systemsavedata.cpp | 22 | ||||
| -rw-r--r-- | src/core/file_sys/archive_systemsavedata.h | 25 |
4 files changed, 76 insertions, 2 deletions
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 0363c9771..3076fa263 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp | |||
| @@ -34,6 +34,27 @@ std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) | |||
| 34 | SYSTEM_ID.c_str(), SDCARD_ID.c_str()); | 34 | SYSTEM_ID.c_str(), SDCARD_ID.c_str()); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { | ||
| 38 | std::vector<u8> binary_path; | ||
| 39 | binary_path.reserve(12); | ||
| 40 | |||
| 41 | // Append each word byte by byte | ||
| 42 | |||
| 43 | // The first word is the media type | ||
| 44 | for (unsigned i = 0; i < 4; ++i) | ||
| 45 | binary_path.push_back((media_type >> (8 * i)) & 0xFF); | ||
| 46 | |||
| 47 | // Next is the low word | ||
| 48 | for (unsigned i = 0; i < 4; ++i) | ||
| 49 | binary_path.push_back((low >> (8 * i)) & 0xFF); | ||
| 50 | |||
| 51 | // Next is the high word | ||
| 52 | for (unsigned i = 0; i < 4; ++i) | ||
| 53 | binary_path.push_back((high >> (8 * i)) & 0xFF); | ||
| 54 | |||
| 55 | return { binary_path }; | ||
| 56 | } | ||
| 57 | |||
| 37 | ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) | 58 | ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) |
| 38 | : mount_point(GetExtDataContainerPath(mount_location, shared)) { | 59 | : mount_point(GetExtDataContainerPath(mount_location, shared)) { |
| 39 | LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); | 60 | LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); |
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index 83c6b0291..c77c04e44 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h | |||
| @@ -58,4 +58,14 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) | |||
| 58 | */ | 58 | */ |
| 59 | std::string GetExtDataContainerPath(const std::string& mount_point, bool shared); | 59 | std::string GetExtDataContainerPath(const std::string& mount_point, bool shared); |
| 60 | 60 | ||
| 61 | /** | ||
| 62 | * Constructs a FileSys::Path object that refers to the ExtData archive identified by | ||
| 63 | * the specified media type, high save id and low save id. | ||
| 64 | * @param media_type The media type where the archive is located (NAND / SDMC) | ||
| 65 | * @param high The high word of the save id for the archive | ||
| 66 | * @param low The low word of the save id for the archive | ||
| 67 | * @returns A FileSys::Path to the wanted archive | ||
| 68 | */ | ||
| 69 | Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low); | ||
| 70 | |||
| 61 | } // namespace FileSys | 71 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index 25c94cd26..4fe785c97 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp | |||
| @@ -17,7 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | namespace FileSys { | 18 | namespace FileSys { |
| 19 | 19 | ||
| 20 | static std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) { | 20 | std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) { |
| 21 | std::vector<u8> vec_data = path.AsBinary(); | 21 | std::vector<u8> vec_data = path.AsBinary(); |
| 22 | const u32* data = reinterpret_cast<const u32*>(vec_data.data()); | 22 | const u32* data = reinterpret_cast<const u32*>(vec_data.data()); |
| 23 | u32 save_low = data[1]; | 23 | u32 save_low = data[1]; |
| @@ -25,10 +25,27 @@ static std::string GetSystemSaveDataPath(const std::string& mount_point, const P | |||
| 25 | 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); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static std::string GetSystemSaveDataContainerPath(const std::string& mount_point) { | 28 | std::string GetSystemSaveDataContainerPath(const std::string& mount_point) { |
| 29 | 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()); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) { | ||
| 33 | std::vector<u8> binary_path; | ||
| 34 | binary_path.reserve(8); | ||
| 35 | |||
| 36 | // Append each word byte by byte | ||
| 37 | |||
| 38 | // First is the high word | ||
| 39 | for (unsigned i = 0; i < 4; ++i) | ||
| 40 | binary_path.push_back((high >> (8 * i)) & 0xFF); | ||
| 41 | |||
| 42 | // Next is the low word | ||
| 43 | for (unsigned i = 0; i < 4; ++i) | ||
| 44 | binary_path.push_back((low >> (8 * i)) & 0xFF); | ||
| 45 | |||
| 46 | return { binary_path }; | ||
| 47 | } | ||
| 48 | |||
| 32 | ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) | 49 | ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) |
| 33 | : base_path(GetSystemSaveDataContainerPath(nand_path)) { | 50 | : base_path(GetSystemSaveDataContainerPath(nand_path)) { |
| 34 | } | 51 | } |
| @@ -46,6 +63,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c | |||
| 46 | 63 | ||
| 47 | ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path) { | 64 | ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path) { |
| 48 | std::string fullpath = GetSystemSaveDataPath(base_path, path); | 65 | std::string fullpath = GetSystemSaveDataPath(base_path, path); |
| 66 | FileUtil::DeleteDirRecursively(fullpath); | ||
| 49 | FileUtil::CreateFullPath(fullpath); | 67 | FileUtil::CreateFullPath(fullpath); |
| 50 | return RESULT_SUCCESS; | 68 | return RESULT_SUCCESS; |
| 51 | } | 69 | } |
diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h index 556a2a488..3431fed88 100644 --- a/src/core/file_sys/archive_systemsavedata.h +++ b/src/core/file_sys/archive_systemsavedata.h | |||
| @@ -28,4 +28,29 @@ private: | |||
| 28 | std::string base_path; | 28 | std::string base_path; |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | /** | ||
| 32 | * Constructs a path to the concrete SystemSaveData archive in the host filesystem based on the | ||
| 33 | * input Path and base mount point. | ||
| 34 | * @param mount_point The base mount point of the SystemSaveData archives. | ||
| 35 | * @param path The path that identifies the requested concrete SystemSaveData archive. | ||
| 36 | * @returns The complete path to the specified SystemSaveData archive in the host filesystem | ||
| 37 | */ | ||
| 38 | std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path); | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file system. | ||
| 42 | * @param mount_point The base folder where this folder resides, ie. SDMC or NAND. | ||
| 43 | * @returns The path to the base SystemSaveData archives' folder in the host file system | ||
| 44 | */ | ||
| 45 | std::string GetSystemSaveDataContainerPath(const std::string& mount_point); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Constructs a FileSys::Path object that refers to the SystemSaveData archive identified by | ||
| 49 | * the specified high save id and low save id. | ||
| 50 | * @param high The high word of the save id for the archive | ||
| 51 | * @param low The low word of the save id for the archive | ||
| 52 | * @returns A FileSys::Path to the wanted archive | ||
| 53 | */ | ||
| 54 | Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low); | ||
| 55 | |||
| 31 | } // namespace FileSys | 56 | } // namespace FileSys |