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)
|
2022-01-24 20:53:17 +01:00
|
|
|
#include <windows.h>
|
2021-01-03 15:00:16 +01:00
|
|
|
#else
|
2022-01-24 20:53:17 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#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-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool isAvailable() const override;
|
|
|
|
[[nodiscard]] bool isReadable() const override;
|
|
|
|
[[nodiscard]] bool isWritable() const override;
|
|
|
|
[[nodiscard]] bool isResizable() const override;
|
|
|
|
[[nodiscard]] 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;
|
2022-01-20 23:24:26 +01:00
|
|
|
|
|
|
|
void resize(size_t newSize) override;
|
|
|
|
void insert(u64 offset, 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;
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] size_t getActualSize() const override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
void save() override;
|
2022-03-04 11:36:37 +01:00
|
|
|
void saveAs(const std::fs::path &path) override;
|
2021-08-21 13:55:21 +02:00
|
|
|
|
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
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
void setPath(const std::fs::path &path);
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool open() override;
|
|
|
|
void close() override;
|
|
|
|
|
|
|
|
protected:
|
2022-01-24 20:53:17 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
2022-02-01 22:09:44 +01:00
|
|
|
HANDLE m_file = INVALID_HANDLE_VALUE;
|
2021-09-08 15:18:24 +02:00
|
|
|
HANDLE m_mapping = INVALID_HANDLE_VALUE;
|
2022-01-24 20:53:17 +01:00
|
|
|
#else
|
2021-09-08 15:18:24 +02:00
|
|
|
int m_file = -1;
|
2022-01-24 20:53:17 +01:00
|
|
|
#endif
|
2021-07-27 21:07:36 +02:00
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
std::fs::path m_path;
|
2021-09-08 15:18:24 +02:00
|
|
|
void *m_mappedFile = nullptr;
|
2022-02-01 22:09:44 +01:00
|
|
|
size_t m_fileSize = 0;
|
2020-11-15 16:06:10 +01:00
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
struct stat m_fileStats = { };
|
2022-02-01 22:09:44 +01:00
|
|
|
bool m_fileStatsValid = false;
|
|
|
|
bool m_emptyFile = false;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|