2020-11-11 09:18:35 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "providers/provider.hpp"
|
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
|
2020-11-16 00:23:27 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2021-01-03 15:00:16 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <sys/mman.h>
|
2021-01-03 15:09:12 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/fcntl.h>
|
2021-01-03 15:00:16 +01:00
|
|
|
#endif
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
namespace hex::prv {
|
|
|
|
|
|
|
|
class FileProvider : public Provider {
|
|
|
|
public:
|
2020-11-11 10:47:02 +01:00
|
|
|
explicit FileProvider(std::string_view path);
|
|
|
|
~FileProvider() override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-11 10:47:02 +01:00
|
|
|
bool isAvailable() override;
|
|
|
|
bool isReadable() override;
|
|
|
|
bool isWritable() override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-11 10:47:02 +01:00
|
|
|
void read(u64 offset, void *buffer, size_t size) override;
|
2020-11-27 13:44:52 +01:00
|
|
|
void write(u64 offset, const void *buffer, size_t size) override;
|
2020-11-27 09:09:48 +01:00
|
|
|
|
|
|
|
void readRaw(u64 offset, void *buffer, size_t size) override;
|
2020-11-27 13:44:52 +01:00
|
|
|
void writeRaw(u64 offset, const void *buffer, size_t size) override;
|
2020-11-22 19:43:35 +01:00
|
|
|
size_t getActualSize() override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-15 16:06:10 +01:00
|
|
|
std::vector<std::pair<std::string, std::string>> getDataInformation() override;
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
private:
|
2021-01-03 15:00:16 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
|
|
|
HANDLE m_file;
|
|
|
|
HANDLE m_mapping;
|
|
|
|
#else
|
|
|
|
int m_file;
|
|
|
|
#endif
|
2020-11-15 16:06:10 +01:00
|
|
|
std::string m_path;
|
2021-01-03 15:00:16 +01:00
|
|
|
void *m_mappedFile;
|
|
|
|
size_t m_fileSize;
|
2020-11-15 16:06:10 +01:00
|
|
|
|
|
|
|
bool m_fileStatsValid = false;
|
|
|
|
struct stat m_fileStats = { 0 };
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
bool m_readable, m_writable;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|