2024-04-23 15:24:08 -04:00
|
|
|
#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 {
|
2024-09-12 04:11:54 -04:00
|
|
|
ServerModVersion version;
|
2024-04-23 15:24:08 -04:00
|
|
|
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<ModDownloadEvent> {
|
|
|
|
public:
|
|
|
|
using Callback = void(ModDownloadEvent*);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string m_id;
|
|
|
|
|
|
|
|
public:
|
2024-11-04 12:42:09 -05:00
|
|
|
ListenerResult handle(std::function<Callback> fn, ModDownloadEvent* event);
|
2024-04-23 15:24:08 -04:00
|
|
|
|
|
|
|
ModDownloadFilter();
|
|
|
|
ModDownloadFilter(std::string const& id);
|
|
|
|
};
|
|
|
|
|
2024-05-09 08:15:06 -04:00
|
|
|
using DependencyFor = std::pair<std::string, ModMetadata::Dependency::Importance>;
|
|
|
|
|
2024-04-23 15:24:08 -04:00
|
|
|
class ModDownload final {
|
|
|
|
private:
|
|
|
|
class Impl;
|
|
|
|
|
|
|
|
std::shared_ptr<Impl> m_impl;
|
|
|
|
|
|
|
|
ModDownload(
|
|
|
|
std::string const& id,
|
|
|
|
std::optional<VersionInfo> const& version,
|
2024-06-03 11:12:48 -04:00
|
|
|
std::optional<DependencyFor> const& dependencyFor,
|
|
|
|
std::optional<std::string> const& replacesMod
|
2024-04-23 15:24:08 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
friend class ModDownloadManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void confirm();
|
|
|
|
void cancel();
|
|
|
|
|
|
|
|
bool isDone() const;
|
|
|
|
bool isActive() const;
|
|
|
|
bool canRetry() const;
|
2024-06-03 11:12:48 -04:00
|
|
|
std::optional<std::string> getReplacesMod() const;
|
2024-05-09 08:15:06 -04:00
|
|
|
std::optional<DependencyFor> getDependencyFor() const;
|
2024-04-23 15:24:08 -04:00
|
|
|
std::string getID() const;
|
|
|
|
DownloadStatus getStatus() const;
|
|
|
|
std::optional<VersionInfo> getVersion() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ModDownloadManager final {
|
|
|
|
private:
|
|
|
|
class Impl;
|
|
|
|
|
|
|
|
std::unique_ptr<Impl> m_impl;
|
|
|
|
|
|
|
|
ModDownloadManager();
|
|
|
|
|
|
|
|
friend class ModDownload;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static ModDownloadManager* get();
|
|
|
|
~ModDownloadManager();
|
|
|
|
|
|
|
|
std::optional<ModDownload> startDownload(
|
|
|
|
std::string const& id,
|
|
|
|
std::optional<VersionInfo> const& version,
|
2024-06-03 11:12:48 -04:00
|
|
|
std::optional<DependencyFor> const& dependencyFor = std::nullopt,
|
|
|
|
std::optional<std::string> const& replacesMod = std::nullopt
|
2024-04-23 15:24:08 -04:00
|
|
|
);
|
|
|
|
void startUpdateAll();
|
|
|
|
void confirmAll();
|
|
|
|
void cancelAll();
|
|
|
|
void dismissAll();
|
|
|
|
bool checkAutoConfirm();
|
|
|
|
|
|
|
|
std::optional<ModDownload> getDownload(std::string const& id) const;
|
|
|
|
std::vector<ModDownload> getDownloads() const;
|
|
|
|
bool hasActiveDownloads() const;
|
|
|
|
|
|
|
|
bool wantsRestart() const;
|
|
|
|
};
|
|
|
|
}
|