2021-08-29 11:10:48 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/ui/view.hpp>
|
2023-11-30 10:22:15 +01:00
|
|
|
|
|
|
|
#include <hex/api/task_manager.hpp>
|
2023-03-23 11:23:07 +01:00
|
|
|
#include <hex/helpers/http_requests.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2024-06-22 10:44:55 +02:00
|
|
|
#include <hex/helpers/default_paths.hpp>
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
#include <future>
|
2021-08-29 11:10:48 +02:00
|
|
|
#include <string>
|
2021-09-23 22:56:49 +02:00
|
|
|
#include <filesystem>
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2022-10-27 13:12:24 +02:00
|
|
|
enum class RequestStatus {
|
|
|
|
NotAttempted,
|
|
|
|
InProgress,
|
|
|
|
Failed,
|
2023-02-16 18:55:21 +01:00
|
|
|
Succeeded,
|
2022-10-27 13:12:24 +02:00
|
|
|
};
|
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
struct StoreEntry {
|
|
|
|
std::string name;
|
|
|
|
std::string description;
|
2023-09-02 18:36:34 +02:00
|
|
|
std::vector<std::string> authors;
|
2021-09-03 02:34:40 +02:00
|
|
|
std::string fileName;
|
|
|
|
std::string link;
|
|
|
|
std::string hash;
|
2021-08-29 11:10:48 +02:00
|
|
|
|
2021-09-23 22:56:49 +02:00
|
|
|
bool isFolder;
|
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
bool downloading;
|
|
|
|
bool installed;
|
|
|
|
bool hasUpdate;
|
2023-10-24 20:00:49 +02:00
|
|
|
bool system;
|
2021-09-03 02:34:40 +02:00
|
|
|
};
|
|
|
|
|
2023-07-11 09:19:52 +02:00
|
|
|
struct StoreCategory {
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString unlocalizedName;
|
2023-07-11 09:19:52 +02:00
|
|
|
std::string requestName;
|
2024-06-22 10:44:55 +02:00
|
|
|
const paths::impl::DefaultPath* path;
|
2023-07-11 09:19:52 +02:00
|
|
|
std::vector<StoreEntry> entries;
|
|
|
|
std::function<void()> downloadCallback;
|
|
|
|
};
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
class ViewStore : public View::Floating {
|
2021-08-29 11:10:48 +02:00
|
|
|
public:
|
2021-09-03 02:34:40 +02:00
|
|
|
ViewStore();
|
2022-03-04 20:52:39 +01:00
|
|
|
~ViewStore() override = default;
|
2021-08-29 11:10:48 +02:00
|
|
|
|
|
|
|
void drawContent() override;
|
|
|
|
|
2023-11-23 13:08:45 +01:00
|
|
|
[[nodiscard]] bool shouldDraw() const override { return true; }
|
2022-01-10 21:05:37 +01:00
|
|
|
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
|
2021-09-03 02:34:40 +02:00
|
|
|
|
2023-04-10 21:30:27 +02:00
|
|
|
[[nodiscard]] ImVec2 getMinSize() const override { return scaled({ 600, 400 }); }
|
|
|
|
[[nodiscard]] ImVec2 getMaxSize() const override { return scaled({ 900, 700 }); }
|
2022-02-21 18:57:53 +01:00
|
|
|
|
2021-09-03 02:34:40 +02:00
|
|
|
private:
|
|
|
|
void drawStore();
|
2023-07-11 09:19:52 +02:00
|
|
|
void drawTab(StoreCategory &category);
|
|
|
|
void handleDownloadFinished(const StoreCategory &category, StoreEntry &entry);
|
2021-09-03 02:34:40 +02:00
|
|
|
|
|
|
|
void refresh();
|
|
|
|
void parseResponse();
|
|
|
|
|
2024-06-22 10:44:55 +02:00
|
|
|
void addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, const paths::impl::DefaultPath *path, std::function<void()> downloadCallback = []{});
|
2023-07-11 09:19:52 +02:00
|
|
|
|
2024-06-22 10:44:55 +02:00
|
|
|
bool download(const paths::impl::DefaultPath *pathType, const std::string &fileName, const std::string &url);
|
|
|
|
bool remove(const paths::impl::DefaultPath *pathType, const std::string &fileName);
|
2023-12-27 16:33:49 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
HttpRequest m_httpRequest = HttpRequest("GET", "");
|
|
|
|
std::future<HttpRequest::Result<std::string>> m_apiRequest;
|
|
|
|
std::future<HttpRequest::Result<std::string>> m_download;
|
|
|
|
std::fs::path m_downloadPath;
|
|
|
|
RequestStatus m_requestStatus = RequestStatus::NotAttempted;
|
|
|
|
|
|
|
|
std::vector<StoreCategory> m_categories;
|
|
|
|
TaskHolder m_updateAllTask;
|
|
|
|
std::atomic<u32> m_updateCount = 0;
|
2021-08-29 11:10:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|