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