1
0
mirror of synced 2024-11-12 02:00:52 +01:00

impr: Improved types used in provider functions

This commit is contained in:
WerWolv 2023-06-04 10:42:11 +02:00
parent 25476d4e1e
commit 07aabe8efa
18 changed files with 50 additions and 21 deletions

View File

@ -21,6 +21,16 @@ namespace hex::prv {
*/
class Provider {
public:
struct Description {
std::string name;
std::string value;
};
struct MenuEntry {
std::string name;
std::function<void()> callback;
};
constexpr static size_t MaxPageSize = 0x1000'0000;
Provider();
@ -96,7 +106,7 @@ namespace hex::prv {
[[nodiscard]] virtual std::optional<u32> getPageOfAddress(u64 address) const;
[[nodiscard]] virtual std::string getName() const = 0;
[[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataDescription() const = 0;
[[nodiscard]] virtual std::vector<Description> getDataDescription() const = 0;
[[nodiscard]] virtual std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument);
/**
@ -121,7 +131,7 @@ namespace hex::prv {
[[nodiscard]] virtual bool hasFilePicker() const;
virtual bool handleFilePicker();
virtual std::vector<std::pair<std::string, std::function<void()>>> getMenuEntries() {
virtual std::vector<MenuEntry> getMenuEntries() {
return { };
};

View File

@ -34,7 +34,7 @@ namespace hex::plugin::builtin {
void close() override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override;
[[nodiscard]] std::vector<Description> getDataDescription() const override;
[[nodiscard]] bool hasLoadInterface() const override { return true; }
bool drawLoadInterface() override;

View File

@ -36,13 +36,13 @@ namespace hex::plugin::builtin {
void saveAs(const std::fs::path &path) override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() 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<std::pair<std::string, std::function<void()>>> getMenuEntries() override;
std::vector<MenuEntry> getMenuEntries() override;
void setPath(const std::fs::path &path);

View File

@ -32,7 +32,7 @@ namespace hex::plugin::builtin {
void save() override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override;
[[nodiscard]] std::vector<Description> getDataDescription() const override;
[[nodiscard]] bool open() override;
void close() override;

View File

@ -27,7 +27,7 @@ namespace hex::plugin::builtin {
void close() override;
[[nodiscard]] std::string getName() const override;
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override { return { }; }
[[nodiscard]] std::vector<Description> getDataDescription() const override;
void loadSettings(const nlohmann::json &settings) override;
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override;

View File

@ -30,7 +30,7 @@ namespace hex::plugin::builtin {
void save() override;
[[nodiscard]] std::string getName() const override { return LangEntry("hex.builtin.provider.mem_file.unsaved"); }
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override { return { }; }
[[nodiscard]] std::vector<Description> getDataDescription() const override { return { }; }
[[nodiscard]] std::string getTypeName() const override {
return "hex.builtin.provider.mem_file";

View File

@ -13,6 +13,7 @@ namespace hex::plugin::builtin {
void close() override;
[[nodiscard]] std::string getName() const override;
std::vector<IntelHexProvider::Description> getDataDescription() const override;
[[nodiscard]] std::string getTypeName() const override {
return "hex.builtin.provider.motorola_srec";

View File

@ -23,7 +23,7 @@ namespace hex::plugin::builtin {
[[nodiscard]] size_t getActualSize() const override { return 0x00; }
[[nodiscard]] std::string getName() const override { return "None"; }
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override { return { }; }
[[nodiscard]] std::vector<Description> getDataDescription() const override { return { }; }
void loadSettings(const nlohmann::json &settings) override { hex::unused(settings); }
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { return settings; }

View File

@ -88,7 +88,7 @@ namespace hex::plugin::builtin {
else
return hex::format("{} View", this->m_provider->getName());
}
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override {
[[nodiscard]] std::vector<Description> getDataDescription() const override {
if (this->m_provider == nullptr)
return { };

View File

@ -270,7 +270,7 @@ namespace hex::plugin::builtin {
return wolv::util::toUTF8String(this->m_path);
}
std::vector<std::pair<std::string, std::string>> DiskProvider::getDataDescription() const {
std::vector<DiskProvider::Description> DiskProvider::getDataDescription() const {
return {
{ "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(this->m_path) },
{ "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(this->m_diskSize) },

View File

@ -144,8 +144,8 @@ namespace hex::plugin::builtin {
return wolv::util::toUTF8String(this->m_path.filename());
}
std::vector<std::pair<std::string, std::string>> FileProvider::getDataDescription() const {
std::vector<std::pair<std::string, std::string>> result;
std::vector<FileProvider::Description> FileProvider::getDataDescription() const {
std::vector<Description> result;
result.emplace_back("hex.builtin.provider.file.path"_lang, wolv::util::toUTF8String(this->m_path));
result.emplace_back("hex.builtin.provider.file.size"_lang, hex::toByteString(this->getActualSize()));
@ -184,7 +184,7 @@ namespace hex::plugin::builtin {
});
}
std::vector<std::pair<std::string, std::function<void()>>> FileProvider::getMenuEntries(){
std::vector<FileProvider::MenuEntry> FileProvider::getMenuEntries(){
return {
{"hex.builtin.provider.file.menu.open_folder"_lang, [path = this->m_path] {
fs::openFolderWithSelectionExternal(path);

View File

@ -238,7 +238,7 @@ namespace hex::plugin::builtin {
return hex::format("hex.builtin.provider.gdb.name"_lang, address, port);
}
std::vector<std::pair<std::string, std::string>> GDBProvider::getDataDescription() const {
std::vector<GDBProvider::Description> GDBProvider::getDataDescription() const {
return {
{"hex.builtin.provider.gdb.server"_lang, hex::format("{}:{}", this->m_ipAddress, this->m_port)},
};

View File

@ -224,6 +224,15 @@ namespace hex::plugin::builtin {
return hex::format("hex.builtin.provider.intel_hex.name"_lang, wolv::util::toUTF8String(this->m_sourceFilePath.filename()));
}
[[nodiscard]] std::vector<IntelHexProvider::Description> IntelHexProvider::getDataDescription() const {
std::vector<Description> result;
result.emplace_back("hex.builtin.provider.file.path"_lang, wolv::util::toUTF8String(this->m_sourceFilePath));
result.emplace_back("hex.builtin.provider.file.size"_lang, hex::toByteString(this->getActualSize()));
return result;
}
bool IntelHexProvider::handleFilePicker() {
auto picked = fs::openFileBrowser(fs::DialogMode::Open, {
{ "Intel Hex File", "hex" },

View File

@ -202,6 +202,16 @@ namespace hex::plugin::builtin {
return hex::format("hex.builtin.provider.motorola_srec.name"_lang, wolv::util::toUTF8String(this->m_sourceFilePath.filename()));
}
[[nodiscard]] std::vector<MotorolaSRECProvider::Description> MotorolaSRECProvider::getDataDescription() const {
std::vector<Description> result;
result.emplace_back("hex.builtin.provider.file.path"_lang, wolv::util::toUTF8String(this->m_sourceFilePath));
result.emplace_back("hex.builtin.provider.file.size"_lang, hex::toByteString(this->getActualSize()));
return result;
}
bool MotorolaSRECProvider::handleFilePicker() {
auto picked = fs::openFileBrowser(fs::DialogMode::Open, {
{ "Motorola SREC File", "s19" },

View File

@ -286,9 +286,9 @@ namespace hex::plugin::builtin {
}
if (ImGui::BeginPopup(popupID.c_str())) {
for (auto p : tabProvider->getMenuEntries()) {
if (ImGui::MenuItem(p.first.c_str())) {
p.second();
for (const auto &menuEntry : tabProvider->getMenuEntries()) {
if (ImGui::MenuItem(menuEntry.name.c_str())) {
menuEntry.callback();
}
}
ImGui::EndPopup();

View File

@ -50,7 +50,6 @@ namespace hex::plugin::builtin {
// Attach the newly created window to the cursor, so it gets dragged around
GImGui->MovingWindow = ImGui::GetCurrentWindow();
GImGui->ActiveId = GImGui->MovingWindow->MoveId;
ImGui::DockContextQueueUndockWindow(GImGui, GImGui->MovingWindow);
}
}
ImGui::End();

View File

@ -38,7 +38,7 @@ namespace hex::plugin::windows {
void save() override {}
[[nodiscard]] std::string getName() const override { return hex::format("hex.windows.provider.process_memory.name"_lang, this->m_selectedProcess != nullptr ? this->m_selectedProcess->name : ""); }
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override {
[[nodiscard]] std::vector<Description> getDataDescription() const override {
return {
{ "hex.windows.provider.process_memory.process_name"_lang, this->m_selectedProcess->name },
{ "hex.windows.provider.process_memory.process_id"_lang, std::to_string(this->m_selectedProcess->id) }

View File

@ -27,7 +27,7 @@ namespace hex::test {
return "";
}
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override {
[[nodiscard]] std::vector<Description> getDataDescription() const override {
return {};
}