store: Added encoding files to store, fixed crash when folder doesn't exist
This commit is contained in:
parent
053c897056
commit
9cf7fc4a2e
@ -18,6 +18,7 @@ namespace hex {
|
||||
Config,
|
||||
Resources,
|
||||
Constants,
|
||||
Encodings,
|
||||
Logs
|
||||
};
|
||||
|
||||
|
@ -98,6 +98,11 @@ namespace hex {
|
||||
return (path / "constants").string();
|
||||
});
|
||||
break;
|
||||
case ImHexPath::Encodings:
|
||||
std::transform(paths.begin(), paths.end(), std::back_inserter(result), [](auto &path){
|
||||
return (path / "encodings").string();
|
||||
});
|
||||
break;
|
||||
case ImHexPath::Logs:
|
||||
std::transform(paths.begin(), paths.end(), std::back_inserter(result), [](auto &path){
|
||||
return (path / "logs").string();
|
||||
@ -142,6 +147,9 @@ namespace hex {
|
||||
case ImHexPath::Constants:
|
||||
result.push_back((applicationSupportDir / "constants").string());
|
||||
break;
|
||||
case ImHexPath::Encodings:
|
||||
result.push_back((applicationSupportDir / "encodings").string());
|
||||
break;
|
||||
case ImHexPath::Logs:
|
||||
result.push_back((applicationSupportDir / "logs").string());
|
||||
break;
|
||||
@ -199,6 +207,10 @@ namespace hex {
|
||||
std::transform(dataDirs.begin(), dataDirs.end(), std::back_inserter(result),
|
||||
[](auto p) { return (p / "constants").string(); });
|
||||
break;
|
||||
case ImHexPath::Encodings:
|
||||
std::transform(dataDirs.begin(), dataDirs.end(), std::back_inserter(result),
|
||||
[](auto p) { return (p / "encodings").string(); });
|
||||
break;
|
||||
case ImHexPath::Logs:
|
||||
std::transform(dataDirs.begin(), dataDirs.end(), std::back_inserter(result),
|
||||
[](auto p) { return (p / "logs").string(); });
|
||||
|
@ -50,7 +50,7 @@ namespace hex::init {
|
||||
try {
|
||||
status = task() && status;
|
||||
} catch (std::exception &e) {
|
||||
log::error("Init task {} threw an exception: {}", name, e.what());
|
||||
log::error("Init task '{}' threw an exception: {}", name, e.what());
|
||||
status = false;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ namespace hex::init {
|
||||
ImHexPath::Config,
|
||||
ImHexPath::Constants,
|
||||
ImHexPath::Yara,
|
||||
ImHexPath::Encodings,
|
||||
ImHexPath::Python,
|
||||
ImHexPath::Logs
|
||||
};
|
||||
|
@ -43,15 +43,15 @@ namespace hex::plugin::builtin {
|
||||
std::future<Response<void>> m_download;
|
||||
fs::path m_downloadPath;
|
||||
|
||||
std::vector<StoreEntry> m_patterns, m_includes, m_magics, m_constants, m_yara;
|
||||
std::vector<StoreEntry> m_patterns, m_includes, m_magics, m_constants, m_yara, m_encodings;
|
||||
|
||||
void drawStore();
|
||||
|
||||
void refresh();
|
||||
void parseResponse();
|
||||
|
||||
void download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update);
|
||||
void remove(ImHexPath pathType, const std::string &fileName);
|
||||
bool download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update);
|
||||
bool remove(ImHexPath pathType, const std::string &fileName);
|
||||
};
|
||||
|
||||
}
|
@ -42,7 +42,7 @@ namespace hex::plugin::builtin {
|
||||
this->refresh();
|
||||
}
|
||||
|
||||
auto drawTab = [this](auto title, ImHexPath pathType, auto &content, std::function<void(const StoreEntry&)> downloadDoneCallback) {
|
||||
auto drawTab = [this](auto title, ImHexPath pathType, auto &content, const std::function<void(const StoreEntry&)> &downloadDoneCallback) {
|
||||
if (ImGui::BeginTabItem(title)) {
|
||||
if (ImGui::BeginTable("##pattern_language", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_RowBg)) {
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
@ -116,18 +116,15 @@ namespace hex::plugin::builtin {
|
||||
|
||||
} else if (entry.hasUpdate) {
|
||||
if (ImGui::Button("hex.builtin.view.store.update"_lang)) {
|
||||
this->download(pathType, entry.fileName, entry.link, true);
|
||||
entry.downloading = true;
|
||||
entry.downloading = this->download(pathType, entry.fileName, entry.link, true);
|
||||
}
|
||||
} else if (!entry.installed) {
|
||||
if (ImGui::Button("hex.builtin.view.store.download"_lang)) {
|
||||
this->download(pathType, entry.fileName, entry.link, false);
|
||||
entry.downloading = true;
|
||||
entry.downloading = this->download(pathType, entry.fileName, entry.link, false);
|
||||
}
|
||||
} else {
|
||||
if (ImGui::Button("hex.builtin.view.store.remove"_lang)) {
|
||||
this->remove(pathType, entry.fileName);
|
||||
entry.installed = false;
|
||||
entry.installed = !this->remove(pathType, entry.fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,17 +140,12 @@ namespace hex::plugin::builtin {
|
||||
};
|
||||
|
||||
if (ImGui::BeginTabBar("storeTabs")) {
|
||||
auto extractTar = []{
|
||||
|
||||
};
|
||||
|
||||
drawTab("hex.builtin.view.store.tab.patterns"_lang, ImHexPath::Patterns, this->m_patterns, [](auto){});
|
||||
drawTab("hex.builtin.view.store.tab.libraries"_lang, ImHexPath::PatternsInclude, this->m_includes, [](auto){});
|
||||
drawTab("hex.builtin.view.store.tab.magics"_lang, ImHexPath::Magic, this->m_magics, [](auto){
|
||||
magic::compile();
|
||||
});
|
||||
drawTab("hex.builtin.view.store.tab.constants"_lang, ImHexPath::Constants, this->m_constants, [](auto){});
|
||||
drawTab("hex.builtin.view.store.tab.yara"_lang, ImHexPath::Yara, this->m_yara, [](auto){});
|
||||
drawTab("hex.builtin.view.store.tab.patterns"_lang, ImHexPath::Patterns, this->m_patterns, [](auto) {});
|
||||
drawTab("hex.builtin.view.store.tab.libraries"_lang, ImHexPath::PatternsInclude, this->m_includes, [](auto) {});
|
||||
drawTab("hex.builtin.view.store.tab.magics"_lang, ImHexPath::Magic, this->m_magics, [](auto) { magic::compile(); });
|
||||
drawTab("hex.builtin.view.store.tab.constants"_lang, ImHexPath::Constants, this->m_constants, [](auto) {});
|
||||
drawTab("hex.builtin.view.store.tab.encodings"_lang, ImHexPath::Encodings, this->m_encodings, [](auto) {});
|
||||
drawTab("hex.builtin.view.store.tab.yara"_lang, ImHexPath::Yara, this->m_yara, [](auto) {});
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
@ -165,6 +157,7 @@ namespace hex::plugin::builtin {
|
||||
this->m_magics.clear();
|
||||
this->m_constants.clear();
|
||||
this->m_yara.clear();
|
||||
this->m_encodings.clear();
|
||||
|
||||
this->m_apiRequest = this->m_net.getString(ImHexApiURL + "/store"s);
|
||||
}
|
||||
@ -217,6 +210,7 @@ namespace hex::plugin::builtin {
|
||||
parseStoreEntries(json, "magic", ImHexPath::Magic, this->m_magics);
|
||||
parseStoreEntries(json, "constants", ImHexPath::Constants, this->m_constants);
|
||||
parseStoreEntries(json, "yara", ImHexPath::Yara, this->m_yara);
|
||||
parseStoreEntries(json, "encodings", ImHexPath::Encodings, this->m_encodings);
|
||||
|
||||
}
|
||||
this->m_apiRequest = { };
|
||||
@ -241,26 +235,36 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}
|
||||
|
||||
void ViewStore::download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) {
|
||||
if (!update) {
|
||||
this->m_downloadPath = hex::getPath(pathType).back() / fs::path(fileName);
|
||||
this->m_download = this->m_net.downloadFile(url, this->m_downloadPath);
|
||||
} else {
|
||||
for (const auto &path : hex::getPath(pathType)) {
|
||||
auto fullPath = path / fs::path(fileName);
|
||||
if (fs::exists(fullPath)) {
|
||||
this->m_downloadPath = fullPath;
|
||||
this->m_download = this->m_net.downloadFile(url, fullPath);
|
||||
}
|
||||
bool ViewStore::download(ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) {
|
||||
bool downloading = false;
|
||||
for (const auto &path : hex::getPath(pathType)) {
|
||||
auto fullPath = path / fs::path(fileName);
|
||||
if (!update || fs::exists(fullPath)) {
|
||||
downloading = true;
|
||||
this->m_downloadPath = fullPath;
|
||||
this->m_download = this->m_net.downloadFile(url, fullPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!downloading) {
|
||||
View::showErrorPopup("hex.builtin.view.store.download_error"_lang);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewStore::remove(ImHexPath pathType, const std::string &fileName) {
|
||||
bool ViewStore::remove(ImHexPath pathType, const std::string &fileName) {
|
||||
bool removed = false;
|
||||
for (const auto &path : hex::getPath(pathType)) {
|
||||
fs::remove(path / fs::path(fileName));
|
||||
fs::remove(path / fs::path(fileName).stem());
|
||||
bool removedFile = fs::remove(path / fs::path(fileName));
|
||||
bool removedFolder = fs::remove(path / fs::path(fileName).stem());
|
||||
|
||||
removed = removedFile || removedFolder;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
}
|
@ -348,8 +348,11 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.store.tab.libraries", "Libraries" },
|
||||
{ "hex.builtin.view.store.tab.magics", "Magic Files" },
|
||||
{ "hex.builtin.view.store.tab.constants", "Konstanten" },
|
||||
{ "hex.builtin.view.store.tab.encodings", "Encodings" },
|
||||
{ "hex.builtin.view.store.tab.yara", "Yara Rules" },
|
||||
{ "hex.builtin.view.store.loading", "Store inhalt wird geladen..." },
|
||||
{ "hex.builtin.view.store.download_error", "Datei konnte nicht heruntergeladen werden! Zielordner konnte nicht gefunden werden." },
|
||||
|
||||
{ "hex.builtin.view.diff.name", "Diffing" },
|
||||
|
||||
{ "hex.builtin.view.provider_settings.name", "Provider Einstellungen" },
|
||||
|
@ -352,7 +352,10 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.store.tab.magics", "Magic Files" },
|
||||
{ "hex.builtin.view.store.tab.constants", "Constants" },
|
||||
{ "hex.builtin.view.store.tab.yara", "Yara Rules" },
|
||||
{ "hex.builtin.view.store.tab.encodings", "Encodings" },
|
||||
{ "hex.builtin.view.store.loading", "Loading store content..." },
|
||||
{ "hex.builtin.view.store.download_error", "Failed to download file! Destination folder does not exist." },
|
||||
|
||||
{ "hex.builtin.view.diff.name", "Diffing" },
|
||||
|
||||
{ "hex.builtin.view.provider_settings.name", "Provider Settings" },
|
||||
|
@ -345,8 +345,11 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.store.tab.libraries", "Librerie" },
|
||||
{ "hex.builtin.view.store.tab.magics", "File Magici" },
|
||||
{ "hex.builtin.view.store.tab.constants", "Costanti" },
|
||||
//{ "hex.builtin.view.store.tab.encodings", "Encodings" },
|
||||
{ "hex.builtin.view.store.tab.yara", "Regole di Yara" },
|
||||
{ "hex.builtin.view.store.loading", "Caricamento del content store..." },
|
||||
//{ "hex.builtin.view.store.download_error", "Failed to download file! Destination folder does not exist." },
|
||||
|
||||
//{ "hex.builtin.view.diff.name", "Diffing" },
|
||||
|
||||
//{ "hex.builtin.view.provider_settings.name", "Provider Settings" },
|
||||
|
@ -346,7 +346,10 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.store.tab.magics", "魔术数据库" },
|
||||
{ "hex.builtin.view.store.tab.constants", "常量" },
|
||||
{ "hex.builtin.view.store.tab.yara", "Yara规则" },
|
||||
{ "hex.builtin.view.store.loading", "正在加载仓库内容..." },
|
||||
//{ "hex.builtin.view.store.tab.encodings", "Encodings" },
|
||||
{ "hex.builtin.view.store.loading", "正在加载仓库内容..." },
|
||||
//{ "hex.builtin.view.store.download_error", "Failed to download file! Destination folder does not exist." },
|
||||
|
||||
{ "hex.builtin.view.diff.name", "差异" },
|
||||
|
||||
//{ "hex.builtin.view.provider_settings.name", "Provider Settings" },
|
||||
|
Loading…
Reference in New Issue
Block a user