-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
256 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
constexpr const char* REPOS_URL = "https://github.com/ScrappySM/CarbonLauncher/raw/refs/heads/main/repos.json"; | ||
|
||
namespace Carbon { | ||
struct Mod { | ||
// Name of the mode | ||
std::string name; | ||
|
||
// A list of all the authors of the mod | ||
std::vector<std::string> authors; | ||
|
||
// A short description of the mod | ||
std::string description; | ||
|
||
// The link to the GitHub repo of the mod | ||
std::string repo; | ||
|
||
// A list of all the dependencies of the mod | ||
std::vector<std::string> dependencies; | ||
|
||
// The git repo tag to download | ||
std::string tag; | ||
|
||
// A list of all the files to download from the GitHub releases | ||
std::vector<std::string> files; | ||
|
||
// The supported game version | ||
std::string supported; | ||
|
||
bool installed = false; | ||
}; | ||
|
||
struct Repo { | ||
// The name of the repository (e.g. ScrappySM, Scrap-Mods) | ||
std::string name; | ||
|
||
// The link to the repositories website | ||
std::string link; | ||
|
||
// A list of all the mods | ||
std::vector<Mod> mods; | ||
}; | ||
|
||
|
||
class RepoManager { | ||
public: | ||
RepoManager(); | ||
~RepoManager(); | ||
|
||
std::vector<Repo> URLToRepos(const std::string& url); | ||
std::vector<Repo>& GetRepos() { return repos; } | ||
|
||
private: | ||
Repo JSONToRepo(nlohmann::json json); | ||
std::vector<Repo> repos = {}; | ||
}; | ||
}; // namespace Carbon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "repomanager.h" | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <spdlog/spdlog.h> | ||
#include <cpr/cpr.h> | ||
|
||
using namespace Carbon; | ||
|
||
Repo RepoManager::JSONToRepo(nlohmann::json json) { | ||
Repo repo; | ||
|
||
repo.name = json["name"]; | ||
repo.link = json["link"]; | ||
|
||
for (const auto& mod : json["mods"]) { | ||
Mod m{ | ||
.name = mod["name"], | ||
.description = mod["description"], | ||
.repo = mod["repo"], | ||
.tag = mod["tag"], | ||
.supported = mod["supported"] | ||
}; | ||
|
||
for (const auto& author : mod["authors"]) { | ||
m.authors.push_back(author); | ||
} | ||
|
||
for (const auto& dependency : mod["dependencies"]) { | ||
m.dependencies.push_back(dependency); | ||
} | ||
|
||
for (const auto& file : mod["files"]) { | ||
std::string sFile = file; | ||
spdlog::info("File: {}", sFile); | ||
m.files.push_back(sFile); | ||
} | ||
|
||
repo.mods.push_back(m); | ||
} | ||
|
||
return repo; | ||
} | ||
|
||
std::vector<Repo> RepoManager::URLToRepos(const std::string& url) { | ||
cpr::Response response = cpr::Get(cpr::Url{ url }); | ||
|
||
nlohmann::json json = nlohmann::json::parse(response.text); | ||
|
||
std::vector<Repo> repos; | ||
for (const auto& repo : json["repositories"]) { | ||
repos.push_back(JSONToRepo(repo)); | ||
} | ||
|
||
return repos; | ||
} | ||
|
||
RepoManager::RepoManager() { | ||
this->repos = URLToRepos(REPOS_URL); | ||
|
||
for (auto& repo : this->repos) { | ||
spdlog::info("Repo: {}", repo.name); | ||
for (auto& mod : repo.mods) { | ||
spdlog::info("Mod: {}", mod.name); | ||
} | ||
} | ||
} | ||
|
||
RepoManager::~RepoManager() { | ||
this->repos.clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters