1
0
mirror of synced 2024-11-30 18:34:29 +01:00
ImHex/lib/libimhex/include/hex/api/content_registry.hpp

391 lines
14 KiB
C++
Raw Normal View History

#pragma once
#include <hex.hpp>
2021-08-29 22:15:18 +02:00
#include <hex/helpers/concepts.hpp>
2022-01-13 14:33:30 +01:00
#include <hex/helpers/paths.hpp>
#include <hex/pattern_language/token.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <functional>
#include <map>
#include <string>
#include <string_view>
#include <vector>
#include <nlohmann/json_fwd.hpp>
namespace hex {
2021-01-12 16:50:15 +01:00
class View;
class LanguageDefinition;
namespace pl {
class Evaluator;
}
namespace dp {
class Node;
}
namespace prv {
class Provider;
}
2021-01-12 16:50:15 +01:00
/*
The Content Registry is the heart of all features in ImHex that are in some way extendable by Plugins.
It allows you to add/register new content that will be picked up and used by the ImHex core or by other
plugins when needed.
*/
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace ContentRegistry {
2021-01-12 16:50:15 +01:00
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace Settings {
using Callback = std::function<bool(const std::string &, nlohmann::json &)>;
struct Entry {
std::string name;
bool requiresRestart;
Callback callback;
};
struct Category {
std::string name;
size_t slot = 0;
bool operator<(const Category &other) const {
return name < other.name;
}
operator const std::string &() const {
return name;
}
};
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
void load();
void store();
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue, const Callback &callback, bool requiresRestart = false);
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback, bool requiresRestart = false);
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &defaultValue, const Callback &callback, bool requiresRestart = false);
void addCategoryDescription(const std::string &unlocalizedCategory, const std::string &unlocalizedCategoryDescription);
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 value);
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &value);
void write(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &value);
i64 read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue);
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
std::string read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue);
std::vector<std::string> read(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::vector<std::string> &defaultValue = {});
std::map<Category, std::vector<Entry>> &getEntries();
std::map<std::string, std::string> &getCategoryDescriptions();
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
nlohmann::json getSetting(const std::string &unlocalizedCategory, const std::string &unlocalizedName);
nlohmann::json &getSettingsData();
2021-12-07 22:47:41 +01:00
}
2021-01-11 21:11:03 +01:00
2021-01-12 16:50:15 +01:00
/* Command Palette Command Registry. Allows adding of new commands to the command palette */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace CommandPaletteCommands {
enum class Type : u32
{
SymbolCommand,
KeywordCommand
};
using DisplayCallback = std::function<std::string(std::string)>;
using ExecuteCallback = std::function<void(std::string)>;
struct Entry {
Type type;
std::string command;
std::string unlocalizedDescription;
DisplayCallback displayCallback;
ExecuteCallback executeCallback;
};
void add(
2022-02-01 22:09:44 +01:00
Type type,
const std::string &command,
const std::string &unlocalizedDescription,
const DisplayCallback &displayCallback,
const ExecuteCallback &executeCallback = [](auto) {});
std::vector<Entry> &getEntries();
2021-12-07 22:47:41 +01:00
}
2021-01-12 16:50:15 +01:00
/* Pattern Language Function Registry. Allows adding of new functions that may be used inside the pattern language */
namespace PatternLanguage {
namespace impl {
struct ColorPalette {
std::string name;
std::vector<u32> colors;
};
}
2022-02-01 22:09:44 +01:00
constexpr static u32 UnlimitedParameters = 0xFFFF'FFFF;
constexpr static u32 MoreParametersThan = 0x8000'0000;
constexpr static u32 LessParametersThan = 0x4000'0000;
constexpr static u32 ExactlyOrMoreParametersThan = 0x2000'0000;
constexpr static u32 NoParameters = 0x0000'0000;
using Namespace = std::vector<std::string>;
2022-02-01 22:09:44 +01:00
using Callback = std::function<std::optional<hex::pl::Token::Literal>(hex::pl::Evaluator *, const std::vector<hex::pl::Token::Literal> &)>;
struct Function {
u32 parameterCount;
Callback func;
bool dangerous;
};
void addFunction(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func);
void addDangerousFunction(const Namespace &ns, const std::string &name, u32 parameterCount, const Callback &func);
std::map<std::string, ContentRegistry::PatternLanguage::Function> &getFunctions();
2022-02-01 22:09:44 +01:00
std::vector<impl::ColorPalette> &getPalettes();
void addColorPalette(const std::string &unlocalizedName, const std::vector<u32> &colors);
void setSelectedPalette(u32 index);
u32 getNextColor();
void resetPalette();
2021-12-07 22:47:41 +01:00
}
2021-01-12 16:50:15 +01:00
/* View Registry. Allows adding of new windows */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace Views {
namespace impl {
void add(View *view);
}
template<hex::derived_from<View> T, typename... Args>
void add(Args &&...args) {
return impl::add(new T(std::forward<Args>(args)...));
2021-01-12 16:50:15 +01:00
}
std::map<std::string, View *> &getEntries();
View *getViewByName(const std::string &unlocalizedName);
2021-01-12 16:50:15 +01:00
2021-12-07 22:47:41 +01:00
}
2021-01-12 16:50:15 +01:00
/* Tools Registry. Allows adding new entries to the tools window */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace Tools {
namespace impl {
2021-01-12 16:50:15 +01:00
using Callback = std::function<void()>;
struct Entry {
std::string name;
Callback function;
};
}
void add(const std::string &unlocalizedName, const impl::Callback &function);
std::vector<impl::Entry> &getEntries();
2021-12-07 22:47:41 +01:00
}
/* Data Inspector Registry. Allows adding of new types to the data inspector */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace DataInspector {
enum class NumberDisplayStyle
{
Decimal,
Hexadecimal,
Octal
};
namespace impl {
2022-02-01 22:09:44 +01:00
using DisplayFunction = std::function<std::string()>;
using EditingFunction = std::function<std::vector<u8>(std::string, std::endian)>;
using GeneratorFunction = std::function<DisplayFunction(const std::vector<u8> &, std::endian, NumberDisplayStyle)>;
struct Entry {
std::string unlocalizedName;
size_t requiredSize;
impl::GeneratorFunction generatorFunction;
std::optional<impl::EditingFunction> editingFunction;
};
}
void add(const std::string &unlocalizedName, size_t requiredSize, impl::GeneratorFunction displayGeneratorFunction, std::optional<impl::EditingFunction> editingFunction = std::nullopt);
std::vector<impl::Entry> &getEntries();
2021-12-07 22:47:41 +01:00
}
2021-02-19 17:36:10 +01:00
/* Data Processor Node Registry. Allows adding new processor nodes to be used in the data processor */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace DataProcessorNode {
namespace impl {
using CreatorFunction = std::function<dp::Node *()>;
struct Entry {
std::string category;
std::string name;
CreatorFunction creatorFunction;
};
void add(const Entry &entry);
}
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
template<hex::derived_from<dp::Node> T, typename... Args>
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, Args &&...args) {
add(impl::Entry { unlocalizedCategory.c_str(), unlocalizedName.c_str(), [=] {
auto node = new T(std::forward<Args>(args)...);
node->setUnlocalizedName(unlocalizedName);
return node;
} });
}
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
void addSeparator();
std::vector<impl::Entry> &getEntries();
2021-12-07 22:47:41 +01:00
}
2021-02-19 17:36:10 +01:00
/* Language Registry. Allows together with the LangEntry class and the _lang user defined literal to add new languages */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace Language {
void registerLanguage(const std::string &name, const std::string &languageCode);
void addLocalizations(const std::string &languageCode, const LanguageDefinition &definition);
std::map<std::string, std::string> &getLanguages();
std::map<std::string, std::vector<LanguageDefinition>> &getLanguageDefinitions();
2021-12-07 22:47:41 +01:00
}
2021-02-19 17:36:10 +01:00
/* Interface Registry. Allows adding new items to various interfaces */
build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 11:37:29 +02:00
namespace Interface {
namespace impl {
2022-02-01 22:09:44 +01:00
using DrawCallback = std::function<void()>;
using LayoutFunction = std::function<void(u32)>;
using ClickCallback = std::function<void()>;
struct Layout {
std::string unlocalizedName;
LayoutFunction callback;
};
struct MainMenuItem {
std::string unlocalizedName;
};
struct MenuItem {
std::string unlocalizedName;
DrawCallback callback;
};
2022-01-22 22:03:19 +01:00
struct SidebarItem {
std::string icon;
DrawCallback callback;
};
struct TitleBarButton {
std::string icon;
std::string unlocalizedTooltip;
ClickCallback callback;
};
}
void registerMainMenuItem(const std::string &unlocalizedName, u32 priority);
void addMenuItem(const std::string &unlocalizedMainMenuName, u32 priority, const impl::DrawCallback &function);
void addWelcomeScreenEntry(const impl::DrawCallback &function);
void addFooterItem(const impl::DrawCallback &function);
void addToolbarItem(const impl::DrawCallback &function);
2022-01-22 22:03:19 +01:00
void addSidebarItem(const std::string &icon, const impl::DrawCallback &function);
void addTitleBarButton(const std::string &icon, const std::string &unlocalizedTooltip, const impl::ClickCallback &function);
void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function);
std::multimap<u32, impl::MainMenuItem> &getMainMenuItems();
std::multimap<u32, impl::MenuItem> &getMenuItems();
std::vector<impl::DrawCallback> &getWelcomeScreenEntries();
std::vector<impl::DrawCallback> &getFooterItems();
std::vector<impl::DrawCallback> &getToolbarItems();
std::vector<impl::SidebarItem> &getSidebarItems();
std::vector<impl::TitleBarButton> &getTitleBarButtons();
std::vector<impl::Layout> &getLayouts();
2021-12-07 22:47:41 +01:00
}
/* Provider Registry. Allows adding new data providers to be created from the UI */
namespace Provider {
namespace impl {
void addProviderName(const std::string &unlocalizedName);
}
template<hex::derived_from<hex::prv::Provider> T>
void add(const std::string &unlocalizedName, bool addToList = true) {
(void)EventManager::subscribe<RequestCreateProvider>([expectedName = unlocalizedName](const std::string &name, hex::prv::Provider **provider) {
if (name != expectedName) return;
auto newProvider = new T();
hex::ImHexApi::Provider::add(newProvider);
if (provider != nullptr)
*provider = newProvider;
});
if (addToList)
impl::addProviderName(unlocalizedName);
}
2021-12-07 22:47:41 +01:00
std::vector<std::string> &getEntries();
2021-12-07 22:47:41 +01:00
}
namespace DataFormatter {
namespace impl {
using Callback = std::function<std::string(prv::Provider *provider, u64 address, size_t size)>;
struct Entry {
std::string unlocalizedName;
Callback callback;
};
}
void add(const std::string &unlocalizedName, const impl::Callback &callback);
std::vector<impl::Entry> &getEntries();
}
namespace FileHandler {
namespace impl {
using Callback = std::function<bool(fs::path)>;
struct Entry {
std::vector<std::string> extensions;
Callback callback;
};
}
void add(const std::vector<std::string> &extensions, const impl::Callback &callback);
std::vector<impl::Entry> &getEntries();
}
};
}