2021-12-07 22:47:41 +01:00
|
|
|
#include "content/views/view_store.hpp"
|
2023-04-19 21:56:34 +02:00
|
|
|
#include <hex/api/theme_manager.hpp>
|
2023-08-06 21:33:15 +02:00
|
|
|
#include <hex/api/achievement_manager.hpp>
|
2023-04-19 21:56:34 +02:00
|
|
|
#include <hex/api_urls.hpp>
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
|
2023-12-23 21:09:41 +01:00
|
|
|
#include <popups/popup_notification.hpp>
|
2023-12-26 00:22:47 +01:00
|
|
|
#include <toasts/toast_notification.hpp>
|
2023-04-08 12:30:38 +02:00
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/crypto.hpp>
|
|
|
|
#include <hex/helpers/logger.hpp>
|
2021-09-08 17:22:54 +02:00
|
|
|
#include <hex/helpers/magic.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-06-16 15:42:08 +02:00
|
|
|
#include <hex/helpers/tar.hpp>
|
2021-09-03 02:34:40 +02:00
|
|
|
|
|
|
|
#include <filesystem>
|
2021-09-08 17:22:54 +02:00
|
|
|
#include <functional>
|
2021-09-03 02:34:40 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <wolv/io/file.hpp>
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ViewStore::ViewStore() : View::Floating("hex.builtin.view.store.name") {
|
2023-05-12 08:38:32 +02:00
|
|
|
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.store.name" }, 1000, Shortcut::None, [&, this] {
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_requestStatus == RequestStatus::NotAttempted)
|
2023-03-20 13:11:43 +01:00
|
|
|
this->refresh();
|
2023-11-23 13:08:45 +01:00
|
|
|
|
2023-03-20 13:11:43 +01:00
|
|
|
this->getWindowOpenState() = true;
|
2022-01-23 02:28:38 +01:00
|
|
|
});
|
2023-03-23 11:23:07 +01:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_httpRequest.setTimeout(30'0000);
|
2023-07-11 09:19:52 +02:00
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
addCategory("hex.builtin.view.store.tab.patterns", "patterns", fs::ImHexPath::Patterns);
|
|
|
|
addCategory("hex.builtin.view.store.tab.includes", "includes", fs::ImHexPath::PatternsInclude);
|
|
|
|
addCategory("hex.builtin.view.store.tab.magic", "magic", fs::ImHexPath::Magic, []{
|
2023-07-11 09:19:52 +02:00
|
|
|
magic::compile();
|
|
|
|
});
|
2023-12-19 12:22:28 +01:00
|
|
|
addCategory("hex.builtin.view.store.tab.nodes", "nodes", fs::ImHexPath::Nodes);
|
|
|
|
addCategory("hex.builtin.view.store.tab.encodings", "encodings", fs::ImHexPath::Encodings);
|
|
|
|
addCategory("hex.builtin.view.store.tab.constants", "constants", fs::ImHexPath::Constants);
|
|
|
|
addCategory("hex.builtin.view.store.tab.themes", "themes", fs::ImHexPath::Themes, [this]{
|
2023-12-19 13:10:25 +01:00
|
|
|
auto themeFile = wolv::io::File(m_downloadPath, wolv::io::File::Mode::Read);
|
2023-07-11 09:19:52 +02:00
|
|
|
|
|
|
|
ThemeManager::addTheme(themeFile.readString());
|
|
|
|
});
|
2023-12-19 12:22:28 +01:00
|
|
|
addCategory("hex.builtin.view.store.tab.yara", "yara", fs::ImHexPath::Yara);
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-24 20:00:49 +02:00
|
|
|
|
|
|
|
void updateEntryMetadata(StoreEntry &storeEntry, const StoreCategory &category) {
|
|
|
|
// Check if file is installed already or has an update available
|
|
|
|
for (const auto &folder : fs::getDefaultPaths(category.path)) {
|
|
|
|
auto path = folder / std::fs::path(storeEntry.fileName);
|
|
|
|
|
|
|
|
if (wolv::io::fs::exists(path)) {
|
|
|
|
storeEntry.installed = true;
|
|
|
|
|
|
|
|
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
|
|
|
auto bytes = file.readVector();
|
|
|
|
|
|
|
|
auto fileHash = crypt::sha256(bytes);
|
|
|
|
|
|
|
|
// Compare installed file hash with hash of repo file
|
|
|
|
if (std::vector(fileHash.begin(), fileHash.end()) != crypt::decode16(storeEntry.hash))
|
|
|
|
storeEntry.hasUpdate = true;
|
|
|
|
|
|
|
|
storeEntry.system = !fs::isPathWritable(folder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
storeEntry.installed = false;
|
|
|
|
storeEntry.hasUpdate = false;
|
|
|
|
storeEntry.system = false;
|
|
|
|
}
|
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
void ViewStore::drawTab(hex::plugin::builtin::StoreCategory &category) {
|
2023-11-21 14:38:01 +01:00
|
|
|
if (ImGui::BeginTabItem(Lang(category.unlocalizedName))) {
|
2023-09-02 18:36:34 +02:00
|
|
|
if (ImGui::BeginTable("##pattern_language", 4, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_RowBg)) {
|
2023-07-11 09:19:52 +02:00
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.store.row.name"_lang, ImGuiTableColumnFlags_WidthFixed);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.store.row.description"_lang, ImGuiTableColumnFlags_None);
|
2023-09-02 18:36:34 +02:00
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.store.row.authors"_lang, ImGuiTableColumnFlags_WidthFixed);
|
2023-07-11 09:19:52 +02:00
|
|
|
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed);
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
u32 id = 1;
|
|
|
|
for (auto &entry : category.entries) {
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(entry.name.c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(entry.description.c_str());
|
2023-09-02 18:36:34 +02:00
|
|
|
if (ImGui::IsItemHovered()) {
|
|
|
|
ImGui::BeginTooltip();
|
|
|
|
ImGui::PushTextWrapPos(500);
|
|
|
|
ImGui::TextUnformatted(entry.description.c_str());
|
|
|
|
ImGui::PopTextWrapPos();
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-04 12:00:32 +02:00
|
|
|
// The space makes a padding in the UI
|
2023-09-02 18:36:34 +02:00
|
|
|
ImGui::Text("%s ", wolv::util::combineStrings(entry.authors, ", ").c_str());
|
2023-07-11 09:19:52 +02:00
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
const auto buttonSize = ImVec2(100_scaled, ImGui::GetTextLineHeightWithSpacing());
|
|
|
|
|
|
|
|
ImGui::PushID(id);
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGui::BeginDisabled(m_updateAllTask.isRunning() || (m_download.valid() && m_download.wait_for(0s) != std::future_status::ready));
|
2023-07-11 09:19:52 +02:00
|
|
|
{
|
|
|
|
if (entry.downloading) {
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGui::ProgressBar(m_httpRequest.getProgress(), buttonSize, "");
|
2023-07-11 09:19:52 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_download.valid() && m_download.wait_for(0s) == std::future_status::ready) {
|
2023-07-11 09:19:52 +02:00
|
|
|
this->handleDownloadFinished(category, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
|
|
|
|
|
|
|
if (entry.hasUpdate) {
|
|
|
|
if (ImGui::Button("hex.builtin.view.store.update"_lang, buttonSize)) {
|
2023-12-28 21:51:31 +01:00
|
|
|
entry.downloading = this->download(category.path, entry.fileName, entry.link);
|
2023-10-24 20:00:49 +02:00
|
|
|
}
|
|
|
|
} else if (entry.system) {
|
|
|
|
ImGui::BeginDisabled();
|
|
|
|
ImGui::Button("hex.builtin.view.store.system"_lang, buttonSize);
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
|
|
|
|
ImGui::BeginTooltip();
|
|
|
|
ImGui::TextUnformatted("hex.builtin.view.store.system.explanation"_lang);
|
|
|
|
ImGui::EndTooltip();
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
} else if (!entry.installed) {
|
|
|
|
if (ImGui::Button("hex.builtin.view.store.download"_lang, buttonSize)) {
|
2023-12-28 21:51:31 +01:00
|
|
|
entry.downloading = this->download(category.path, entry.fileName, entry.link);
|
2023-08-06 21:33:15 +02:00
|
|
|
AchievementManager::unlockAchievement("hex.builtin.achievement.misc", "hex.builtin.achievement.misc.download_from_store.name");
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ImGui::Button("hex.builtin.view.store.remove"_lang, buttonSize)) {
|
|
|
|
entry.installed = !this->remove(category.path, entry.fileName);
|
2023-10-24 20:00:49 +02:00
|
|
|
// remove() will not update the entry to mark it as a system entry, so we do it manually
|
|
|
|
updateEntryMetadata(entry, category);
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
ImGui::PopID();
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewStore::drawStore() {
|
2023-11-16 22:24:06 +01:00
|
|
|
ImGuiExt::Header("hex.builtin.view.store.desc"_lang, true);
|
2021-09-03 02:34:40 +02:00
|
|
|
|
2023-03-23 13:32:47 +01:00
|
|
|
bool reloading = false;
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_apiRequest.valid()) {
|
|
|
|
if (m_apiRequest.wait_for(0s) != std::future_status::ready)
|
2023-03-23 13:32:47 +01:00
|
|
|
reloading = true;
|
2023-12-27 17:10:50 +01:00
|
|
|
else {
|
|
|
|
try {
|
|
|
|
this->parseResponse();
|
|
|
|
} catch (nlohmann::json::exception &e) {
|
|
|
|
log::error("Failed to parse store response: {}", e.what());
|
|
|
|
}
|
|
|
|
}
|
2023-03-23 13:32:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::BeginDisabled(reloading);
|
2021-12-07 22:47:41 +01:00
|
|
|
if (ImGui::Button("hex.builtin.view.store.reload"_lang)) {
|
2021-09-03 02:34:40 +02:00
|
|
|
this->refresh();
|
|
|
|
}
|
2023-03-23 13:32:47 +01:00
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
|
|
if (reloading) {
|
|
|
|
ImGui::SameLine();
|
2023-11-16 22:24:06 +01:00
|
|
|
ImGuiExt::TextSpinner("hex.builtin.view.store.loading"_lang);
|
2023-03-23 13:32:47 +01:00
|
|
|
}
|
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
// Align the button to the right
|
|
|
|
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - 25_scaled);
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGui::BeginDisabled(m_updateAllTask.isRunning() || m_updateCount == 0);
|
2023-11-16 22:24:06 +01:00
|
|
|
if (ImGuiExt::IconButton(ICON_VS_CLOUD_DOWNLOAD, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_updateAllTask = TaskManager::createTask("Update All...", m_updateCount, [this](auto &task) {
|
2023-07-11 09:19:52 +02:00
|
|
|
u32 progress = 0;
|
2023-12-19 13:10:25 +01:00
|
|
|
for (auto &category : m_categories) {
|
2023-07-11 09:19:52 +02:00
|
|
|
for (auto &entry : category.entries) {
|
|
|
|
if (entry.hasUpdate) {
|
2023-12-28 21:51:31 +01:00
|
|
|
entry.downloading = this->download(category.path, entry.fileName, entry.link);
|
2023-12-28 20:35:35 +01:00
|
|
|
if (!m_download.valid())
|
|
|
|
continue;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_download.wait();
|
2023-07-11 09:19:52 +02:00
|
|
|
this->handleDownloadFinished(category, entry);
|
|
|
|
task.update(progress);
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-29 11:10:48 +02:00
|
|
|
}
|
2023-03-23 20:35:16 +01:00
|
|
|
});
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGuiExt::InfoTooltip(hex::format("hex.builtin.view.store.update_count"_lang, m_updateCount.load()).c_str());
|
2023-03-23 20:35:16 +01:00
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
|
|
if (ImGui::BeginTabBar("storeTabs")) {
|
2023-12-19 13:10:25 +01:00
|
|
|
for (auto &category : m_categories) {
|
2023-07-11 09:19:52 +02:00
|
|
|
this->drawTab(category);
|
|
|
|
}
|
2021-09-03 02:34:40 +02:00
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
2021-08-29 11:10:48 +02:00
|
|
|
}
|
2023-07-11 09:19:52 +02:00
|
|
|
|
2021-08-29 11:10:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
void ViewStore::refresh() {
|
2023-10-04 12:00:32 +02:00
|
|
|
// Do not refresh if a refresh is already in progress
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_requestStatus == RequestStatus::InProgress)
|
2022-10-27 13:12:24 +02:00
|
|
|
return;
|
2023-12-19 13:10:25 +01:00
|
|
|
m_requestStatus = RequestStatus::InProgress;
|
2022-10-27 13:12:24 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
for (auto &category : m_categories) {
|
2023-07-11 09:19:52 +02:00
|
|
|
category.entries.clear();
|
|
|
|
}
|
2021-09-03 02:34:40 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_httpRequest.setUrl(ImHexApiURL + "/store"s);
|
|
|
|
m_apiRequest = m_httpRequest.execute();
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewStore::parseResponse() {
|
2023-12-19 13:10:25 +01:00
|
|
|
auto response = m_apiRequest.get();
|
|
|
|
m_requestStatus = response.isSuccess() ? RequestStatus::Succeeded : RequestStatus::Failed;
|
|
|
|
if (m_requestStatus == RequestStatus::Succeeded) {
|
2023-03-23 11:23:07 +01:00
|
|
|
auto json = nlohmann::json::parse(response.getData());
|
2021-09-03 02:34:40 +02:00
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
auto parseStoreEntries = [](auto storeJson, StoreCategory &category) {
|
2021-09-03 02:34:40 +02:00
|
|
|
// Check if the response handles the type of files
|
2023-07-11 09:19:52 +02:00
|
|
|
if (storeJson.contains(category.requestName)) {
|
2021-09-03 02:34:40 +02:00
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
for (auto &entry : storeJson[category.requestName]) {
|
2021-09-03 02:34:40 +02:00
|
|
|
|
|
|
|
// Check if entry is valid
|
2023-09-02 18:36:34 +02:00
|
|
|
if (entry.contains("name") && entry.contains("desc") && entry.contains("authors") && entry.contains("file") && entry.contains("url") && entry.contains("hash") && entry.contains("folder")) {
|
2021-09-03 02:34:40 +02:00
|
|
|
|
|
|
|
// Parse entry
|
2023-10-24 20:00:49 +02:00
|
|
|
StoreEntry storeEntry = { entry["name"], entry["desc"], entry["authors"], entry["file"], entry["url"], entry["hash"], entry["folder"], false, false, false, false };
|
2021-09-03 02:34:40 +02:00
|
|
|
|
2023-10-24 20:00:49 +02:00
|
|
|
updateEntryMetadata(storeEntry, category);
|
2023-07-11 09:19:52 +02:00
|
|
|
category.entries.push_back(storeEntry);
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-23 13:32:47 +01:00
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
std::sort(category.entries.begin(), category.entries.end(), [](const auto &lhs, const auto &rhs) {
|
2023-03-23 13:32:47 +01:00
|
|
|
return lhs.name < rhs.name;
|
|
|
|
});
|
2021-09-03 02:34:40 +02:00
|
|
|
};
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
for (auto &category : m_categories) {
|
2023-07-11 09:19:52 +02:00
|
|
|
parseStoreEntries(json, category);
|
|
|
|
}
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_updateCount = 0;
|
|
|
|
for (auto &category : m_categories) {
|
2023-07-11 09:19:52 +02:00
|
|
|
for (auto &entry : category.entries) {
|
|
|
|
if (entry.hasUpdate)
|
2023-12-19 13:10:25 +01:00
|
|
|
m_updateCount += 1;
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
2023-12-19 13:10:25 +01:00
|
|
|
m_apiRequest = {};
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewStore::drawContent() {
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_requestStatus == RequestStatus::Failed)
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGuiExt::TextFormattedColored(ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), "hex.builtin.view.store.netfailed"_lang);
|
|
|
|
|
|
|
|
this->drawStore();
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
|
|
|
|
2023-12-28 21:51:31 +01:00
|
|
|
bool ViewStore::download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url) {
|
2022-01-23 21:52:24 +01:00
|
|
|
bool downloading = false;
|
2023-09-02 17:51:21 +02:00
|
|
|
for (const auto &folderPath : fs::getDefaultPaths(pathType)) {
|
|
|
|
if (!fs::isPathWritable(folderPath))
|
2022-02-28 23:10:04 +01:00
|
|
|
continue;
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
// Verify that we write the file to the right folder
|
2023-09-02 17:51:21 +02:00
|
|
|
// this is to prevent the filename from having elements like ../
|
|
|
|
auto fullPath = std::fs::weakly_canonical(folderPath / std::fs::path(fileName));
|
|
|
|
auto [folderIter, pathIter] = std::mismatch(folderPath.begin(), folderPath.end(), fullPath.begin());
|
2023-11-10 20:47:08 +01:00
|
|
|
if (folderIter != folderPath.end()) {
|
2023-09-02 17:51:21 +02:00
|
|
|
log::warn("The destination file name '{}' is invalid", fileName);
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-28 23:10:04 +01:00
|
|
|
|
2023-12-28 20:59:25 +01:00
|
|
|
downloading = true;
|
|
|
|
m_downloadPath = fullPath;
|
|
|
|
|
|
|
|
m_httpRequest.setUrl(url);
|
|
|
|
m_download = m_httpRequest.downloadFile(fullPath);
|
|
|
|
break;
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
2022-01-23 21:52:24 +01:00
|
|
|
|
|
|
|
if (!downloading) {
|
2023-12-26 00:22:47 +01:00
|
|
|
ui::ToastError::open("hex.builtin.view.store.download_error"_lang);
|
2022-01-23 21:52:24 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-09-03 02:34:40 +02:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
bool ViewStore::remove(fs::ImHexPath pathType, const std::string &fileName) {
|
2022-06-16 15:42:08 +02:00
|
|
|
bool removed = true;
|
2022-03-04 11:36:37 +01:00
|
|
|
for (const auto &path : fs::getDefaultPaths(pathType)) {
|
2022-06-16 15:42:08 +02:00
|
|
|
const auto filePath = path / fileName;
|
|
|
|
const auto folderPath = (path / std::fs::path(fileName).stem());
|
2022-01-23 21:52:24 +01:00
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
wolv::io::fs::remove(filePath);
|
|
|
|
wolv::io::fs::removeAll(folderPath);
|
2022-06-16 15:42:08 +02:00
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
removed = removed && !wolv::io::fs::exists(filePath) && !wolv::io::fs::exists(folderPath);
|
2023-12-08 10:29:44 +01:00
|
|
|
EventStoreContentRemoved::post(filePath);
|
2021-10-17 22:23:01 +02:00
|
|
|
}
|
2022-01-23 21:52:24 +01:00
|
|
|
|
|
|
|
return removed;
|
2021-08-29 11:10:48 +02:00
|
|
|
}
|
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
void ViewStore::addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_categories.push_back({ unlocalizedName, requestName, path, { }, std::move(downloadCallback) });
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewStore::handleDownloadFinished(const StoreCategory &category, StoreEntry &entry) {
|
|
|
|
entry.downloading = false;
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
auto response = m_download.get();
|
2023-07-11 09:19:52 +02:00
|
|
|
if (response.isSuccess()) {
|
|
|
|
if (entry.hasUpdate)
|
2023-12-19 13:10:25 +01:00
|
|
|
m_updateCount -= 1;
|
2023-07-11 09:19:52 +02:00
|
|
|
|
|
|
|
entry.installed = true;
|
|
|
|
entry.hasUpdate = false;
|
2023-10-24 20:00:49 +02:00
|
|
|
entry.system = false;
|
2023-07-11 09:19:52 +02:00
|
|
|
|
|
|
|
if (entry.isFolder) {
|
2023-12-19 13:10:25 +01:00
|
|
|
Tar tar(m_downloadPath, Tar::Mode::Read);
|
|
|
|
tar.extractAll(m_downloadPath.parent_path() / m_downloadPath.stem());
|
|
|
|
EventStoreContentDownloaded::post(m_downloadPath.parent_path() / m_downloadPath.stem());
|
2023-07-11 09:19:52 +02:00
|
|
|
} else {
|
2023-12-19 13:10:25 +01:00
|
|
|
EventStoreContentDownloaded::post(m_downloadPath);
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
category.downloadCallback();
|
2023-12-27 16:33:49 +01:00
|
|
|
} else {
|
2023-07-11 09:19:52 +02:00
|
|
|
log::error("Download failed! HTTP Code {}", response.getStatusCode());
|
2023-12-27 16:33:49 +01:00
|
|
|
}
|
2023-07-11 09:19:52 +02:00
|
|
|
|
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_download = {};
|
2023-07-11 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:10:48 +02:00
|
|
|
}
|