2020-11-11 09:18:35 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2023-03-12 18:27:29 +01:00
|
|
|
|
|
|
|
#include <wolv/io/file.hpp>
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2023-03-17 11:43:50 +01:00
|
|
|
#include <mutex>
|
2020-11-11 09:18:35 +01:00
|
|
|
#include <string_view>
|
|
|
|
|
2022-11-07 00:04:47 +01:00
|
|
|
namespace hex::plugin::builtin {
|
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:
|
2023-01-01 02:29:38 +01:00
|
|
|
FileProvider() = default;
|
|
|
|
~FileProvider() override = default;
|
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;
|
2022-06-17 14:21:56 +02:00
|
|
|
void remove(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;
|
2023-05-11 09:27:23 +02:00
|
|
|
|
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;
|
2023-03-21 15:42:10 +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;
|
2023-06-04 10:42:11 +02:00
|
|
|
[[nodiscard]] std::vector<Description> getDataDescription() const override;
|
2023-01-24 09:07:11 +01:00
|
|
|
std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override;
|
2020-11-15 16:06:10 +01:00
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
[[nodiscard]] bool hasFilePicker() const override { return true; }
|
|
|
|
[[nodiscard]] bool handleFilePicker() override;
|
2022-08-12 15:11:27 +02:00
|
|
|
|
2023-06-04 10:42:11 +02:00
|
|
|
std::vector<MenuEntry> getMenuEntries() override;
|
2023-05-21 13:21:53 +02: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;
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2022-12-19 08:52:12 +01:00
|
|
|
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64 address) const override;
|
2022-08-14 09:38:38 +02:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
protected:
|
2022-03-04 11:36:37 +01:00
|
|
|
std::fs::path m_path;
|
2023-05-11 09:27:23 +02:00
|
|
|
wolv::io::File m_file;
|
|
|
|
size_t m_fileSize = 0;
|
2023-03-17 11:43:50 +01:00
|
|
|
|
2023-02-17 10:26:09 +01:00
|
|
|
std::optional<struct stat> m_fileStats;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|