impr: Refactor and modularize data information view

This commit is contained in:
WerWolv
2024-02-21 00:06:52 +01:00
parent a2ffac9424
commit 56e7c15064
25 changed files with 852 additions and 628 deletions

View File

@@ -24,6 +24,7 @@ namespace hex {
class View;
class Shortcut;
class Task;
namespace dp {
class Node;
@@ -1259,6 +1260,7 @@ namespace hex {
[[nodiscard]] bool isExperimentEnabled(const std::string &experimentName);
}
/* Reports Registry. Allows adding new sections to exported reports */
namespace Reports {
namespace impl {
@@ -1276,6 +1278,73 @@ namespace hex {
void addReportProvider(impl::Callback callback);
}
namespace DataInformation {
class InformationSection {
public:
InformationSection(const UnlocalizedString &unlocalizedName, const UnlocalizedString &unlocalizedDescription = "", bool hasSettings = false)
: m_unlocalizedName(unlocalizedName), m_unlocalizedDescription(unlocalizedDescription),
m_hasSettings(hasSettings) { }
virtual ~InformationSection() = default;
[[nodiscard]] const UnlocalizedString& getUnlocalizedName() const { return m_unlocalizedName; }
[[nodiscard]] const UnlocalizedString& getUnlocalizedDescription() const { return m_unlocalizedDescription; }
virtual void process(Task &task, prv::Provider *provider, Region region) = 0;
virtual void reset() = 0;
virtual void drawSettings() { }
virtual void drawContent() = 0;
[[nodiscard]] bool isValid() const { return m_valid; }
void markValid(bool valid = true) { m_valid = valid; }
[[nodiscard]] bool isEnabled() const { return m_enabled; }
void setEnabled(bool enabled) { m_enabled = enabled; }
[[nodiscard]] bool isAnalyzing() const { return m_analyzing; }
void setAnalyzing(bool analyzing) { m_analyzing = analyzing; }
virtual void load(const nlohmann::json &data) {
m_enabled = data.value<bool>("enabled", true);
}
[[nodiscard]] virtual nlohmann::json store() {
nlohmann::json data;
data["enabled"] = m_enabled.load();
return data;
}
[[nodiscard]] bool hasSettings() const { return m_hasSettings; }
private:
UnlocalizedString m_unlocalizedName, m_unlocalizedDescription;
bool m_hasSettings;
std::atomic<bool> m_analyzing = false;
std::atomic<bool> m_valid = false;
std::atomic<bool> m_enabled = true;
};
namespace impl {
using CreateCallback = std::function<std::unique_ptr<InformationSection>()>;
const std::vector<CreateCallback>& getInformationSectionConstructors();
void addInformationSectionCreator(const CreateCallback &callback);
}
template<typename T>
void addInformationSection(auto && ...args) {
impl::addInformationSectionCreator([args...] {
return std::make_unique<T>(std::forward<decltype(args)>(args)...);
});
}
}
}
}

View File

@@ -19,7 +19,9 @@ struct GLFWwindow;
namespace hex {
class AutoResetBase;
namespace impl {
class AutoResetBase;
}
namespace prv {
class Provider;
@@ -409,7 +411,7 @@ namespace hex {
bool isWindowResizable();
void addAutoResetObject(AutoResetBase *object);
void addAutoResetObject(hex::impl::AutoResetBase *object);
void cleanup();
}

View File

@@ -31,7 +31,8 @@ namespace hex {
* @brief Updates the current process value of the task
* @param value Current value
*/
void update(u64 value = 0);
void update(u64 value);
void update() const;
/**
* @brief Sets the maximum value of the task

View File

@@ -5,14 +5,18 @@
namespace hex {
class AutoResetBase {
public:
virtual ~AutoResetBase() = default;
virtual void reset() = 0;
};
namespace impl {
class AutoResetBase {
public:
virtual ~AutoResetBase() = default;
virtual void reset() = 0;
};
}
template<typename T>
class AutoReset : AutoResetBase {
class AutoReset : public impl::AutoResetBase {
public:
using Type = T;

View File

@@ -17,13 +17,13 @@ namespace hex::magic {
bool compile();
std::string getDescription(const std::vector<u8> &data, bool firstEntryOnly = false);
std::string getDescription(prv::Provider *provider, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getDescription(prv::Provider *provider, u64 address = 0x00, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getMIMEType(const std::vector<u8> &data, bool firstEntryOnly = false);
std::string getMIMEType(prv::Provider *provider, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getMIMEType(prv::Provider *provider, u64 address = 0x00, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getExtensions(const std::vector<u8> &data, bool firstEntryOnly = false);
std::string getExtensions(prv::Provider *provider, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getExtensions(prv::Provider *provider, u64 address = 0x00, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getAppleCreatorType(const std::vector<u8> &data, bool firstEntryOnly = false);
std::string getAppleCreatorType(prv::Provider *provider, size_t size = 100_KiB, bool firstEntryOnly = false);
std::string getAppleCreatorType(prv::Provider *provider, u64 address = 0x00, size_t size = 100_KiB, bool firstEntryOnly = false);
bool isValidMIMEType(const std::string &mimeType);