#pragma once #include "Server.hpp" namespace server { struct DownloadStatusFetching { uint8_t percentage; bool operator==(DownloadStatusFetching const&) const = default; }; struct DownloadStatusConfirm { ServerModVersion version; bool operator==(DownloadStatusConfirm const&) const = default; }; struct DownloadStatusDownloading { uint8_t percentage; bool operator==(DownloadStatusDownloading const&) const = default; }; struct DownloadStatusDone { ServerModVersion version; bool operator==(DownloadStatusDone const&) const = default; }; struct DownloadStatusError { std::string details; bool operator==(DownloadStatusError const&) const = default; }; struct DownloadStatusCancelled { bool operator==(DownloadStatusCancelled const&) const = default; }; using DownloadStatus = std::variant< DownloadStatusFetching, DownloadStatusConfirm, DownloadStatusDownloading, DownloadStatusDone, DownloadStatusError, DownloadStatusCancelled >; struct ModDownloadEvent : public Event { std::string id; ModDownloadEvent(std::string const& id); }; class ModDownloadFilter : public EventFilter { public: using Callback = void(ModDownloadEvent*); protected: std::string m_id; public: ListenerResult handle(MiniFunction fn, ModDownloadEvent* event); ModDownloadFilter(); ModDownloadFilter(std::string const& id); }; using DependencyFor = std::pair; class ModDownload final { private: class Impl; std::shared_ptr m_impl; ModDownload( std::string const& id, std::optional const& version, std::optional const& dependencyFor, std::optional const& replacesMod ); friend class ModDownloadManager; public: void confirm(); void cancel(); bool isDone() const; bool isActive() const; bool canRetry() const; std::optional getReplacesMod() const; std::optional getDependencyFor() const; std::string getID() const; DownloadStatus getStatus() const; std::optional getVersion() const; }; class ModDownloadManager final { private: class Impl; std::unique_ptr m_impl; ModDownloadManager(); friend class ModDownload; public: static ModDownloadManager* get(); ~ModDownloadManager(); std::optional startDownload( std::string const& id, std::optional const& version, std::optional const& dependencyFor = std::nullopt, std::optional const& replacesMod = std::nullopt ); void startUpdateAll(); void confirmAll(); void cancelAll(); void dismissAll(); bool checkAutoConfirm(); std::optional getDownload(std::string const& id) const; std::vector getDownloads() const; bool hasActiveDownloads() const; bool wantsRestart() const; }; }