1
0
mirror of synced 2024-11-27 17:10:51 +01:00
ImHex/plugins/builtin/include/content/views/view_store.hpp
iTrooz_ 32ab1c1a06
sys: Load content store content when it's first opened (#795)
* refresh store on open

* show the user if the request failed

* do not refresh if a refresh is in progress

This makes ImHex crash

* InProgress

* fix formatting

* use a localized message

* set localized message in other langs
2022-10-27 13:12:24 +02:00

68 lines
1.7 KiB
C++

#pragma once
#include <hex.hpp>
#include <hex/ui/view.hpp>
#include <hex/helpers/net.hpp>
#include <hex/helpers/fs.hpp>
#include <array>
#include <future>
#include <string>
#include <filesystem>
namespace hex::plugin::builtin {
enum class RequestStatus {
NotAttempted,
InProgress,
Failed,
Succeded,
};
struct StoreEntry {
std::string name;
std::string description;
std::string fileName;
std::string link;
std::string hash;
bool isFolder;
bool downloading;
bool installed;
bool hasUpdate;
};
class ViewStore : public View {
public:
ViewStore();
~ViewStore() override = default;
void drawContent() override;
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override { return { 500, 400 }; }
[[nodiscard]] ImVec2 getMaxSize() const override { return { 500, 400 }; }
private:
Net m_net;
std::future<Response<std::string>> m_apiRequest;
std::future<Response<void>> m_download;
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;
void drawStore();
void refresh();
void parseResponse();
bool download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url, bool update);
bool remove(fs::ImHexPath pathType, const std::string &fileName);
};
}