1
0
mirror of synced 2025-01-31 03:53:44 +01:00

feat: Allow themes and nodes to be downloaded from the content store

This commit is contained in:
WerWolv 2023-02-16 18:55:21 +01:00
parent d3d6a8a838
commit 5ccbfc1ff8
7 changed files with 606 additions and 97 deletions

View File

@ -102,7 +102,8 @@ namespace hex::api {
if (theme.contains("base")) {
if (theme["base"].is_string()) {
changeTheme(theme["base"].get<std::string>());
if (theme["base"] != name)
changeTheme(theme["base"].get<std::string>());
} else {
hex::log::error("Theme '{}' has invalid base theme!", name);
}

View File

@ -17,7 +17,7 @@ namespace hex::plugin::builtin {
NotAttempted,
InProgress,
Failed,
Succeded,
Succeeded,
};
struct StoreEntry {
@ -45,7 +45,7 @@ namespace hex::plugin::builtin {
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override { return { 600, 400 }; }
[[nodiscard]] ImVec2 getMaxSize() const override { return { 800, 600 }; }
[[nodiscard]] ImVec2 getMaxSize() const override { return { 900, 700 }; }
private:
Net m_net;
@ -54,7 +54,7 @@ namespace hex::plugin::builtin {
std::fs::path m_downloadPath;
RequestStatus m_requestStatus = RequestStatus::NotAttempted;
std::vector<StoreEntry> m_patterns, m_includes, m_magics, m_constants, m_yara, m_encodings;
std::vector<StoreEntry> m_patterns, m_includes, m_magics, m_constants, m_yara, m_encodings, m_nodes, m_themes;
void drawStore();

View File

@ -795,7 +795,9 @@
"hex.builtin.view.store.tab.encodings": "Encodings",
"hex.builtin.view.store.tab.libraries": "Libraries",
"hex.builtin.view.store.tab.magics": "Magic Files",
"hex.builtin.view.store.tab.nodes": "Nodes",
"hex.builtin.view.store.tab.patterns": "Patterns",
"hex.builtin.view.store.tab.themes": "Themes",
"hex.builtin.view.store.tab.yara": "Yara Rules",
"hex.builtin.view.store.update": "Update",
"hex.builtin.view.theme_manager.name": "Theme Manager",

View File

@ -1,6 +1,5 @@
{
"name": "Classic",
"image_postfix": "_dark",
"base": "Classic",
"colors": {
"imgui": {
"border": "#7F7F7F7F",
@ -59,20 +58,18 @@
"title-background-collapse": "#66668CCC",
"window-background": "#000000D8"
},
"implot": {
"axis-grid": "#E5E5E53F",
"axis-text": "#E5E5E5FF",
"crosshairs": "#7F7F7FBF",
"error-bar": "#E5E5E5FF",
"frame-bg": "#6D6D6D63",
"inlay-text": "#E5E5E5FF",
"legend-bg": "#1C1C23EA",
"legend-border": "#7F7F7F7F",
"legend-text": "#E5E5E5FF",
"plot-bg": "#00000059",
"plot-border": "#7F7F7F7F",
"selection": "#F7F763FF",
"title-text": "#E5E5E5FF"
"imhex": {
"desc-button": "#282850FF",
"desc-button-active": "#505078FF",
"desc-button-hovered": "#3C3C64FF",
"highlight": "#4DC69BFF",
"toolbar-blue": "#06539BFF",
"toolbar-brown": "#DBB377FF",
"toolbar-gray": "#E6E6E6FF",
"toolbar-green": "#388B42FF",
"toolbar-purple": "#672A78FF",
"toolbar-red": "#E74C3CFF",
"toolbar-yellow": "#F1C40FFF"
},
"imnodes": {
"box-selector": "#5252A164",
@ -105,18 +102,28 @@
"title-bar-hovered": "#5252A1FF",
"title-bar-selected": "#5252A1FF"
},
"imhex": {
"desc-button": "#282850FF",
"desc-button-active": "#505078FF",
"desc-button-hovered": "#3C3C64FF",
"highlight": "#4DC69BFF",
"toolbar-blue": "#06539BFF",
"toolbar-brown": "#DBB377FF",
"toolbar-gray": "#E6E6E6FF",
"toolbar-green": "#388B42FF",
"toolbar-purple": "#672A78FF",
"toolbar-red": "#E74C3CFF",
"toolbar-yellow": "#F1C40FFF"
"implot": {
"axis-bg": "#00000000",
"axis-bg-active": "#00000000",
"axis-bg-hovered": "#00000000",
"axis-grid": "#E5E5E53F",
"axis-text": "#E5E5E5FF",
"axis-tick": "#0000003F",
"crosshairs": "#7F7F7FBF",
"error-bar": "#E5E5E5FF",
"fill": "#00000000",
"frame-bg": "#6D6D6D63",
"inlay-text": "#E5E5E5FF",
"legend-bg": "#1C1C23EA",
"legend-border": "#7F7F7F7F",
"legend-text": "#E5E5E5FF",
"line": "#00000000",
"marker-fill": "#00000000",
"marker-outline": "#00000000",
"plot-bg": "#00000059",
"plot-border": "#7F7F7F7F",
"selection": "#F7F763FF",
"title-text": "#E5E5E5FF"
},
"text-editor": {
"background": "#000080FF",
@ -141,5 +148,165 @@
"selection": "#00FFFF80",
"string": "#008080FF"
}
},
"image_postfix": "_dark",
"name": "Classic",
"styles": {
"imgui": {
"alpha": 1.0,
"button-text-align": [
0.5,
0.5
],
"cell-padding": [
4.0,
2.0
],
"child-border-size": 1.0,
"child-rounding": 0.0,
"disabled-alpha": 0.6000000238418579,
"frame-border-size": 0.0,
"frame-padding": [
4.0,
3.0
],
"frame-rounding": 0.0,
"grab-min-size": 12.0,
"grab-rounding": 0.0,
"indent-spacing": 10.0,
"item-inner-spacing": [
4.0,
4.0
],
"item-spacing": [
8.0,
4.0
],
"popup-border-size": 1.0,
"popup-rounding": 0.0,
"scrollbar-rounding": 9.0,
"scrollbar-size": 14.0,
"selectable-text-align": [
0.0,
0.0
],
"tab-rounding": 4.0,
"window-border-size": 1.0,
"window-min-size": [
32.0,
32.0
],
"window-padding": [
8.0,
8.0
],
"window-rounding": 0.0,
"window-title-align": [
0.0,
0.5
]
},
"imnodes": {
"grid-spacing": 24.0,
"link-hover-distance": 10.0,
"link-line-segments-per-length": 0.10000000149011612,
"link-thickness": 3.0,
"mini-map-offset": [
4.0,
4.0
],
"mini-map-padding": [
8.0,
8.0
],
"node-border-thickness": 1.0,
"node-corner-rounding": 4.0,
"node-padding": [
8.0,
8.0
],
"pin-circle-radius": 4.0,
"pin-hover-radius": 10.0,
"pin-line-thickness": 1.0,
"pin-offset": 0.0,
"pin-quad-side-length": 7.0,
"pin-triangle-side-length": 9.5
},
"implot": {
"annotation-padding": [
2.0,
2.0
],
"digital-bit-gap": 4.0,
"digital-bit-height": 8.0,
"error-bar-size": 5.0,
"error-bar-weight": 1.5,
"fill-alpha": 1.0,
"fit-padding": [
0.0,
0.0
],
"label-padding": [
5.0,
5.0
],
"legend-inner-padding": [
5.0,
5.0
],
"legend-padding": [
10.0,
10.0
],
"legend-spacing": [
5.0,
0.0
],
"line-weight": 1.0,
"major-grid-size": [
1.0,
1.0
],
"major-tick-len": [
10.0,
10.0
],
"major-tick-size": [
1.0,
1.0
],
"marker-size": 4.0,
"marker-weight": 1.0,
"minor-alpha": 0.25,
"minor-grid-size": [
1.0,
1.0
],
"minor-tick-len": [
5.0,
5.0
],
"minor-tick-size": [
1.0,
1.0
],
"mouse-pos-padding": [
10.0,
10.0
],
"plot-border-size": 1.0,
"plot-default-size": [
400.0,
300.0
],
"plot-min-size": [
200.0,
150.0
],
"plot-padding": [
10.0,
10.0
]
}
}
}

View File

@ -1,6 +1,5 @@
{
"name": "Dark",
"image_postfix": "_dark",
"base": "Dark",
"colors": {
"imgui": {
"border": "#6D6D7F7F",
@ -59,19 +58,18 @@
"title-background-collapse": "#232323FF",
"window-background": "#0F0F0FEF"
},
"implot": {
"axis-grid": "#FFFFFF3F",
"axis-text": "#FFFFFFFF",
"crosshairs": "#FFFFFF7F",
"frame-bg": "#FFFFFF11",
"inlay-text": "#FFFFFFFF",
"legend-bg": "#141414EF",
"legend-border": "#6D6D7F7F",
"legend-text": "#FFFFFFFF",
"plot-bg": "#0000007F",
"plot-border": "#6D6D7F7F",
"selection": "#FF9900FF",
"title-text": "#FFFFFFFF"
"imhex": {
"desc-button": "#141414FF",
"desc-button-active": "#3C3C3CFF",
"desc-button-hovered": "#282828FF",
"highlight": "#4DC69BFF",
"toolbar-blue": "#06539BFF",
"toolbar-brown": "#DBB377FF",
"toolbar-gray": "#E6E6E6FF",
"toolbar-green": "#388B42FF",
"toolbar-purple": "#672A78FF",
"toolbar-red": "#E74C3CFF",
"toolbar-yellow": "#F1C40FFF"
},
"imnodes": {
"box-selector": "#3D85E01E",
@ -104,18 +102,28 @@
"title-bar-hovered": "#4296FAFF",
"title-bar-selected": "#4296FAFF"
},
"imhex": {
"desc-button": "#141414FF",
"desc-button-active": "#3C3C3CFF",
"desc-button-hovered": "#282828FF",
"highlight": "#4DC69BFF",
"toolbar-blue": "#06539BFF",
"toolbar-brown": "#DBB377FF",
"toolbar-gray": "#E6E6E6FF",
"toolbar-green": "#388B42FF",
"toolbar-purple": "#672A78FF",
"toolbar-red": "#E74C3CFF",
"toolbar-yellow": "#F1C40FFF"
"implot": {
"axis-bg": "#00000000",
"axis-bg-active": "#00000000",
"axis-bg-hovered": "#00000000",
"axis-grid": "#FFFFFF3F",
"axis-text": "#FFFFFFFF",
"axis-tick": "#00000000",
"crosshairs": "#FFFFFF7F",
"error-bar": "#00000000",
"fill": "#00000000",
"frame-bg": "#FFFFFF11",
"inlay-text": "#FFFFFFFF",
"legend-bg": "#141414EF",
"legend-border": "#6D6D7F7F",
"legend-text": "#FFFFFFFF",
"line": "#00000000",
"marker-fill": "#00000000",
"marker-outline": "#00000000",
"plot-bg": "#0000007F",
"plot-border": "#6D6D7F7F",
"selection": "#FF9900FF",
"title-text": "#FFFFFFFF"
},
"text-editor": {
"background": "#101010FF",
@ -140,5 +148,165 @@
"selection": "#2060A080",
"string": "#E07070FF"
}
},
"image_postfix": "_dark",
"name": "Dark",
"styles": {
"imgui": {
"alpha": 1.0,
"button-text-align": [
0.5,
0.5
],
"cell-padding": [
4.0,
2.0
],
"child-border-size": 1.0,
"child-rounding": 0.0,
"disabled-alpha": 0.6000000238418579,
"frame-border-size": 0.0,
"frame-padding": [
4.0,
3.0
],
"frame-rounding": 0.0,
"grab-min-size": 12.0,
"grab-rounding": 0.0,
"indent-spacing": 10.0,
"item-inner-spacing": [
4.0,
4.0
],
"item-spacing": [
8.0,
4.0
],
"popup-border-size": 1.0,
"popup-rounding": 0.0,
"scrollbar-rounding": 9.0,
"scrollbar-size": 14.0,
"selectable-text-align": [
0.0,
0.0
],
"tab-rounding": 4.0,
"window-border-size": 1.0,
"window-min-size": [
32.0,
32.0
],
"window-padding": [
8.0,
8.0
],
"window-rounding": 0.0,
"window-title-align": [
0.0,
0.5
]
},
"imnodes": {
"grid-spacing": 24.0,
"link-hover-distance": 10.0,
"link-line-segments-per-length": 0.10000000149011612,
"link-thickness": 3.0,
"mini-map-offset": [
4.0,
4.0
],
"mini-map-padding": [
8.0,
8.0
],
"node-border-thickness": 1.0,
"node-corner-rounding": 4.0,
"node-padding": [
8.0,
8.0
],
"pin-circle-radius": 4.0,
"pin-hover-radius": 10.0,
"pin-line-thickness": 1.0,
"pin-offset": 0.0,
"pin-quad-side-length": 7.0,
"pin-triangle-side-length": 9.5
},
"implot": {
"annotation-padding": [
2.0,
2.0
],
"digital-bit-gap": 4.0,
"digital-bit-height": 8.0,
"error-bar-size": 5.0,
"error-bar-weight": 1.5,
"fill-alpha": 1.0,
"fit-padding": [
0.0,
0.0
],
"label-padding": [
5.0,
5.0
],
"legend-inner-padding": [
5.0,
5.0
],
"legend-padding": [
10.0,
10.0
],
"legend-spacing": [
5.0,
0.0
],
"line-weight": 1.0,
"major-grid-size": [
1.0,
1.0
],
"major-tick-len": [
10.0,
10.0
],
"major-tick-size": [
1.0,
1.0
],
"marker-size": 4.0,
"marker-weight": 1.0,
"minor-alpha": 0.25,
"minor-grid-size": [
1.0,
1.0
],
"minor-tick-len": [
5.0,
5.0
],
"minor-tick-size": [
1.0,
1.0
],
"mouse-pos-padding": [
10.0,
10.0
],
"plot-border-size": 1.0,
"plot-default-size": [
400.0,
300.0
],
"plot-min-size": [
200.0,
150.0
],
"plot-padding": [
10.0,
10.0
]
}
}
}

View File

@ -1,6 +1,5 @@
{
"name": "Light",
"image_postfix": "_light",
"base": "Light",
"colors": {
"imgui": {
"border": "#0000004C",
@ -59,20 +58,18 @@
"title-background-collapse": "#DBDBDBFF",
"window-background": "#EFEFEFFF"
},
"implot": {
"axis-grid": "#FFFFFFFF",
"axis-text": "#000000FF",
"axis-tick": "#0000003F",
"crosshairs": "#0000007F",
"frame-bg": "#FFFFFFFF",
"inlay-text": "#000000FF",
"legend-bg": "#FFFFFFF9",
"legend-border": "#D1D1D1CC",
"legend-text": "#000000FF",
"plot-bg": "#6B91FF21",
"plot-border": "#00000000",
"selection": "#D1A307FF",
"title-text": "#000000FF"
"imhex": {
"desc-button": "#E6E6E6FF",
"desc-button-active": "#BEBEBEFF",
"desc-button-hovered": "#D2D2D2FF",
"highlight": "#299770FF",
"toolbar-blue": "#06539BFF",
"toolbar-brown": "#DBB377FF",
"toolbar-gray": "#191919FF",
"toolbar-green": "#388B42FF",
"toolbar-purple": "#672A78FF",
"toolbar-red": "#E74C3CFF",
"toolbar-yellow": "#F1C40FFF"
},
"imnodes": {
"box-selector": "#5AAAFA1E",
@ -105,18 +102,28 @@
"title-bar-hovered": "#D1D1D1FF",
"title-bar-selected": "#D1D1D1FF"
},
"imhex": {
"desc-button": "#E6E6E6FF",
"desc-button-active": "#BEBEBEFF",
"desc-button-hovered": "#D2D2D2FF",
"highlight": "#299770FF",
"toolbar-blue": "#06539BFF",
"toolbar-brown": "#DBB377FF",
"toolbar-gray": "#191919FF",
"toolbar-green": "#388B42FF",
"toolbar-purple": "#672A78FF",
"toolbar-red": "#E74C3CFF",
"toolbar-yellow": "#F1C40FFF"
"implot": {
"axis-bg": "#00000000",
"axis-bg-active": "#00000000",
"axis-bg-hovered": "#00000000",
"axis-grid": "#FFFFFFFF",
"axis-text": "#000000FF",
"axis-tick": "#0000003F",
"crosshairs": "#0000007F",
"error-bar": "#00000000",
"fill": "#00000000",
"frame-bg": "#FFFFFFFF",
"inlay-text": "#000000FF",
"legend-bg": "#FFFFFFF9",
"legend-border": "#D1D1D1CC",
"legend-text": "#000000FF",
"line": "#00000000",
"marker-fill": "#00000000",
"marker-outline": "#00000000",
"plot-bg": "#6B91FF21",
"plot-border": "#00000000",
"selection": "#D1A307FF",
"title-text": "#000000FF"
},
"text-editor": {
"background": "#FFFFFFFF",
@ -141,5 +148,165 @@
"selection": "#00006080",
"string": "#A02020FF"
}
},
"image_postfix": "_light",
"name": "Light",
"styles": {
"imgui": {
"alpha": 1.0,
"button-text-align": [
0.5,
0.5
],
"cell-padding": [
4.0,
2.0
],
"child-border-size": 1.0,
"child-rounding": 0.0,
"disabled-alpha": 0.6000000238418579,
"frame-border-size": 0.0,
"frame-padding": [
4.0,
3.0
],
"frame-rounding": 0.0,
"grab-min-size": 12.0,
"grab-rounding": 0.0,
"indent-spacing": 10.0,
"item-inner-spacing": [
4.0,
4.0
],
"item-spacing": [
8.0,
4.0
],
"popup-border-size": 1.0,
"popup-rounding": 0.0,
"scrollbar-rounding": 9.0,
"scrollbar-size": 14.0,
"selectable-text-align": [
0.0,
0.0
],
"tab-rounding": 4.0,
"window-border-size": 1.0,
"window-min-size": [
32.0,
32.0
],
"window-padding": [
8.0,
8.0
],
"window-rounding": 0.0,
"window-title-align": [
0.0,
0.5
]
},
"imnodes": {
"grid-spacing": 24.0,
"link-hover-distance": 10.0,
"link-line-segments-per-length": 0.10000000149011612,
"link-thickness": 3.0,
"mini-map-offset": [
4.0,
4.0
],
"mini-map-padding": [
8.0,
8.0
],
"node-border-thickness": 1.0,
"node-corner-rounding": 4.0,
"node-padding": [
8.0,
8.0
],
"pin-circle-radius": 4.0,
"pin-hover-radius": 10.0,
"pin-line-thickness": 1.0,
"pin-offset": 0.0,
"pin-quad-side-length": 7.0,
"pin-triangle-side-length": 9.5
},
"implot": {
"annotation-padding": [
2.0,
2.0
],
"digital-bit-gap": 4.0,
"digital-bit-height": 8.0,
"error-bar-size": 5.0,
"error-bar-weight": 1.5,
"fill-alpha": 1.0,
"fit-padding": [
0.0,
0.0
],
"label-padding": [
5.0,
5.0
],
"legend-inner-padding": [
5.0,
5.0
],
"legend-padding": [
10.0,
10.0
],
"legend-spacing": [
5.0,
0.0
],
"line-weight": 1.0,
"major-grid-size": [
1.0,
1.0
],
"major-tick-len": [
10.0,
10.0
],
"major-tick-size": [
1.0,
1.0
],
"marker-size": 4.0,
"marker-weight": 1.0,
"minor-alpha": 0.25,
"minor-grid-size": [
1.0,
1.0
],
"minor-tick-len": [
5.0,
5.0
],
"minor-tick-size": [
1.0,
1.0
],
"mouse-pos-padding": [
10.0,
10.0
],
"plot-border-size": 1.0,
"plot-default-size": [
400.0,
300.0
],
"plot-min-size": [
200.0,
150.0
],
"plot-padding": [
10.0,
10.0
]
}
}
}

View File

@ -42,7 +42,7 @@ namespace hex::plugin::builtin {
this->refresh();
}
auto drawTab = [this](auto title, fs::ImHexPath pathType, auto &content, const std::function<void(const StoreEntry &)> &downloadDoneCallback) {
auto drawTab = [this](auto title, fs::ImHexPath pathType, auto &content, const std::function<void()> &downloadDoneCallback = []{}) {
if (ImGui::BeginTabItem(title)) {
if (ImGui::BeginTable("##pattern_language", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupScrollFreeze(0, 1);
@ -80,7 +80,7 @@ namespace hex::plugin::builtin {
tar.extractAll(this->m_downloadPath.parent_path() / this->m_downloadPath.stem());
}
downloadDoneCallback(entry);
downloadDoneCallback();
} else
log::error("Download failed! HTTP Code {}", response.code);
@ -114,12 +114,14 @@ namespace hex::plugin::builtin {
};
if (ImGui::BeginTabBar("storeTabs")) {
drawTab("hex.builtin.view.store.tab.patterns"_lang, fs::ImHexPath::Patterns, this->m_patterns, [](auto) {});
drawTab("hex.builtin.view.store.tab.libraries"_lang, fs::ImHexPath::PatternsInclude, this->m_includes, [](auto) {});
drawTab("hex.builtin.view.store.tab.magics"_lang, fs::ImHexPath::Magic, this->m_magics, [](auto) { magic::compile(); });
drawTab("hex.builtin.view.store.tab.constants"_lang, fs::ImHexPath::Constants, this->m_constants, [](auto) {});
drawTab("hex.builtin.view.store.tab.encodings"_lang, fs::ImHexPath::Encodings, this->m_encodings, [](auto) {});
drawTab("hex.builtin.view.store.tab.yara"_lang, fs::ImHexPath::Yara, this->m_yara, [](auto) {});
drawTab("hex.builtin.view.store.tab.patterns"_lang, fs::ImHexPath::Patterns, this->m_patterns);
drawTab("hex.builtin.view.store.tab.libraries"_lang, fs::ImHexPath::PatternsInclude, this->m_includes);
drawTab("hex.builtin.view.store.tab.magics"_lang, fs::ImHexPath::Magic, this->m_magics, magic::compile);
drawTab("hex.builtin.view.store.tab.constants"_lang, fs::ImHexPath::Constants, this->m_constants);
drawTab("hex.builtin.view.store.tab.encodings"_lang, fs::ImHexPath::Encodings, this->m_encodings);
drawTab("hex.builtin.view.store.tab.yara"_lang, fs::ImHexPath::Yara, this->m_yara);
drawTab("hex.builtin.view.store.tab.nodes"_lang, fs::ImHexPath::Nodes, this->m_nodes);
drawTab("hex.builtin.view.store.tab.themes"_lang, fs::ImHexPath::Themes, this->m_themes);
ImGui::EndTabBar();
}
@ -143,8 +145,8 @@ namespace hex::plugin::builtin {
void ViewStore::parseResponse() {
auto response = this->m_apiRequest.get();
this->m_requestStatus = response.code == 200 ? RequestStatus::Succeded : RequestStatus::Failed;
if (this->m_requestStatus == RequestStatus::Succeded) {
this->m_requestStatus = response.code == 200 ? RequestStatus::Succeeded : RequestStatus::Failed;
if (this->m_requestStatus == RequestStatus::Succeeded) {
auto json = nlohmann::json::parse(response.body);
auto parseStoreEntries = [](auto storeJson, const std::string &name, fs::ImHexPath pathType, std::vector<StoreEntry> &results) {
@ -191,6 +193,8 @@ namespace hex::plugin::builtin {
parseStoreEntries(json, "constants", fs::ImHexPath::Constants, this->m_constants);
parseStoreEntries(json, "yara", fs::ImHexPath::Yara, this->m_yara);
parseStoreEntries(json, "encodings", fs::ImHexPath::Encodings, this->m_encodings);
parseStoreEntries(json, "nodes", fs::ImHexPath::Nodes, this->m_nodes);
parseStoreEntries(json, "themes", fs::ImHexPath::Themes, this->m_themes);
}
this->m_apiRequest = {};
}