Added --report option

This commit is contained in:
Sude 2014-02-13 10:05:16 +02:00
parent 13d3e5e25b
commit 9dda0fccdc
4 changed files with 38 additions and 0 deletions

View File

@ -35,6 +35,7 @@ class Config
bool bDuplicateHandler; bool bDuplicateHandler;
bool bSaveConfig; bool bSaveConfig;
bool bResetConfig; bool bResetConfig;
bool bReport;
std::string sGameRegex; std::string sGameRegex;
std::string sDirectory; std::string sDirectory;
std::string sXMLFile; std::string sXMLFile;

View File

@ -77,6 +77,7 @@ class Downloader
std::string coverXML; std::string coverXML;
size_t resume_position; size_t resume_position;
std::vector< std::string > report;
}; };
#endif // DOWNLOADER_H #endif // DOWNLOADER_H

View File

@ -127,6 +127,7 @@ int main(int argc, char *argv[])
("status", bpo::value<bool>(&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") ("status", bpo::value<bool>(&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<bool>(&config.bSaveConfig)->zero_tokens()->default_value(false), "Create config file with current settings") ("save-config", bpo::value<bool>(&config.bSaveConfig)->zero_tokens()->default_value(false), "Create config file with current settings")
("reset-config", bpo::value<bool>(&config.bResetConfig)->zero_tokens()->default_value(false), "Reset config settings to default") ("reset-config", bpo::value<bool>(&config.bResetConfig)->zero_tokens()->default_value(false), "Reset config settings to default")
("report", bpo::value<bool>(&config.bReport)->zero_tokens()->default_value(false), "Save report of downloaded/repaired files")
; ;
// Commandline options (config file) // Commandline options (config file)
options_cli_cfg.add_options() options_cli_cfg.add_options()

View File

@ -32,6 +32,23 @@ Downloader::Downloader(Config &conf)
Downloader::~Downloader() 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 progressbar;
delete gogAPI; delete gogAPI;
curl_easy_cleanup(curlhandle); 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; std::cout << "Failed to delete " << path << std::endl;
} }
if (config.bReport)
{
std::string status = static_cast<std::string>(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; return res;
} }
@ -929,6 +955,7 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
} }
// Check all chunks // Check all chunks
int iChunksRepaired = 0;
for (int i=0; i<chunks; i++) for (int i=0; i<chunks; i++)
{ {
size_t chunk_begin = chunk_from.at(i); size_t chunk_begin = chunk_from.at(i);
@ -963,6 +990,8 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
curl_easy_setopt(curlhandle, CURLOPT_RANGE, range.c_str()); //download range curl_easy_setopt(curlhandle, CURLOPT_RANGE, range.c_str()); //download range
this->beginDownload(); //begin chunk download this->beginDownload(); //begin chunk download
std::cout << std::endl; std::cout << std::endl;
if (config.bReport)
iChunksRepaired++;
i--; //verify downloaded chunk i--; //verify downloaded chunk
} }
else else
@ -975,6 +1004,12 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
std::cout << std::endl; std::cout << std::endl;
fclose(outfile); 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; return res;
} }