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
|
|
|
|
2024-02-24 12:06:06 +01:00
|
|
|
#include <set>
|
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:
|
2024-03-10 14:31:39 +01:00
|
|
|
constexpr static u64 MaxMemoryFileSize = 128 * 1024 * 1024;
|
|
|
|
|
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
|
|
|
|
2023-12-08 16:22:36 +01:00
|
|
|
void resizeRaw(u64 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;
|
2023-05-11 09:27:23 +02:00
|
|
|
|
2023-12-07 12:06:26 +01:00
|
|
|
[[nodiscard]] u64 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
|
|
|
|
2023-08-09 20:04:12 +02:00
|
|
|
private:
|
|
|
|
void convertToMemoryFile();
|
2024-03-10 14:31:39 +01:00
|
|
|
void handleFileChange();
|
2023-08-09 20:04:12 +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
|
|
|
|
2024-03-10 14:31:39 +01:00
|
|
|
wolv::io::ChangeTracker m_changeTracker;
|
|
|
|
std::vector<u8> m_data;
|
|
|
|
bool m_loadedIntoMemory = false;
|
2024-03-15 17:57:06 +01:00
|
|
|
bool m_ignoreNextChangeEvent = false;
|
2024-03-10 14:31:39 +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;
|
2024-02-24 12:06:06 +01:00
|
|
|
|
|
|
|
static std::set<FileProvider*> s_openedFiles;
|
2020-11-11 09:18:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|