Skip to content

Commit

Permalink
Serialize file system
Browse files Browse the repository at this point in the history
This fixes #108
  • Loading branch information
momo5502 committed Jan 25, 2025
1 parent 376015a commit 0454120
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/windows-emulator/file_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_{};
Expand Down
12 changes: 10 additions & 2 deletions src/windows-emulator/windows_emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,18 +1111,24 @@ 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);
}

void windows_emulator::deserialize(utils::buffer_deserializer& buffer)
{
buffer.register_factory<x64_emulator_wrapper>([this] { return x64_emulator_wrapper{this->emu()}; });
buffer.register_factory<x64_emulator_wrapper>([this] {
return x64_emulator_wrapper{this->emu()}; //
});

buffer.register_factory<windows_emulator_wrapper>([this] { return windows_emulator_wrapper{*this}; });
buffer.register_factory<windows_emulator_wrapper>([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);
Expand All @@ -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();
Expand All @@ -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_;
}

0 comments on commit 0454120

Please sign in to comment.