diff --git a/include/config.h b/include/config.h index 40e3aaa..77d6efc 100644 --- a/include/config.h +++ b/include/config.h @@ -35,6 +35,7 @@ class Config bool bDuplicateHandler; bool bSaveConfig; bool bResetConfig; + bool bReport; std::string sGameRegex; std::string sDirectory; std::string sXMLFile; diff --git a/include/downloader.h b/include/downloader.h index a5883eb..46210f0 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -77,6 +77,7 @@ class Downloader std::string coverXML; size_t resume_position; + std::vector< std::string > report; }; #endif // DOWNLOADER_H diff --git a/main.cpp b/main.cpp index 0d4a694..1f0a361 100644 --- a/main.cpp +++ b/main.cpp @@ -127,6 +127,7 @@ int main(int argc, char *argv[]) ("status", bpo::value(&config.bCheckStatus)->zero_tokens()->default_value(false), "Show status of files\n\nOutput format:\nstatuscode gamename filename filesize filehash\n\nStatus codes:\nOK - File is OK\nND - File is not downloaded\nMD5 - MD5 mismatch, different version") ("save-config", bpo::value(&config.bSaveConfig)->zero_tokens()->default_value(false), "Create config file with current settings") ("reset-config", bpo::value(&config.bResetConfig)->zero_tokens()->default_value(false), "Reset config settings to default") + ("report", bpo::value(&config.bReport)->zero_tokens()->default_value(false), "Save report of downloaded/repaired files") ; // Commandline options (config file) options_cli_cfg.add_options() diff --git a/src/downloader.cpp b/src/downloader.cpp index 15c0807..a7b8682 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -32,6 +32,23 @@ Downloader::Downloader(Config &conf) Downloader::~Downloader() { + if (config.bReport && !this->report.empty()) + { + std::ofstream ofs("lgogdownloader-report.log"); + if (ofs) + { + std::cout << "Saving report: lgogdownloader-report.log" << std::endl; + for (unsigned int i = 0; i < this->report.size(); ++i) + { + ofs << this->report[i] << std::endl; + } + ofs.close(); + } + else + { + std::cout << "Failed to save report" << std::endl; + } + } delete progressbar; delete gogAPI; curl_easy_cleanup(curlhandle); @@ -760,6 +777,15 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil std::cout << "Failed to delete " << path << std::endl; } + if (config.bReport) + { + std::string status = static_cast(curl_easy_strerror(res)); + if (bResume && res == CURLE_RANGE_ERROR) // CURLE_RANGE_ERROR on resume attempts is not an error that user needs to know about + status = "No error"; + std::string report_line = "Downloaded [" + status + "] " + filepath; + this->report.push_back(report_line); + } + return res; } @@ -929,6 +955,7 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, } // Check all chunks + int iChunksRepaired = 0; for (int i=0; ibeginDownload(); //begin chunk download std::cout << std::endl; + if (config.bReport) + iChunksRepaired++; i--; //verify downloaded chunk } else @@ -975,6 +1004,12 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, std::cout << std::endl; fclose(outfile); + if (config.bReport) + { + std::string report_line = "Repaired [" + std::to_string(iChunksRepaired) + "/" + std::to_string(chunks) + "] " + filepath; + this->report.push_back(report_line); + } + return res; }