Making stateless file IO platform-agnostic.
This commit is contained in:
@@ -11,14 +11,12 @@
|
||||
#define XENIA_BASE_FILESYSTEM_H_
|
||||
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "xenia/base/string.h"
|
||||
|
||||
// TOODO(benvanik): remove windows headers.
|
||||
#undef DeleteFile
|
||||
|
||||
namespace xe {
|
||||
namespace filesystem {
|
||||
|
||||
@@ -33,6 +31,50 @@ bool IsFolder(const std::wstring& path);
|
||||
FILE* OpenFile(const std::wstring& path, const char* mode);
|
||||
bool DeleteFile(const std::wstring& path);
|
||||
|
||||
struct FileAccess {
|
||||
// Implies kFileReadData.
|
||||
static const uint32_t kGenericRead = 0x80000000;
|
||||
// Implies kFileWriteData.
|
||||
static const uint32_t kGenericWrite = 0x40000000;
|
||||
static const uint32_t kGenericExecute = 0x20000000;
|
||||
static const uint32_t kGenericAll = 0x10000000;
|
||||
static const uint32_t kFileReadData = 0x00000001;
|
||||
static const uint32_t kFileWriteData = 0x00000002;
|
||||
static const uint32_t kFileAppendData = 0x00000004;
|
||||
};
|
||||
|
||||
class FileHandle {
|
||||
public:
|
||||
// Opens the file, failing if it doesn't exist.
|
||||
// The desired_access bitmask denotes the permissions on the file.
|
||||
static std::unique_ptr<FileHandle> OpenExisting(std::wstring path,
|
||||
uint32_t desired_access);
|
||||
|
||||
virtual ~FileHandle() = default;
|
||||
|
||||
std::wstring path() const { return path_; }
|
||||
|
||||
// Reads the requested number of bytes from the file starting at the given
|
||||
// offset. The total number of bytes read is returned only if the complete
|
||||
// read succeeds.
|
||||
virtual bool Read(size_t file_offset, void* buffer, size_t buffer_length,
|
||||
size_t* out_bytes_read) = 0;
|
||||
|
||||
// Writes the given buffer to the file starting at the given offset.
|
||||
// The total number of bytes written is returned only if the complete
|
||||
// write succeeds.
|
||||
virtual bool Write(size_t file_offset, const void* buffer,
|
||||
size_t buffer_length, size_t* out_bytes_written) = 0;
|
||||
|
||||
// Flushes any pending write buffers to the underlying filesystem.
|
||||
virtual void Flush() = 0;
|
||||
|
||||
protected:
|
||||
FileHandle(std::wstring path) : path_(std::move(path)) {}
|
||||
|
||||
std::wstring path_;
|
||||
};
|
||||
|
||||
struct FileInfo {
|
||||
enum class Type {
|
||||
kFile,
|
||||
|
||||
Reference in New Issue
Block a user