2014-12-16 05:33:41 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-12-16 05:33:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-06-21 14:44:11 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2020-01-08 22:13:56 +00:00
|
|
|
#include <boost/serialization/base_object.hpp>
|
|
|
|
#include <boost/serialization/unique_ptr.hpp>
|
2020-04-11 10:52:11 +00:00
|
|
|
#include <boost/serialization/vector.hpp>
|
2014-12-16 05:33:41 +00:00
|
|
|
#include "common/common_types.h"
|
2014-12-21 21:36:18 +00:00
|
|
|
#include "common/file_util.h"
|
2014-12-16 05:33:41 +00:00
|
|
|
#include "core/file_sys/archive_backend.h"
|
2015-05-06 05:15:46 +00:00
|
|
|
#include "core/file_sys/directory_backend.h"
|
|
|
|
#include "core/file_sys/file_backend.h"
|
2015-06-21 14:44:11 +00:00
|
|
|
#include "core/hle/result.h"
|
2014-12-16 05:33:41 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FileSys namespace
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
|
|
|
class DiskFile : public FileBackend {
|
|
|
|
public:
|
2018-02-24 13:14:54 +00:00
|
|
|
DiskFile(FileUtil::IOFile&& file_, const Mode& mode_,
|
|
|
|
std::unique_ptr<DelayGenerator> delay_generator_)
|
2016-10-17 02:10:23 +00:00
|
|
|
: file(new FileUtil::IOFile(std::move(file_))) {
|
2018-02-24 13:14:54 +00:00
|
|
|
delay_generator = std::move(delay_generator_);
|
2016-10-17 02:10:23 +00:00
|
|
|
mode.hex = mode_.hex;
|
|
|
|
}
|
2014-12-18 14:06:37 +00:00
|
|
|
|
2018-09-06 20:03:28 +00:00
|
|
|
ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override;
|
|
|
|
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
|
|
|
|
const u8* buffer) override;
|
2015-07-13 23:43:34 +00:00
|
|
|
u64 GetSize() const override;
|
|
|
|
bool SetSize(u64 size) const override;
|
2014-12-16 05:33:41 +00:00
|
|
|
bool Close() const override;
|
2014-12-18 14:06:37 +00:00
|
|
|
|
2014-12-16 05:33:41 +00:00
|
|
|
void Flush() const override {
|
|
|
|
file->Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Mode mode;
|
2015-01-03 19:15:53 +00:00
|
|
|
std::unique_ptr<FileUtil::IOFile> file;
|
2020-01-08 22:13:56 +00:00
|
|
|
|
2020-04-11 10:52:11 +00:00
|
|
|
private:
|
|
|
|
DiskFile() = default;
|
|
|
|
|
2020-01-08 22:13:56 +00:00
|
|
|
template <class Archive>
|
|
|
|
void serialize(Archive& ar, const unsigned int) {
|
|
|
|
ar& boost::serialization::base_object<FileBackend>(*this);
|
2020-04-11 10:52:11 +00:00
|
|
|
ar& mode.hex;
|
2020-01-08 22:13:56 +00:00
|
|
|
ar& file;
|
|
|
|
}
|
2020-04-11 10:52:11 +00:00
|
|
|
friend class boost::serialization::access;
|
2014-12-16 05:33:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DiskDirectory : public DirectoryBackend {
|
|
|
|
public:
|
2018-03-28 23:43:03 +00:00
|
|
|
explicit DiskDirectory(const std::string& path);
|
2014-12-16 05:33:41 +00:00
|
|
|
|
|
|
|
~DiskDirectory() override {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:41:29 +00:00
|
|
|
u32 Read(u32 count, Entry* entries) override;
|
2014-12-16 05:33:41 +00:00
|
|
|
|
|
|
|
bool Close() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-03-28 23:40:30 +00:00
|
|
|
FileUtil::FSTEntry directory{};
|
2014-12-16 05:33:41 +00:00
|
|
|
|
|
|
|
// 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;
|
2020-04-11 10:52:11 +00:00
|
|
|
|
|
|
|
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;
|
2014-12-16 05:33:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|
2020-04-11 10:52:11 +00:00
|
|
|
|
|
|
|
BOOST_CLASS_EXPORT_KEY(FileSys::DiskFile)
|
|
|
|
BOOST_CLASS_EXPORT_KEY(FileSys::DiskDirectory)
|