citra-emu
/
citra-canary
Archived
1
0
Fork 0

Basic archive backend serialization

This commit is contained in:
Hamish Milne 2020-01-02 23:34:26 +00:00 committed by zhupengfei
parent 2d2c7218ef
commit 2bf5b46460
18 changed files with 185 additions and 16 deletions

23
TODO
View File

@ -10,19 +10,20 @@
✘ App loader @cancelled(20-01-01 22:59) ✘ App loader @cancelled(20-01-01 22:59)
No relevant state No relevant state
☐ Archive manager @started(20-01-01 23:03) ☐ Archive manager @started(20-01-01 23:03)
☐ NCCH ☐ NCCH @started(20-01-02 22:50)
☐ Normal ✔ Normal @done(20-01-02 22:50)
☐ Self ☐ Self
☐ SaveData ✔ SaveData @started(20-01-02 23:03) @done(20-01-02 23:27) @lasted(25m)
☐ Normal ✔ Normal @done(20-01-02 23:03)
☐ Ext ✔ Ext @done(20-01-02 23:26)
☐ Other ✔ Other @done(20-01-02 23:21)
☐ Source SD ✔ Source SD @done(20-01-02 23:03)
☐ System ✔ System @done(20-01-02 23:13)
☐ SDMC ✔ SDMC @done(20-01-02 23:34)
☐ Normal ✔ Normal @done(20-01-02 23:34)
☐ Write-only ✔ Write-only @done(20-01-02 23:34)
☐ File refs ☐ File refs
☐ Replace delay generator with virtual fns
☐ Custom texture cache ☐ Custom texture cache
✘ MMIO @cancelled(20-01-01 01:06) ✘ MMIO @cancelled(20-01-01 01:06)
Seems that this whole subsystem is only used in tests Seems that this whole subsystem is only used in tests

View File

