mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
Add (optional) option to include pre-releaes
This commit is contained in:
@@ -47,7 +47,7 @@ struct ThemeEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Result downloadToFile(std::string url, std::string path);
|
Result downloadToFile(std::string url, std::string path);
|
||||||
Result downloadFromRelease(std::string url, std::string asset, std::string path);
|
Result downloadFromRelease(std::string url, std::string asset, std::string path, bool includePrereleases);
|
||||||
|
|
||||||
void displayProgressBar();
|
void displayProgressBar();
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ std::string getLatestCommit(std::string repo, std::string array, std::string ite
|
|||||||
std::vector<ThemeEntry> getThemeList(std::string repo, std::string path);
|
std::vector<ThemeEntry> getThemeList(std::string repo, std::string path);
|
||||||
|
|
||||||
namespace download {
|
namespace download {
|
||||||
void downloadRelease(std::string repo, std::string file, std::string output, std::string message);
|
void downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, std::string message);
|
||||||
void downloadFile(std::string file, std::string output, std::string message);
|
void downloadFile(std::string file, std::string output, std::string message);
|
||||||
void deleteFileList(std::string file, std::string message);
|
void deleteFileList(std::string file, std::string message);
|
||||||
void installFileList(std::string file, std::string message);
|
void installFileList(std::string file, std::string message);
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ Result downloadToFile(std::string url, std::string path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result downloadFromRelease(std::string url, std::string asset, std::string path)
|
Result downloadFromRelease(std::string url, std::string asset, std::string path, bool includePrereleases)
|
||||||
{
|
{
|
||||||
Result ret = 0;
|
Result ret = 0;
|
||||||
void *socubuf = memalign(0x1000, 0x100000);
|
void *socubuf = memalign(0x1000, 0x100000);
|
||||||
@@ -221,7 +221,7 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path)
|
|||||||
std::string repoOwner = result[1].str(), repoName = result[2].str();
|
std::string repoOwner = result[1].str(), repoName = result[2].str();
|
||||||
|
|
||||||
std::stringstream apiurlStream;
|
std::stringstream apiurlStream;
|
||||||
apiurlStream << "https://api.github.com/repos/" << repoOwner << "/" << repoName << "/releases/latest";
|
apiurlStream << "https://api.github.com/repos/" << repoOwner << "/" << repoName << (includePrereleases ? "/releases" : "/releases/latest");
|
||||||
std::string apiurl = apiurlStream.str();
|
std::string apiurl = apiurlStream.str();
|
||||||
|
|
||||||
printf("Downloading latest release from repo:\n%s\nby:\n%s\n", repoName.c_str(), repoOwner.c_str());
|
printf("Downloading latest release from repo:\n%s\nby:\n%s\n", repoName.c_str(), repoOwner.c_str());
|
||||||
@@ -259,6 +259,7 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path)
|
|||||||
printf("Looking for asset with matching name:\n%s\n", asset.c_str());
|
printf("Looking for asset with matching name:\n%s\n", asset.c_str());
|
||||||
std::string assetUrl;
|
std::string assetUrl;
|
||||||
json parsedAPI = json::parse(result_buf);
|
json parsedAPI = json::parse(result_buf);
|
||||||
|
if(includePrereleases) parsedAPI = parsedAPI[0];
|
||||||
if (parsedAPI["assets"].is_array()) {
|
if (parsedAPI["assets"].is_array()) {
|
||||||
for (auto jsonAsset : parsedAPI["assets"]) {
|
for (auto jsonAsset : parsedAPI["assets"]) {
|
||||||
if (jsonAsset.is_object() && jsonAsset["name"].is_string() && jsonAsset["browser_download_url"].is_string()) {
|
if (jsonAsset.is_object() && jsonAsset["name"].is_string() && jsonAsset["browser_download_url"].is_string()) {
|
||||||
@@ -627,12 +628,12 @@ void displayProgressBar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void download::downloadRelease(std::string repo, std::string file, std::string output, std::string message) {
|
void download::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, std::string message) {
|
||||||
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
|
||||||
showProgressBar = true;
|
showProgressBar = true;
|
||||||
progressBarType = 0;
|
progressBarType = 0;
|
||||||
Threads::create((ThreadFunc)displayProgressBar);
|
Threads::create((ThreadFunc)displayProgressBar);
|
||||||
if (downloadFromRelease("https://github.com/" + repo, file, output) != 0) {
|
if (downloadFromRelease("https://github.com/" + repo, file, output, includePrereleases) != 0) {
|
||||||
showProgressBar = false;
|
showProgressBar = false;
|
||||||
downloadFailed();
|
downloadFailed();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void runFunctions(nlohmann::json &json) {
|
|||||||
if(!missing) download::downloadFile(file, output, message);
|
if(!missing) download::downloadFile(file, output, message);
|
||||||
|
|
||||||
} else if(type == "downloadRelease") {
|
} else if(type == "downloadRelease") {
|
||||||
bool missing = false;
|
bool missing = false, includePrereleases = false;
|
||||||
std::string repo, file, output, message;
|
std::string repo, file, output, message;
|
||||||
if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
|
if(json.at(choice).at(i).contains("repo")) repo = json.at(choice).at(i).at("repo");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
@@ -164,8 +164,9 @@ void runFunctions(nlohmann::json &json) {
|
|||||||
else missing = true;
|
else missing = true;
|
||||||
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
if(json.at(choice).at(i).contains("output")) output = json.at(choice).at(i).at("output");
|
||||||
else missing = true;
|
else missing = true;
|
||||||
|
if(json.at(choice).at(i).contains("includePrereleases")) includePrereleases = json.at(choice).at(i).at("includePrereleases");
|
||||||
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
if(json.at(choice).at(i).contains("message")) message = json.at(choice).at(i).at("message");
|
||||||
if(!missing) download::downloadRelease(repo, file, output, message);
|
if(!missing) download::downloadRelease(repo, file, output, includePrereleases, message);
|
||||||
|
|
||||||
} else if(type == "extractFile") {
|
} else if(type == "extractFile") {
|
||||||
bool missing = false;
|
bool missing = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user