2020-11-11 09:18:35 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin::prv {
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
class FileProvider : public hex::prv::Provider {
|
2020-11-11 09:18:35 +01:00
|
|
|
public:
|
2021-12-07 22:47:41 +01:00
|
|
|
explicit FileProvider();
|
2020-11-11 10:47:02 +01:00
|
|
|
~FileProvider() override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
bool isAvailable() const override;
|
|
|
|
bool isReadable() const override;
|
|
|
|
bool isWritable() const override;
|
|
|
|
bool isResizable() const override;
|
|
|
|
bool isSavable() const override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-03-21 14:50:47 +01:00
|
|
|
void read(u64 offset, void *buffer, size_t size, bool overlays) override;
|
2020-11-27 13:44:52 +01:00
|
|
|
void write(u64 offset, const void *buffer, size_t size) override;
|
2021-07-27 21:07:36 +02:00
|
|
|
void resize(ssize_t newSize) 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;
|
2021-09-21 02:29:54 +02:00
|
|
|
size_t getActualSize() const override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
void save() override;
|
|
|
|
void saveAs(const std::string &path) override;
|
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
[[nodiscard]] std::string getName() const override;
|
|
|
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override;
|
2020-11-15 16:06:10 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
void open(const std::string &path);
|
|
|
|
void close();
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
private:
|
2021-01-03 15:00:16 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
2021-09-08 15:18:24 +02:00
|
|
|
HANDLE m_file = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE m_mapping = INVALID_HANDLE_VALUE;
|
2021-01-03 15:00:16 +01:00
|
|
|
#else
|
2021-09-08 15:18:24 +02:00
|
|
|
int m_file = -1;
|
2021-01-03 15:00:16 +01:00
|
|
|
#endif
|
2021-07-27 21:07:36 +02:00
|
|
|
|
2020-11-15 16:06:10 +01:00
|
|
|
std::string m_path;
|
2021-09-08 15:18:24 +02:00
|
|
|
void *m_mappedFile = nullptr;
|
|
|
|
size_t m_fileSize = 0;
|
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
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
bool m_readable = false, m_writable = false;
|
2020-11-11 09:18:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|