@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <fmt/format.h> #include <fmt/format.h>
#include "common/archives.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
@ -19,6 +20,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_ExtSaveData)
namespace FileSys { namespace FileSys {
/** /**

View File

@ -6,6 +6,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <boost/serialization/export.hpp>
#include <boost/serialization/string.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
#include "core/hle/result.h" #include "core/hle/result.h"
@ -54,6 +56,14 @@ private:
/// Returns a path with the correct SaveIdHigh value for Shared extdata paths. /// Returns a path with the correct SaveIdHigh value for Shared extdata paths.
Path GetCorrectedPath(const Path& path); Path GetCorrectedPath(const Path& path);
ArchiveFactory_ExtSaveData() = default;
template <class Archive>
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); Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low);
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_ExtSaveData)

View File

@ -8,6 +8,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "bad_word_list.app.romfs.h" #include "bad_word_list.app.romfs.h"
#include "common/archives.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
@ -28,6 +29,10 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::NCCHArchive)
SERIALIZE_EXPORT_IMPL(FileSys::NCCHFile)
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_NCCH)
namespace FileSys { namespace FileSys {
struct NCCHArchivePath { struct NCCHArchivePath {

View File

@ -7,6 +7,9 @@
#include <array> #include <array>
#include <memory> #include <memory>
#include <string> #include <string>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/vector.hpp>
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
#include "core/file_sys/file_backend.h" #include "core/file_sys/file_backend.h"
#include "core/hle/result.h" #include "core/hle/result.h"
@ -63,6 +66,17 @@ public:
protected: protected:
u64 title_id; u64 title_id;
Service::FS::MediaType media_type; Service::FS::MediaType media_type;
private:
NCCHArchive() = default; // NOTE: If the public ctor has behaviour, need to replace this with
// *_construct_data
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveBackend>(*this);
ar& title_id;
ar& media_type;
}
friend class boost::serialization::access;
}; };
// File backend for NCCH files // File backend for NCCH files
@ -81,7 +95,16 @@ public:
void Flush() const override {} void Flush() const override {}
private: private:
std::vector<u8> file_buffer; NCCHFile() = default; // NOTE: If the public ctor has behaviour, need to replace this with
// *_construct_data
std::vector<u8> file_buffer; // TODO: Replace with file ref for serialization
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<FileBackend>(*this);
ar& file_buffer;
}
friend class boost::serialization::access;
}; };
/// File system interface to the NCCH archive /// File system interface to the NCCH archive
@ -97,6 +120,15 @@ public:
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
u64 program_id) override; u64 program_id) override;
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::NCCHArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::NCCHFile)
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_NCCH)

View File

@ -4,6 +4,7 @@
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include "common/archives.h"
#include "core/file_sys/archive_other_savedata.h" #include "core/file_sys/archive_other_savedata.h"
#include "core/file_sys/errors.h" #include "core/file_sys/errors.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
@ -12,6 +13,9 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_OtherSaveDataPermitted)
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_OtherSaveDataGeneral)
namespace FileSys { namespace FileSys {
// TODO(wwylele): The storage info in exheader should be checked before accessing these archives // TODO(wwylele): The storage info in exheader should be checked before accessing these archives

View File

@ -4,6 +4,8 @@
#pragma once #pragma once
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "core/file_sys/archive_source_sd_savedata.h" #include "core/file_sys/archive_source_sd_savedata.h"
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -27,8 +29,15 @@ public:
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
private: private:
std::string mount_point; std::string mount_point; // TODO: Remove, unused?
std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source; std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source;
ArchiveFactory_OtherSaveDataPermitted() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& sd_savedata_source;
}
friend class boost::serialization::access;
}; };
/// File system interface to the OtherSaveDataGeneral archive /// File system interface to the OtherSaveDataGeneral archive
@ -47,8 +56,18 @@ public:
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
private: private:
std::string mount_point; std::string mount_point; // TODO: Remove, unused?
std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source; std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source;
ArchiveFactory_OtherSaveDataGeneral() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& sd_savedata_source;
}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_OtherSaveDataPermitted)
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_OtherSaveDataGeneral)

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <utility> #include <utility>
#include "common/archives.h"
#include "core/core.h" #include "core/core.h"
#include "core/file_sys/archive_savedata.h" #include "core/file_sys/archive_savedata.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
@ -10,6 +11,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SaveData)
namespace FileSys { namespace FileSys {
ArchiveFactory_SaveData::ArchiveFactory_SaveData( ArchiveFactory_SaveData::ArchiveFactory_SaveData(

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <boost/serialization/shared_ptr.hpp>
#include "core/file_sys/archive_source_sd_savedata.h" #include "core/file_sys/archive_source_sd_savedata.h"
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -27,8 +28,17 @@ public:
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
private: private:
std::string mount_point; std::string mount_point; // TODO: Remove this? seems unused
std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source; std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source;
ArchiveFactory_SaveData() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& sd_savedata_source;
}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SaveData)

View File

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include "common/archives.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/file_sys/archive_sdmc.h" #include "core/file_sys/archive_sdmc.h"
@ -15,6 +16,9 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::SDMCArchive)
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SDMC)
namespace FileSys { namespace FileSys {
class SDMCDelayGenerator : public DelayGenerator { class SDMCDelayGenerator : public DelayGenerator {

View File

@ -6,6 +6,9 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/string.hpp>
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
#include "core/hle/result.h" #include "core/hle/result.h"
@ -42,6 +45,14 @@ public:
protected: protected:
ResultVal<std::unique_ptr<FileBackend>> OpenFileBase(const Path& path, const Mode& mode) const; ResultVal<std::unique_ptr<FileBackend>> OpenFileBase(const Path& path, const Mode& mode) const;
std::string mount_point; std::string mount_point;
SDMCArchive() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveBackend>(*this);
ar& mount_point;
}
friend class boost::serialization::access;
}; };
/// File system interface to the SDMC archive /// File system interface to the SDMC archive
@ -66,6 +77,16 @@ public:
private: private:
std::string sdmc_directory; std::string sdmc_directory;
ArchiveFactory_SDMC() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& sdmc_directory;
}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::SDMCArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SDMC)

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <memory> #include <memory>
#include "common/archives.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "core/file_sys/archive_sdmcwriteonly.h" #include "core/file_sys/archive_sdmcwriteonly.h"
#include "core/file_sys/directory_backend.h" #include "core/file_sys/directory_backend.h"
@ -13,6 +14,9 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::SDMCWriteOnlyArchive)
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SDMCWriteOnly)
namespace FileSys { namespace FileSys {
class SDMCWriteOnlyDelayGenerator : public DelayGenerator { class SDMCWriteOnlyDelayGenerator : public DelayGenerator {

View File

@ -31,6 +31,14 @@ public:
const Mode& mode) const override; const Mode& mode) const override;
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override; ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
private:
SDMCWriteOnlyArchive() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<SDMCArchive>(*this);
}
friend class boost::serialization::access;
}; };
/// File system interface to the SDMC write-only archive /// File system interface to the SDMC write-only archive
@ -55,6 +63,16 @@ public:
private: private:
std::string sdmc_directory; std::string sdmc_directory;
ArchiveFactory_SDMCWriteOnly() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& sdmc_directory;
}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::SDMCWriteOnlyArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SDMCWriteOnly)

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <fmt/format.h> #include <fmt/format.h>
#include "common/archives.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/file_sys/archive_source_sd_savedata.h" #include "core/file_sys/archive_source_sd_savedata.h"
@ -13,6 +14,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveSource_SDSaveData)
namespace FileSys { namespace FileSys {
namespace { namespace {

View File

@ -6,6 +6,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <boost/serialization/export.hpp>
#include <boost/serialization/string.hpp>
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
#include "core/hle/result.h" #include "core/hle/result.h"
@ -27,6 +29,15 @@ public:
private: private:
std::string mount_point; std::string mount_point;
ArchiveSource_SDSaveData() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& mount_point;
}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveSource_SDSaveData)

View File

@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <fmt/format.h> #include <fmt/format.h>
#include "common/archives.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "core/file_sys/archive_systemsavedata.h" #include "core/file_sys/archive_systemsavedata.h"
@ -17,6 +18,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace // FileSys namespace
SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SystemSaveData)
namespace FileSys { namespace FileSys {
std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) { std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) {

View File

@ -6,6 +6,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <boost/serialization/export.hpp>
#include <boost/serialization/string.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
#include "core/hle/result.h" #include "core/hle/result.h"
@ -31,6 +33,13 @@ public:
private: private:
std::string base_path; std::string base_path;
ArchiveFactory_SystemSaveData() = default;
template <class Archive>
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); Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low);
} // namespace FileSys } // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::ArchiveFactory_SystemSaveData)

View File

@ -89,7 +89,12 @@ public:
virtual void Flush() const = 0; virtual void Flush() const = 0;
protected: protected:
std::unique_ptr<DelayGenerator> delay_generator; std::unique_ptr<DelayGenerator> delay_generator; // TODO: replace with virtual Get*DelayNs
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {}
friend class boost::serialization::access;
}; };
} // namespace FileSys } // namespace FileSys