From 4cc637c0b2a4cd174a14cde7e87e4e158a1cbfbf Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 8 Sep 2021 17:22:54 +0200 Subject: [PATCH] sys: Finish up the online store --- plugins/builtin/source/lang/de_DE.cpp | 13 ++++++++ plugins/builtin/source/lang/en_US.cpp | 14 ++++++++ plugins/builtin/source/lang/it_IT.cpp | 14 ++++++++ source/views/view_store.cpp | 47 ++++++++++++++------------- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index cf60b7d79..a164e55fd 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -297,6 +297,19 @@ namespace hex::plugin::builtin { { "hex.view.constants.name", "Konstanten" }, + { "hex.view.store.name", "Content Store" }, + { "hex.view.store.desc", "Downloade extra Content von ImHex' online Datenbank" }, + { "hex.view.store.reload", "Neu laden" }, + { "hex.view.store.name", "Name" }, + { "hex.view.store.description", "Beschreibung" }, + { "hex.view.store.download", "Download" }, + { "hex.view.store.update", "Update" }, + { "hex.view.store.remove", "Entfernen" }, + { "hex.view.store.tab.patterns", "Patterns" }, + { "hex.view.store.tab.libraries", "Libraries" }, + { "hex.view.store.tab.magics", "Magic Files" }, + { "hex.view.store.loading", "Store inhalt wird geladen..." }, + /* Builtin plugin features */ { "hex.builtin.command.calc.desc", "Rechner" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 3c4ea4718..5fe7c5759 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -297,6 +297,20 @@ namespace hex::plugin::builtin { { "hex.view.constants.name", "Constants" }, + { "hex.view.store.name", "Content Store" }, + { "hex.view.store.desc", "Download new content from ImHex' online database" }, + { "hex.view.store.reload", "Reload" }, + { "hex.view.store.name", "Name" }, + { "hex.view.store.description", "Description" }, + { "hex.view.store.download", "Download" }, + { "hex.view.store.update", "Update" }, + { "hex.view.store.remove", "Remove" }, + { "hex.view.store.tab.patterns", "Patterns" }, + { "hex.view.store.tab.libraries", "Libraries" }, + { "hex.view.store.tab.magics", "Magic Files" }, + { "hex.view.store.loading", "Loading store content..." }, + + /* Builtin plugin features */ { "hex.builtin.command.calc.desc", "Calculator" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index d8849e0a3..67ae77a98 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -296,6 +296,20 @@ namespace hex::plugin::builtin { // { "hex.view.constants.name", "Constants" }, + //{ "hex.view.store.name", "Content Store" }, + // { "hex.view.store.desc", "Download new content from ImHex' online database" }, + // { "hex.view.store.reload", "Reload" }, + // { "hex.view.store.name", "Name" }, + // { "hex.view.store.description", "Description" }, + // { "hex.view.store.download", "Download" }, + // { "hex.view.store.update", "Update" }, + // { "hex.view.store.remove", "Remove" }, + // { "hex.view.store.tab.patterns", "Patterns" }, + // { "hex.view.store.tab.libraries", "Libraries" }, + // { "hex.view.store.tab.magics", "Magic Files" }, + // { "hex.view.store.loading", "Loading store content..." }, + + /* Builtin plugin features */ { "hex.builtin.command.calc.desc", "Calcolatrice" }, diff --git a/source/views/view_store.cpp b/source/views/view_store.cpp index f2106a047..8884063b2 100644 --- a/source/views/view_store.cpp +++ b/source/views/view_store.cpp @@ -7,9 +7,11 @@ #include #include #include +#include #include #include +#include #include namespace hex { @@ -26,24 +28,24 @@ namespace hex { ViewStore::~ViewStore() { } void ViewStore::drawStore() { - ImGui::Header("ImHex content store", true); + ImGui::Header("hex.view.store.desc"_lang, true); - if (ImGui::Button("Reload")) { + if (ImGui::Button("hex.view.store.reload"_lang)) { this->refresh(); } - auto drawTab = [this](auto title, ImHexPath pathType, auto &content) { + auto drawTab = [this](auto title, ImHexPath pathType, auto &content, std::function downloadDoneCallback) { if (ImGui::BeginTabItem(title)) { - if (ImGui::BeginTable("##pattern_language", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) { + if (ImGui::BeginTable("##pattern_language", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_RowBg)) { ImGui::TableSetupScrollFreeze(0, 1); - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_None, 1.0); - ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_None, 3.0); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_None, 1.0); + ImGui::TableSetupColumn("hex.view.store.name"_lang, ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("hex.view.store.description"_lang, ImGuiTableColumnFlags_None); + ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed); ImGui::TableHeadersRow(); for (auto &entry : content) { - ImGui::TableNextRow(); + ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeight() + 4.0F * ImGui::GetStyle().FramePadding.y); ImGui::TableNextColumn(); ImGui::TextUnformatted(entry.name.c_str()); ImGui::TableNextColumn(); @@ -53,7 +55,7 @@ namespace hex { ImGui::BeginDisabled(this->m_download.valid() && this->m_download.wait_for(0s) != std::future_status::ready); { if (entry.downloading) { - ImGui::TextSpinner("Downloading..."); + ImGui::TextSpinner(""); if (this->m_download.valid() && this->m_download.wait_for(0s) == std::future_status::ready) { entry.downloading = false; @@ -62,6 +64,7 @@ namespace hex { if (response.code == 200) { entry.installed = true; entry.hasUpdate = false; + downloadDoneCallback(); } else log::error("Download failed!"); @@ -70,17 +73,17 @@ namespace hex { } } else if (entry.hasUpdate) { - if (ImGui::Button("Update")) { + if (ImGui::Button("hex.view.store.update"_lang)) { this->download(pathType, entry.fileName, entry.link, true); entry.downloading = true; } } else if (!entry.installed) { - if (ImGui::Button("Download")) { + if (ImGui::Button("hex.view.store.download"_lang)) { this->download(pathType, entry.fileName, entry.link, false); entry.downloading = true; } } else { - if (ImGui::Button("Remove")) { + if (ImGui::Button("hex.view.store.remove"_lang)) { this->remove(pathType, entry.fileName); entry.installed = false; } @@ -96,9 +99,11 @@ namespace hex { }; if (ImGui::BeginTabBar("storeTabs")) { - drawTab("Patterns", ImHexPath::Patterns, this->m_patterns); - drawTab("Libraries", ImHexPath::PatternsInclude, this->m_includes); - drawTab("Magic", ImHexPath::Magic, this->m_magics); + drawTab("hex.view.store.tab.patterns"_lang, ImHexPath::Patterns, this->m_patterns, []{}); + drawTab("hex.view.store.tab.libraries"_lang, ImHexPath::PatternsInclude, this->m_includes, []{}); + drawTab("hex.view.store.tab.magics"_lang, ImHexPath::Magic, this->m_magics, []{ + magic::compile(); + }); ImGui::EndTabBar(); } @@ -114,9 +119,7 @@ namespace hex { void ViewStore::parseResponse() { auto response = this->m_apiRequest.get(); - if (response.code != 200) - ImGui::TextUnformatted("Invalid response from store API"); - else { + if (response.code == 200) { auto json = nlohmann::json::parse(response.body); auto parseStoreEntries = [](auto storeJson, const std::string &name, ImHexPath pathType, std::vector &results) { @@ -157,13 +160,11 @@ namespace hex { } }; - parseStoreEntries(json, "pattern_language", ImHexPath::Patterns, this->m_patterns); + parseStoreEntries(json, "patterns", ImHexPath::Patterns, this->m_patterns); parseStoreEntries(json, "includes", ImHexPath::PatternsInclude, this->m_includes); parseStoreEntries(json, "magic", ImHexPath::Magic, this->m_magics); - - - this->m_apiRequest = { }; } + this->m_apiRequest = { }; } @@ -172,7 +173,7 @@ namespace hex { if (ImGui::BeginPopupModal(View::toWindowName("hex.view.store.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) { if (this->m_apiRequest.valid()) { if (this->m_apiRequest.wait_for(0s) != std::future_status::ready) - ImGui::TextSpinner("Loading store content..."); + ImGui::TextSpinner("hex.view.store.loading"_lang); else this->parseResponse(); }