1
0
mirror of synced 2024-11-27 17:10:51 +01:00
ImHex/plugins/builtin/include/content/providers/file_provider.hpp

68 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
#include <hex/providers/provider.hpp>
#include <string_view>
2020-11-16 00:23:27 +01:00
#include <sys/stat.h>
#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>
#endif
2021-12-07 22:47:41 +01:00
namespace hex::plugin::builtin::prv {
2021-12-07 22:47:41 +01:00
class FileProvider : public hex::prv::Provider {
public:
2021-12-07 22:47:41 +01:00
explicit FileProvider();
~FileProvider() override;
[[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;
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;
void resize(ssize_t newSize) override;
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;
[[nodiscard]] size_t getActualSize() const override;
void save() override;
void saveAs(const fs::path &path) override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override;
void setPath(const fs::path &path);
2021-12-07 22:47:41 +01:00
[[nodiscard]] bool open() override;
void close() override;
protected:
#if defined(OS_WINDOWS)
HANDLE m_file = INVALID_HANDLE_VALUE;
HANDLE m_mapping = INVALID_HANDLE_VALUE;
#else
int m_file = -1;
#endif
fs::path m_path;
void *m_mappedFile = nullptr;
size_t m_fileSize = 0;
bool m_fileStatsValid = false;
2021-12-15 22:52:35 +01:00
bool m_emptyFile = false;
struct stat m_fileStats = { 0 };
bool m_readable = false, m_writable = false;
};
}