Add %ARCHIVE_DEFAULT%.

This commit is contained in:
StackZ
2020-07-01 00:27:04 +02:00
parent ba57bb743b
commit 54c426032b
7 changed files with 231 additions and 157 deletions
+10
View File
@@ -35,6 +35,7 @@ void Config::addMissingThings() {
if (this->json["VERSION"] < 2) {
this->setString("3DSX_PATH", _3DSX_PATH);
this->setString("NDS_PATH", _NDS_PATH);
this->setString("ARCHIVE_PATH", ARCHIVES_DEFAULT);
}
}
@@ -74,6 +75,7 @@ void Config::initialize() {
this->setBool("SHOW_SPEED", false);
this->setString("3DSX_PATH", _3DSX_PATH);
this->setString("NDS_PATH", _NDS_PATH);
this->setString("ARCHIVE_PATH", ARCHIVES_DEFAULT);
this->setInt("VERSION", this->configVersion);
// Write to file.
@@ -282,6 +284,12 @@ Config::Config() {
this->ndspath(this->getString("NDS_PATH"));
}
if (!this->json.contains("ARCHIVE_PATH")) {
this->archivepath(ARCHIVES_DEFAULT);
} else {
this->archivepath(this->getString("ARCHIVE_PATH"));
}
this->changesMade = false; // No changes made yet.
}
@@ -321,6 +329,8 @@ void Config::save() {
this->setBool("SHOW_SPEED", this->showSpeed());
this->setString("3DSX_PATH", this->_3dsxpath());
this->setString("NDS_PATH", this->ndspath());
this->setString("ARCHIVE_PATH", this->archivepath());
// Write changes to file.
const std::string dump = this->json.dump(1, '\t');
fwrite(dump.c_str(), 1, this->json.dump(1, '\t').size(), file);
+12 -3
View File
@@ -71,6 +71,7 @@ Result ScriptHelper::downloadRelease(std::string repo, std::string file, std::st
std::string out;
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxpath().c_str());
out = std::regex_replace(out, std::regex("%NDS%"), config->ndspath().c_str());
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
Result ret = NONE;
if (downloadFromRelease("https://github.com/" + repo, file, out, message, includePrereleases, showVersions) != 0) {
@@ -89,6 +90,7 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str
std::string out;
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxpath().c_str());
out = std::regex_replace(out, std::regex("%NDS%"), config->ndspath().c_str());
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
Result ret = NONE;
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
@@ -108,13 +110,16 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str
// Remove a File.
Result ScriptHelper::removeFile(std::string file, std::string message) {
std::string out;
out = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
Result ret = NONE;
if (access(file.c_str(), F_OK) != 0 ) {
if (access(out.c_str(), F_OK) != 0 ) {
return DELETE_ERROR;
}
Msg::DisplayMsg(message);
deleteFile(file.c_str());
deleteFile(out.c_str());
return ret;
}
@@ -130,12 +135,16 @@ void ScriptHelper::installFile(std::string file, bool updatingSelf, std::string
// Extract Files.
void ScriptHelper::extractFile(std::string file, std::string input, std::string output, std::string message) {
std::string out, in;
in = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
out = std::regex_replace(output, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
filesExtracted = 0;
progressbarType = ProgressBar::Extracting;
Threads::create((ThreadFunc)displayProgressBar);
extractArchive(file, input, output);
extractArchive(in, input, out);
showProgressBar = false;
}