Add disk archive serialization (fix crash in driver renegade etc.)
This commit is contained in:
parent
a210e7e2bd
commit
e9ab8f82d4
3 changed files with 83 additions and 23 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include "common/archives.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
|
@ -14,6 +15,9 @@
|
|||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
||||
SERIALIZE_EXPORT_IMPL(FileSys::DiskFile)
|
||||
SERIALIZE_EXPORT_IMPL(FileSys::DiskDirectory)
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length,
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <vector>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/unique_ptr.hpp>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
#include "core/file_sys/archive_backend.h"
|
||||
|
@ -46,12 +47,16 @@ protected:
|
|||
Mode mode;
|
||||
std::unique_ptr<FileUtil::IOFile> file;
|
||||
|
||||
private:
|
||||
DiskFile() = default;
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive& ar, const unsigned int) {
|
||||
ar& boost::serialization::base_object<FileBackend>(*this);
|
||||
ar& mode;
|
||||
ar& mode.hex;
|
||||
ar& file;
|
||||
}
|
||||
friend class boost::serialization::access;
|
||||
};
|
||||
|
||||
class DiskDirectory : public DirectoryBackend {
|
||||
|
@ -74,6 +79,27 @@ protected:
|
|||
// We need to remember the last entry we returned, so a subsequent call to Read will continue
|
||||
// from the next one. This iterator will always point to the next unread entry.
|
||||
std::vector<FileUtil::FSTEntry>::iterator children_iterator;
|
||||
|
||||
private:
|
||||
DiskDirectory() = default;
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive& ar, const unsigned int) {
|
||||
ar& boost::serialization::base_object<DirectoryBackend>(*this);
|
||||
ar& directory;
|
||||
u64 child_index;
|
||||
if (Archive::is_saving::value) {
|
||||
child_index = children_iterator - directory.children.begin();
|
||||
}
|
||||
ar& child_index;
|
||||
if (Archive::is_loading::value) {
|
||||
children_iterator = directory.children.begin() + child_index;
|
||||
}
|
||||
}
|
||||
friend class boost::serialization::access;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
||||
|
||||
BOOST_CLASS_EXPORT_KEY(FileSys::DiskFile)
|
||||
BOOST_CLASS_EXPORT_KEY(FileSys::DiskDirectory)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue