mason/src/dependency.h

68 lines
1.9 KiB
C
Raw Normal View History

2023-08-31 20:06:02 +00:00
#pragma once
#include <string>
#include <optional>
2023-09-01 21:39:24 +00:00
#include <filesystem>
2023-09-03 00:53:36 +00:00
#include <list>
#include <stdio.h>
2023-09-01 21:39:24 +00:00
2023-09-03 00:53:36 +00:00
#include <nlohmann/json.hpp>
2023-09-01 21:39:24 +00:00
#include <curl/curl.h>
2023-09-04 21:45:01 +00:00
#include <archive.h>
#include <archive_entry.h>
2023-08-31 20:06:02 +00:00
class Dependency {
public:
enum class Type {
automatic,
simple,
mason
};
Dependency(
const std::string& path,
Type type = Type::automatic,
const std::optional<std::string>& name = std::nullopt,
const std::optional<std::string>& version = std::nullopt
);
Type getType() const;
std::optional<std::string> getName() const;
std::optional<std::string> getVersion() const;
2023-09-01 21:39:24 +00:00
bool prepare(const std::filesystem::path& source, const std::filesystem::path& destination);
2023-08-31 20:06:02 +00:00
const std::string path;
2023-09-01 21:39:24 +00:00
private:
2023-09-03 00:53:36 +00:00
static size_t writeFile(void* data, size_t size, size_t nmemb, void* file);
static size_t writeString(void* data, size_t size, size_t nmemb, void* mem);
static int trace(CURL *handle, curl_infotype type, char *data, size_t size, void *clientp);
bool download(const std::string& url, const std::filesystem::path& destination);
bool downloadRepo(
const std::filesystem::path& destination,
const std::string& protocol,
const std::string& host,
const std::string& owner,
const std::string& repo,
std::filesystem::path& out
2023-09-03 00:53:36 +00:00
);
bool repoGiteaApi1(
const std::string& protocol,
const std::string& host,
const std::string& owner,
const std::string& repo,
nlohmann::json& json
);
CURLcode httpGet(const std::string& url, std::string& result, const std::list<std::string_view>& headers = {});
2023-09-01 21:39:24 +00:00
2023-09-04 21:45:01 +00:00
bool extract(const std::filesystem::path& source, const std::filesystem::path& destination) const;
int copy(struct archive *ar, struct archive *aw) const;
2023-08-31 20:06:02 +00:00
private:
Type type;
std::optional<std::string> name;
std::optional<std::string> version;
};