2021-12-12 00:42:12 +01:00
|
|
|
#pragma once
|
2023-10-04 12:00:32 +02:00
|
|
|
#if !defined(OS_WEB)
|
2021-12-12 00:42:12 +01:00
|
|
|
|
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-11-07 00:04:47 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2021-12-12 00:42:12 +01:00
|
|
|
|
|
|
|
class DiskProvider : public hex::prv::Provider {
|
|
|
|
public:
|
2023-11-10 20:47:08 +01:00
|
|
|
DiskProvider() = default;
|
2022-08-12 15:11:27 +02:00
|
|
|
~DiskProvider() override = default;
|
2021-12-12 00:42:12 +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;
|
|
|
|
|
|
|
|
void readRaw(u64 offset, void *buffer, size_t size) override;
|
|
|
|
void writeRaw(u64 offset, const void *buffer, size_t size) override;
|
2023-12-07 12:06:26 +01:00
|
|
|
[[nodiscard]] u64 getActualSize() const override;
|
2021-12-12 00:42:12 +01:00
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
void setPath(const std::fs::path &path);
|
2021-12-12 00:42:12 +01:00
|
|
|
|
|
|
|
[[nodiscard]] bool open() override;
|
|
|
|
void close() override;
|
|
|
|
|
2022-01-16 01:51:31 +01:00
|
|
|
[[nodiscard]] std::string getName() const override;
|
2023-06-04 10:42:11 +02:00
|
|
|
[[nodiscard]] std::vector<Description> getDataDescription() const override;
|
2021-12-12 00:42:12 +01:00
|
|
|
|
|
|
|
[[nodiscard]] bool hasLoadInterface() const override { return true; }
|
2023-03-16 16:48:15 +01:00
|
|
|
bool drawLoadInterface() override;
|
2021-12-12 11:56:26 +01:00
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
void loadSettings(const nlohmann::json &settings) override;
|
2023-11-30 14:40:07 +01:00
|
|
|
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override;
|
2022-08-08 21:23:52 +02:00
|
|
|
|
|
|
|
[[nodiscard]] std::string getTypeName() const override {
|
|
|
|
return "hex.builtin.provider.disk";
|
|
|
|
}
|
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64 address) 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;
|
2022-08-14 14:45:18 +02:00
|
|
|
|
2021-12-12 00:42:12 +01:00
|
|
|
protected:
|
2021-12-12 11:56:26 +01:00
|
|
|
void reloadDrives();
|
|
|
|
|
2023-10-16 23:45:46 +02:00
|
|
|
struct DriveInfo {
|
|
|
|
std::string path;
|
|
|
|
std::string friendlyName;
|
|
|
|
|
|
|
|
auto operator<=>(const DriveInfo &other) const {
|
|
|
|
return this->path <=> other.path;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::set<DriveInfo> m_availableDrives;
|
2022-03-04 11:36:37 +01:00
|
|
|
std::fs::path m_path;
|
2023-10-17 10:22:56 +02:00
|
|
|
std::string m_friendlyName;
|
2021-12-12 00:42:12 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
2023-11-30 10:22:15 +01:00
|
|
|
void *m_diskHandle = reinterpret_cast<void*>(-1);
|
2022-01-24 20:53:17 +01:00
|
|
|
#else
|
|
|
|
std::string m_pathBuffer;
|
|
|
|
int m_diskHandle = -1;
|
|
|
|
#endif
|
2021-12-12 00:42:12 +01:00
|
|
|
|
2022-03-04 20:52:39 +01:00
|
|
|
size_t m_diskSize = 0;
|
|
|
|
size_t m_sectorSize = 0;
|
2021-12-12 00:42:12 +01:00
|
|
|
|
2022-03-04 20:52:39 +01:00
|
|
|
u64 m_sectorBufferAddress = 0;
|
2021-12-12 00:42:12 +01:00
|
|
|
std::vector<u8> m_sectorBuffer;
|
|
|
|
|
|
|
|
bool m_readable = false;
|
|
|
|
bool m_writable = false;
|
|
|
|
};
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
}
|
|
|
|
#endif
|