1
0
mirror of synced 2024-11-29 01:44:31 +01:00
ImHex/plugins/builtin/include/content/providers/file_provider.hpp
2023-12-08 16:22:36 +01:00

71 lines
2.2 KiB
C++

#pragma once
#include <hex/providers/provider.hpp>
#include <wolv/io/file.hpp>
#include <mutex>
#include <string_view>
namespace hex::plugin::builtin {
class FileProvider : public hex::prv::Provider {
public:
FileProvider() = default;
~FileProvider() override = default;
[[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 resizeRaw(u64 newSize) override;
void insertRaw(u64 offset, u64 size) override;
void removeRaw(u64 offset, u64 size) override;
void readRaw(u64 offset, void *buffer, size_t size) override;
void writeRaw(u64 offset, const void *buffer, size_t size) override;
[[nodiscard]] u64 getActualSize() const override;
void save() override;
void saveAs(const std::fs::path &path) override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::vector<Description> getDataDescription() const override;
std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override;
[[nodiscard]] bool hasFilePicker() const override { return true; }
[[nodiscard]] bool handleFilePicker() override;
std::vector<MenuEntry> getMenuEntries() override;
void setPath(const std::fs::path &path);
[[nodiscard]] bool open() override;
void close() override;
void loadSettings(const nlohmann::json &settings) override;
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override;
[[nodiscard]] std::string getTypeName() const override {
return "hex.builtin.provider.file";
}
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64 address) const override;
private:
void convertToMemoryFile();
protected:
std::fs::path m_path;
wolv::io::File m_file;
size_t m_fileSize = 0;
std::optional<struct stat> m_fileStats;
bool m_readable = false, m_writable = false;
};
}