From 0454120f45cb42431434aff64c67fff5eea4da5d Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 07:47:04 +0100 Subject: [PATCH] Serialize file system This fixes #108 --- src/windows-emulator/file_system.hpp | 10 ++++++++++ src/windows-emulator/windows_emulator.cpp | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/windows-emulator/file_system.hpp b/src/windows-emulator/file_system.hpp index 89a1f1f..a9a1e23 100644 --- a/src/windows-emulator/file_system.hpp +++ b/src/windows-emulator/file_system.hpp @@ -61,6 +61,16 @@ class file_system return windows_path{drive, std::move(folders)}; } + void serialize(utils::buffer_serializer& buffer) const + { + buffer.write(this->working_dir_); + } + + void deserialize(utils::buffer_deserializer& buffer) + { + buffer.read(this->working_dir_); + } + private: std::filesystem::path root_{}; windows_path working_dir_{}; diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index ab0cd20..f944849 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -1111,6 +1111,7 @@ void windows_emulator::start(std::chrono::nanoseconds timeout, size_t count) void windows_emulator::serialize(utils::buffer_serializer& buffer) const { buffer.write(this->use_relative_time_); + this->file_sys.serialize(buffer); this->emu().serialize(buffer); this->process_.serialize(buffer); this->dispatcher_.serialize(buffer); @@ -1118,11 +1119,16 @@ void windows_emulator::serialize(utils::buffer_serializer& buffer) const void windows_emulator::deserialize(utils::buffer_deserializer& buffer) { - buffer.register_factory([this] { return x64_emulator_wrapper{this->emu()}; }); + buffer.register_factory([this] { + return x64_emulator_wrapper{this->emu()}; // + }); - buffer.register_factory([this] { return windows_emulator_wrapper{*this}; }); + buffer.register_factory([this] { + return windows_emulator_wrapper{*this}; // + }); buffer.read(this->use_relative_time_); + this->file_sys.deserialize(buffer); this->emu().deserialize(buffer); this->process_.deserialize(buffer); @@ -1134,6 +1140,7 @@ void windows_emulator::save_snapshot() this->emu().save_snapshot(); utils::buffer_serializer serializer{}; + this->file_sys.serialize(serializer); this->process_.serialize(serializer); this->process_snapshot_ = serializer.move_buffer(); @@ -1153,6 +1160,7 @@ void windows_emulator::restore_snapshot() this->emu().restore_snapshot(); utils::buffer_deserializer deserializer{this->process_snapshot_}; + this->file_sys.deserialize(deserializer); this->process_.deserialize(deserializer); // this->process_ = *this->process_snapshot_; }