From d8b8d6da964fbe33db6c92d90d23d4ad1c62549d Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 23 Sep 2016 22:16:13 +0100 Subject: [PATCH 1/2] Exit with non-zero status when at least one --download-file fails --- include/downloader.h | 2 +- main.cpp | 7 +++++-- src/downloader.cpp | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/downloader.h b/include/downloader.h index c9b5ee2..2edb8c4 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -72,7 +72,7 @@ class Downloader void checkOrphans(); void checkStatus(); void updateCache(); - void downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath); + int downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath); void showWishlist(); CURL* curlhandle; Timer timer; diff --git a/main.cpp b/main.cpp index 0e5e4bc..360ec7f 100644 --- a/main.cpp +++ b/main.cpp @@ -550,6 +550,9 @@ int main(int argc, char *argv[]) return 1; } } + + int res = 0; + if (config.bShowWishlist) downloader.showWishlist(); else if (config.bUpdateCache) @@ -560,7 +563,7 @@ int main(int argc, char *argv[]) { for (std::vector::iterator it = vFileIdStrings.begin(); it != vFileIdStrings.end(); it++) { - downloader.downloadFileWithId(*it, config.sOutputFilename); + res |= downloader.downloadFileWithId(*it, config.sOutputFilename) ? 1 : 0; } } else if (config.bRepair) // Repair file @@ -587,5 +590,5 @@ int main(int argc, char *argv[]) if (!config.sOrphanRegex.empty() && config.bDownload) downloader.checkOrphans(); - return 0; + return res; } diff --git a/src/downloader.cpp b/src/downloader.cpp index b239f65..0e97ba0 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -2790,8 +2790,9 @@ void Downloader::saveChangelog(const std::string& changelog, const std::string& return; } -void Downloader::downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath) +int Downloader::downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath) { + int res = 1; size_t pos = fileid_string.find("/"); if (pos == std::string::npos) { @@ -2825,7 +2826,7 @@ void Downloader::downloadFileWithId(const std::string& fileid_string, const std: else filepath = output_filepath; std::cout << "Downloading: " << filepath << std::endl; - this->downloadFile(url, filepath, std::string(), gamename); + res = this->downloadFile(url, filepath, std::string(), gamename); std::cout << std::endl; } else @@ -2835,7 +2836,7 @@ void Downloader::downloadFileWithId(const std::string& fileid_string, const std: } } - return; + return res; } void Downloader::showWishlist() From 1388c00a4e789d6b0cb0a7cc7e3f7d3e1aaa1e3a Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 23 Sep 2016 22:20:37 +0100 Subject: [PATCH 2/2] Exit with non-zero status when --list or --list-details fails --- include/downloader.h | 2 +- main.cpp | 2 +- src/downloader.cpp | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/downloader.h b/include/downloader.h index 2edb8c4..bede8fd 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -65,7 +65,7 @@ class Downloader virtual ~Downloader(); int init(); int login(); - void listGames(); + int listGames(); void updateCheck(); void repair(); void download(); diff --git a/main.cpp b/main.cpp index 360ec7f..4380152 100644 --- a/main.cpp +++ b/main.cpp @@ -571,7 +571,7 @@ int main(int argc, char *argv[]) else if (config.bDownload) // Download games downloader.download(); else if (config.bListDetails || config.bList) // Detailed list of games/extras - downloader.listGames(); + res = downloader.listGames(); else if (!config.sOrphanRegex.empty()) // Check for orphaned files if regex for orphans is set downloader.checkOrphans(); else if (config.bCheckStatus) diff --git a/src/downloader.cpp b/src/downloader.cpp index 0e97ba0..f7eeb04 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -495,12 +495,15 @@ int Downloader::getGameDetails() return 0; } -void Downloader::listGames() +int Downloader::listGames() { if (config.bListDetails) // Detailed list { - if (this->games.empty()) - this->getGameDetails(); + if (this->games.empty()) { + int res = this->getGameDetails(); + if (res > 0) + return res; + } for (unsigned int i = 0; i < games.size(); ++i) { @@ -696,6 +699,7 @@ void Downloader::listGames() } } + return 0; } void Downloader::repair()