mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	Serialize file/directory services
This commit is contained in:
		
							parent
							
								
									9525d81344
								
							
						
					
					
						commit
						ca971ff31f
					
				
					 7 changed files with 81 additions and 3 deletions
				
			
		|  | @ -8,6 +8,8 @@ | |||
| #include <string> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
| #include <boost/serialization/string.hpp> | ||||
| #include <boost/serialization/vector.hpp> | ||||
| #include "common/bit_field.h" | ||||
| #include "common/common_types.h" | ||||
| #include "common/swap.h" | ||||
|  | @ -63,7 +65,33 @@ private: | |||
|     LowPathType type; | ||||
|     std::vector<u8> binary; | ||||
|     std::string string; | ||||
|     std::u16string u16str; | ||||
|     std::u16string u16str{}; | ||||
| 
 | ||||
|     template <class Archive> | ||||
|     void serialize(Archive& ar, const unsigned int) { | ||||
|         ar& type; | ||||
|         switch (type) { | ||||
|         case LowPathType::Binary: | ||||
|             ar& binary; | ||||
|             break; | ||||
|         case LowPathType::Char: | ||||
|             ar& string; | ||||
|             break; | ||||
|         case LowPathType::Wchar: | ||||
|             static_assert(sizeof(wchar_t) == sizeof(char16_t)); | ||||
|             { | ||||
|                 std::wstring wstring(reinterpret_cast<wchar_t*>(u16str.data())); | ||||
|                 ar& wstring; | ||||
|                 if (!Archive::is_saving::value) { | ||||
|                     u16str = std::u16string(reinterpret_cast<char16_t*>(wstring.data())); | ||||
|                 } | ||||
|             } | ||||
|             break; | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
|     friend class boost::serialization::access; | ||||
| }; | ||||
| 
 | ||||
| /// Parameters of the archive, as specified in the Create or Format call.
 | ||||
|  |  | |||
|  | @ -53,6 +53,11 @@ public: | |||
|      * @return true if the directory closed correctly | ||||
|      */ | ||||
|     virtual bool Close() const = 0; | ||||
| 
 | ||||
| private: | ||||
|     template <class Archive> | ||||
|     void serialize(Archive& ar, const unsigned int) {} | ||||
|     friend class boost::serialization::access; | ||||
| }; | ||||
| 
 | ||||
| } // namespace FileSys
 | ||||
|  |  | |||
|  | @ -2,13 +2,25 @@ | |||
| // Licensed under GPLv2 or any later version
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include "common/archives.h" | ||||
| #include "common/logging/log.h" | ||||
| #include "core/file_sys/directory_backend.h" | ||||
| #include "core/hle/ipc_helpers.h" | ||||
| #include "core/hle/service/fs/directory.h" | ||||
| 
 | ||||
| SERIALIZE_EXPORT_IMPL(Service::FS::Directory) | ||||
| 
 | ||||
| namespace Service::FS { | ||||
| 
 | ||||
| template <class Archive> | ||||
| void Directory::serialize(Archive& ar, const unsigned int) { | ||||
|     ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this); | ||||
|     ar& path; | ||||
|     ar& backend; | ||||
| } | ||||
| 
 | ||||
| Directory::Directory() : ServiceFramework("", 1) {} | ||||
| 
 | ||||
| Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, | ||||
|                      const FileSys::Path& path) | ||||
|     : ServiceFramework("", 1), path(path), backend(std::move(backend)) { | ||||
|  |  | |||
|  | @ -25,6 +25,15 @@ public: | |||
| protected: | ||||
|     void Read(Kernel::HLERequestContext& ctx); | ||||
|     void Close(Kernel::HLERequestContext& ctx); | ||||
| 
 | ||||
| private: | ||||
|     Directory(); | ||||
| 
 | ||||
|     template <class Archive> | ||||
|     void serialize(Archive& ar, const unsigned int); | ||||
|     friend class boost::serialization::access; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Service::FS
 | ||||
| 
 | ||||
| BOOST_CLASS_EXPORT_KEY(Service::FS::Directory) | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ | |||
| // Licensed under GPLv2 or any later version
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include "common/archives.h" | ||||
| #include "common/logging/log.h" | ||||
| #include "core/core.h" | ||||
| #include "core/file_sys/errors.h" | ||||
|  | @ -13,8 +14,20 @@ | |||
| #include "core/hle/kernel/server_session.h" | ||||
| #include "core/hle/service/fs/file.h" | ||||
| 
 | ||||
| SERIALIZE_EXPORT_IMPL(Service::FS::File) | ||||
| SERIALIZE_EXPORT_IMPL(Service::FS::FileSessionSlot) | ||||
| 
 | ||||
| namespace Service::FS { | ||||
| 
 | ||||
| template <class Archive> | ||||
| void File::serialize(Archive& ar, const unsigned int) { | ||||
|     ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this); | ||||
|     ar& path; | ||||
|     ar& backend; | ||||
| } | ||||
| 
 | ||||
| File::File() : ServiceFramework("", 1), kernel(Core::Global<Kernel::KernelSystem>()) {} | ||||
| 
 | ||||
| File::File(Kernel::KernelSystem& kernel, std::unique_ptr<FileSys::FileBackend>&& backend, | ||||
|            const FileSys::Path& path) | ||||
|     : ServiceFramework("", 1), path(path), backend(std::move(backend)), kernel(kernel) { | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ | |||
| 
 | ||||
| #include <memory> | ||||
| #include "core/file_sys/archive_backend.h" | ||||
| #include "core/global.h" | ||||
| #include "core/hle/service/service.h" | ||||
| 
 | ||||
| namespace Core { | ||||
|  | @ -30,6 +31,7 @@ private: | |||
|         ar& size; | ||||
|         ar& subfile; | ||||
|     } | ||||
|     friend class boost::serialization::access; | ||||
| }; | ||||
| 
 | ||||
| // TODO: File is not a real service, but it can still utilize ServiceFramework::RegisterHandlers.
 | ||||
|  | @ -71,6 +73,15 @@ private: | |||
|     void OpenSubFile(Kernel::HLERequestContext& ctx); | ||||
| 
 | ||||
|     Kernel::KernelSystem& kernel; | ||||
| 
 | ||||
|     File(); | ||||
| 
 | ||||
|     template <class Archive> | ||||
|     void serialize(Archive& ar, const unsigned int); | ||||
|     friend class boost::serialization::access; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Service::FS
 | ||||
| 
 | ||||
| BOOST_CLASS_EXPORT_KEY(Service::FS::FileSessionSlot) | ||||
| BOOST_CLASS_EXPORT_KEY(Service::FS::File) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue