mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
I do not like if(..).
This commit is contained in:
@@ -17,8 +17,7 @@ Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result deletePrevious(u64 titleid, FS_MediaType media)
|
||||
{
|
||||
Result deletePrevious(u64 titleid, FS_MediaType media) {
|
||||
Result ret = 0;
|
||||
|
||||
u32 titles_amount = 0;
|
||||
@@ -65,8 +64,7 @@ FS_MediaType getTitleDestination(u64 titleId) {
|
||||
// Variables.
|
||||
u64 installSize = 0, installOffset = 0;
|
||||
|
||||
Result installCia(const char * ciaPath, bool updatingSelf)
|
||||
{
|
||||
Result installCia(const char * ciaPath, bool updatingSelf) {
|
||||
u32 bytes_read = 0, bytes_written;
|
||||
installSize = 0, installOffset = 0; u64 size = 0;
|
||||
Handle ciaHandle, fileHandle;
|
||||
@@ -124,6 +122,7 @@ Result installCia(const char * ciaPath, bool updatingSelf)
|
||||
printf("Error in:\nAM_FinishCiaInstall\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = FSFILE_Close(fileHandle);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nFSFILE_Close\n");
|
||||
@@ -131,8 +130,8 @@ Result installCia(const char * ciaPath, bool updatingSelf)
|
||||
}
|
||||
|
||||
if (updatingSelf) {
|
||||
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD)))
|
||||
return ret;
|
||||
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD))) return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -53,15 +53,15 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
||||
a = archive_read_new();
|
||||
archive_read_support_format_all(a);
|
||||
|
||||
if(archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
|
||||
if (archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
|
||||
return EXTRACT_ERROR_OPENFILE;
|
||||
}
|
||||
|
||||
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||
if(archive_entry_size(entry) > 0) { // Ignore folders
|
||||
if (archive_entry_size(entry) > 0) { // Ignore folders
|
||||
std::smatch match;
|
||||
std::string entryName(archive_entry_pathname(entry));
|
||||
if(std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||
extractingFile = outputPath + match.suffix().str();
|
||||
|
||||
// make directories
|
||||
@@ -75,12 +75,12 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
||||
extractSize = sizeLeft;
|
||||
writeOffset = 0;
|
||||
FILE *file = fopen(extractingFile.c_str(), "wb");
|
||||
if(!file) {
|
||||
if (!file) {
|
||||
return EXTRACT_ERROR_WRITEFILE;
|
||||
}
|
||||
|
||||
u8 *buf = new u8[0x30000];
|
||||
if(buf == nullptr) {
|
||||
if (buf == nullptr) {
|
||||
return EXTRACT_ERROR_ALLOC;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
||||
sizeLeft -= size;
|
||||
writeOffset += size;
|
||||
}
|
||||
|
||||
filesExtracted++;
|
||||
fclose(file);
|
||||
delete[] buf;
|
||||
|
||||
@@ -45,22 +45,22 @@ extern void downloadFailed();
|
||||
|
||||
// Get String of the Script.
|
||||
std::string ScriptHelper::getString(nlohmann::json json, const std::string &key, const std::string &key2) {
|
||||
if(!json.contains(key)) return "MISSING: " + key;
|
||||
if(!json.at(key).is_object()) return "NOT OBJECT: " + key;
|
||||
if (!json.contains(key)) return "MISSING: " + key;
|
||||
if (!json.at(key).is_object()) return "NOT OBJECT: " + key;
|
||||
|
||||
if(!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2;
|
||||
if(!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2;
|
||||
if (!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2;
|
||||
if (!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2;
|
||||
|
||||
return json.at(key).at(key2).get_ref<const std::string&>();
|
||||
}
|
||||
|
||||
// Get int of the Script.
|
||||
int ScriptHelper::getNum(nlohmann::json json, const std::string &key, const std::string &key2) {
|
||||
if(!json.contains(key)) return 0;
|
||||
if(!json.at(key).is_object()) return 0;
|
||||
if (!json.contains(key)) return 0;
|
||||
if (!json.at(key).is_object()) return 0;
|
||||
|
||||
if(!json.at(key).contains(key2)) return 0;
|
||||
if(!json.at(key).at(key2).is_number()) return 0;
|
||||
if (!json.at(key).contains(key2)) return 0;
|
||||
if (!json.at(key).at(key2).is_number()) return 0;
|
||||
return json.at(key).at(key2).get_ref<const int64_t&>();
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ Result ScriptHelper::downloadRelease(std::string repo, std::string file, std::st
|
||||
ret = FAILED_DOWNLOAD;
|
||||
return ret;
|
||||
}
|
||||
|
||||
showProgressBar = false;
|
||||
return ret;
|
||||
}
|
||||
@@ -90,6 +91,7 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str
|
||||
ret = FAILED_DOWNLOAD;
|
||||
return ret;
|
||||
}
|
||||
|
||||
showProgressBar = false;
|
||||
return ret;
|
||||
}
|
||||
@@ -97,9 +99,10 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str
|
||||
// Remove a File.
|
||||
Result ScriptHelper::removeFile(std::string file, std::string message) {
|
||||
Result ret = NONE;
|
||||
if(access(file.c_str(), F_OK) != 0 ) {
|
||||
if (access(file.c_str(), F_OK) != 0 ) {
|
||||
return DELETE_ERROR;
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
deleteFile(file.c_str());
|
||||
return ret;
|
||||
@@ -144,10 +147,11 @@ void ScriptHelper::displayTimeMsg(std::string message, int seconds) {
|
||||
|
||||
bool ScriptHelper::checkIfValid(std::string scriptFile, int mode) {
|
||||
FILE* file = fopen(scriptFile.c_str(), "rt");
|
||||
if(!file) {
|
||||
if (!file) {
|
||||
printf("File not found\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
|
||||
@@ -181,28 +185,32 @@ Result ScriptHelper::prompt(std::string message) {
|
||||
if (!Msg::promptMsg(message)) {
|
||||
ret = SCRIPT_CANCELED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result ScriptHelper::copyFile(std::string source, std::string destination, std::string message) {
|
||||
Result ret = NONE;
|
||||
if(access(source.c_str(), F_OK) != 0 ) {
|
||||
if (access(source.c_str(), F_OK) != 0 ) {
|
||||
return COPY_ERROR;
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
// If destination does not exist, create dirs.
|
||||
if(access(destination.c_str(), F_OK) != 0 ) {
|
||||
if (access(destination.c_str(), F_OK) != 0 ) {
|
||||
makeDirs(destination.c_str());
|
||||
}
|
||||
|
||||
fcopy(source.c_str(), destination.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result ScriptHelper::renameFile(std::string oldName, std::string newName, std::string message) {
|
||||
Result ret = NONE;
|
||||
if(access(oldName.c_str(), F_OK) != 0 ) {
|
||||
if (access(oldName.c_str(), F_OK) != 0 ) {
|
||||
return MOVE_ERROR;
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
// TODO: Kinda avoid that?
|
||||
makeDirs(newName.c_str());
|
||||
|
||||
Reference in New Issue
Block a user