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>
|
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
|
|
|
|
2015-12-28 15:03:09 +00:00
|
|
|
ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
|
2017-10-25 23:55:11 +00:00
|
|
|
ResultVal<size_t> Write(u64 offset, 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;
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|