From 2bf5b464609348e786a068074d41e74fb5331a35 Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Thu, 2 Jan 2020 23:34:26 +0000 Subject: [PATCH] Basic archive backend serialization --- TODO | 23 +++++++------ src/core/file_sys/archive_extsavedata.cpp | 3 ++ src/core/file_sys/archive_extsavedata.h | 12 +++++++ src/core/file_sys/archive_ncch.cpp | 5 +++ src/core/file_sys/archive_ncch.h | 34 ++++++++++++++++++- src/core/file_sys/archive_other_savedata.cpp | 4 +++ src/core/file_sys/archive_other_savedata.h | 23 +++++++++++-- src/core/file_sys/archive_savedata.cpp | 3 ++ src/core/file_sys/archive_savedata.h | 12 ++++++- src/core/file_sys/archive_sdmc.cpp | 4 +++ src/core/file_sys/archive_sdmc.h | 21 ++++++++++++ src/core/file_sys/archive_sdmcwriteonly.cpp | 4 +++ src/core/file_sys/archive_sdmcwriteonly.h | 18 ++++++++++ .../file_sys/archive_source_sd_savedata.cpp | 3 ++ .../file_sys/archive_source_sd_savedata.h | 11 ++++++ src/core/file_sys/archive_systemsavedata.cpp | 3 ++ src/core/file_sys/archive_systemsavedata.h | 11 ++++++ src/core/file_sys/file_backend.h | 7 +++- 18 files changed, 185 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index 5ea46f2e8..c1f5e49cd 100644 --- a/TODO +++ b/TODO @@ -10,19 +10,20 @@ ✘ App loader @cancelled(20-01-01 22:59) No relevant state ☐ Archive manager @started(20-01-01 23:03) - ☐ NCCH - ☐ Normal + ☐ NCCH @started(20-01-02 22:50) + ✔ Normal @done(20-01-02 22:50) ☐ Self - ☐ SaveData - ☐ Normal - ☐ Ext - ☐ Other - ☐ Source SD - ☐ System - ☐ SDMC - ☐ Normal - ☐ Write-only + ✔ SaveData @started(20-01-02 23:03) @done(20-01-02 23:27) @lasted(25m) + ✔ Normal @done(20-01-02 23:03) + ✔ Ext @done(20-01-02 23:26) + ✔ Other @done(20-01-02 23:21) + ✔ Source SD @done(20-01-02 23:03) + ✔ System @done(20-01-02 23:13) + ✔ SDMC @done(20-01-02 23:34) + ✔ Normal @done(20-01-02 23:34) + ✔ Write-only @done(20-01-02 23:34) ☐ File refs + ☐ Replace delay generator with virtual fns ☐ Custom texture cache ✘ MMIO @cancelled(20-01-01 01:06) Seems that this whole subsystem is only used in tests diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index efcdb2d7f..22084b690 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "common/archives.h" #include "common/common_types.h" #include "common/file_util.h" #include "common/logging/log.h" @@ -19,6 +20,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_ExtSaveData) + namespace FileSys { /** diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index 7dc345c84..b00e1633d 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h @@ -6,6 +6,8 @@ #include #include +#include +#include #include "common/common_types.h" #include "core/file_sys/archive_backend.h" #include "core/hle/result.h" @@ -54,6 +56,14 @@ private: /// Returns a path with the correct SaveIdHigh value for Shared extdata paths. Path GetCorrectedPath(const Path& path); + + ArchiveFactory_ExtSaveData() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& shared; + ar& mount_point; + } + friend class boost::serialization::access; }; /** @@ -94,3 +104,5 @@ std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low); } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_ExtSaveData) diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 06fe69622..789547f0e 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -8,6 +8,7 @@ #include #include #include "bad_word_list.app.romfs.h" +#include "common/archives.h" #include "common/common_types.h" #include "common/file_util.h" #include "common/logging/log.h" @@ -28,6 +29,10 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::NCCHArchive) +SERIALIZE_EXPORT_IMPL(FileSys::NCCHFile) +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_NCCH) + namespace FileSys { struct NCCHArchivePath { diff --git a/src/core/file_sys/archive_ncch.h b/src/core/file_sys/archive_ncch.h index 28d9ff044..52ae827c3 100644 --- a/src/core/file_sys/archive_ncch.h +++ b/src/core/file_sys/archive_ncch.h @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "core/file_sys/archive_backend.h" #include "core/file_sys/file_backend.h" #include "core/hle/result.h" @@ -63,6 +66,17 @@ public: protected: u64 title_id; Service::FS::MediaType media_type; + +private: + NCCHArchive() = default; // NOTE: If the public ctor has behaviour, need to replace this with + // *_construct_data + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& title_id; + ar& media_type; + } + friend class boost::serialization::access; }; // File backend for NCCH files @@ -81,7 +95,16 @@ public: void Flush() const override {} private: - std::vector file_buffer; + NCCHFile() = default; // NOTE: If the public ctor has behaviour, need to replace this with + // *_construct_data + std::vector file_buffer; // TODO: Replace with file ref for serialization + + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& file_buffer; + } + friend class boost::serialization::access; }; /// File system interface to the NCCH archive @@ -97,6 +120,15 @@ public: ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, u64 program_id) override; ResultVal GetFormatInfo(const Path& path, u64 program_id) const override; + +private: + template + void serialize(Archive& ar, const unsigned int) {} + friend class boost::serialization::access; }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::NCCHArchive) +BOOST_CLASS_EXPORT_KEY(FileSys::NCCHFile) +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_NCCH) diff --git a/src/core/file_sys/archive_other_savedata.cpp b/src/core/file_sys/archive_other_savedata.cpp index 1c3b071ba..d4f8debc4 100644 --- a/src/core/file_sys/archive_other_savedata.cpp +++ b/src/core/file_sys/archive_other_savedata.cpp @@ -4,6 +4,7 @@ #include #include +#include "common/archives.h" #include "core/file_sys/archive_other_savedata.h" #include "core/file_sys/errors.h" #include "core/hle/kernel/process.h" @@ -12,6 +13,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_OtherSaveDataPermitted) +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_OtherSaveDataGeneral) + namespace FileSys { // TODO(wwylele): The storage info in exheader should be checked before accessing these archives diff --git a/src/core/file_sys/archive_other_savedata.h b/src/core/file_sys/archive_other_savedata.h index e3e8f83c3..a9deae95a 100644 --- a/src/core/file_sys/archive_other_savedata.h +++ b/src/core/file_sys/archive_other_savedata.h @@ -4,6 +4,8 @@ #pragma once +#include +#include #include "core/file_sys/archive_source_sd_savedata.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -27,8 +29,15 @@ public: ResultVal GetFormatInfo(const Path& path, u64 program_id) const override; private: - std::string mount_point; + std::string mount_point; // TODO: Remove, unused? std::shared_ptr sd_savedata_source; + + ArchiveFactory_OtherSaveDataPermitted() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& sd_savedata_source; + } + friend class boost::serialization::access; }; /// File system interface to the OtherSaveDataGeneral archive @@ -47,8 +56,18 @@ public: ResultVal GetFormatInfo(const Path& path, u64 program_id) const override; private: - std::string mount_point; + std::string mount_point; // TODO: Remove, unused? std::shared_ptr sd_savedata_source; + + ArchiveFactory_OtherSaveDataGeneral() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& sd_savedata_source; + } + friend class boost::serialization::access; }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_OtherSaveDataPermitted) +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_OtherSaveDataGeneral) diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index c1046e2f5..fc4bd34fa 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include "common/archives.h" #include "core/core.h" #include "core/file_sys/archive_savedata.h" #include "core/hle/kernel/process.h" @@ -10,6 +11,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SaveData) + namespace FileSys { ArchiveFactory_SaveData::ArchiveFactory_SaveData( diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h index 591a3b900..3ebe94a63 100644 --- a/src/core/file_sys/archive_savedata.h +++ b/src/core/file_sys/archive_savedata.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/file_sys/archive_source_sd_savedata.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -27,8 +28,17 @@ public: ResultVal GetFormatInfo(const Path& path, u64 program_id) const override; private: - std::string mount_point; + std::string mount_point; // TODO: Remove this? seems unused std::shared_ptr sd_savedata_source; + + ArchiveFactory_SaveData() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& sd_savedata_source; + } + friend class boost::serialization::access; }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SaveData) diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index d2269fe7c..1c5118320 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp @@ -4,6 +4,7 @@ #include #include +#include "common/archives.h" #include "common/file_util.h" #include "common/logging/log.h" #include "core/file_sys/archive_sdmc.h" @@ -15,6 +16,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::SDMCArchive) +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SDMC) + namespace FileSys { class SDMCDelayGenerator : public DelayGenerator { diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 41d7b7c59..2e0abf44b 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h @@ -6,6 +6,9 @@ #include #include +#include +#include +#include #include "core/file_sys/archive_backend.h" #include "core/hle/result.h" @@ -42,6 +45,14 @@ public: protected: ResultVal> OpenFileBase(const Path& path, const Mode& mode) const; std::string mount_point; + + SDMCArchive() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& mount_point; + } + friend class boost::serialization::access; }; /// File system interface to the SDMC archive @@ -66,6 +77,16 @@ public: private: std::string sdmc_directory; + + ArchiveFactory_SDMC() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& sdmc_directory; + } + friend class boost::serialization::access; }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::SDMCArchive) +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SDMC) diff --git a/src/core/file_sys/archive_sdmcwriteonly.cpp b/src/core/file_sys/archive_sdmcwriteonly.cpp index 74552d751..ea64dc864 100644 --- a/src/core/file_sys/archive_sdmcwriteonly.cpp +++ b/src/core/file_sys/archive_sdmcwriteonly.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include "common/archives.h" #include "common/file_util.h" #include "core/file_sys/archive_sdmcwriteonly.h" #include "core/file_sys/directory_backend.h" @@ -13,6 +14,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::SDMCWriteOnlyArchive) +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SDMCWriteOnly) + namespace FileSys { class SDMCWriteOnlyDelayGenerator : public DelayGenerator { diff --git a/src/core/file_sys/archive_sdmcwriteonly.h b/src/core/file_sys/archive_sdmcwriteonly.h index 8191f053f..2ba504aa7 100644 --- a/src/core/file_sys/archive_sdmcwriteonly.h +++ b/src/core/file_sys/archive_sdmcwriteonly.h @@ -31,6 +31,14 @@ public: const Mode& mode) const override; ResultVal> OpenDirectory(const Path& path) const override; + +private: + SDMCWriteOnlyArchive() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + } + friend class boost::serialization::access; }; /// File system interface to the SDMC write-only archive @@ -55,6 +63,16 @@ public: private: std::string sdmc_directory; + + ArchiveFactory_SDMCWriteOnly() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& sdmc_directory; + } + friend class boost::serialization::access; }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::SDMCWriteOnlyArchive) +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SDMCWriteOnly) diff --git a/src/core/file_sys/archive_source_sd_savedata.cpp b/src/core/file_sys/archive_source_sd_savedata.cpp index 0b8072b96..9afbfd73c 100644 --- a/src/core/file_sys/archive_source_sd_savedata.cpp +++ b/src/core/file_sys/archive_source_sd_savedata.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include "common/archives.h" #include "common/file_util.h" #include "common/logging/log.h" #include "core/file_sys/archive_source_sd_savedata.h" @@ -13,6 +14,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveSource_SDSaveData) + namespace FileSys { namespace { diff --git a/src/core/file_sys/archive_source_sd_savedata.h b/src/core/file_sys/archive_source_sd_savedata.h index b5fe43cc1..4ac028a3d 100644 --- a/src/core/file_sys/archive_source_sd_savedata.h +++ b/src/core/file_sys/archive_source_sd_savedata.h @@ -6,6 +6,8 @@ #include #include +#include +#include #include "core/file_sys/archive_backend.h" #include "core/hle/result.h" @@ -27,6 +29,15 @@ public: private: std::string mount_point; + + ArchiveSource_SDSaveData() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& mount_point; + } + friend class boost::serialization::access; }; } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveSource_SDSaveData) diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index cef42e561..ecfb34219 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "common/archives.h" #include "common/common_types.h" #include "common/file_util.h" #include "core/file_sys/archive_systemsavedata.h" @@ -17,6 +18,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// // FileSys namespace +SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SystemSaveData) + namespace FileSys { std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) { diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h index e72ecce3a..cf18cab89 100644 --- a/src/core/file_sys/archive_systemsavedata.h +++ b/src/core/file_sys/archive_systemsavedata.h @@ -6,6 +6,8 @@ #include #include +#include +#include #include "common/common_types.h" #include "core/file_sys/archive_backend.h" #include "core/hle/result.h" @@ -31,6 +33,13 @@ public: private: std::string base_path; + + ArchiveFactory_SystemSaveData() = default; + template + void serialize(Archive& ar, const unsigned int) { + ar& base_path; + } + friend class boost::serialization::access; }; /** @@ -60,3 +69,5 @@ std::string GetSystemSaveDataContainerPath(const std::string& mount_point); Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low); } // namespace FileSys + +BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SystemSaveData) diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h index c865c98e8..03dff156d 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/file_backend.h @@ -89,7 +89,12 @@ public: virtual void Flush() const = 0; protected: - std::unique_ptr delay_generator; + std::unique_ptr delay_generator; // TODO: replace with virtual Get*DelayNs + +private: + template + void serialize(Archive& ar, const unsigned int) {} + friend class boost::serialization::access; }; } // namespace FileSys