mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Added --report option
This commit is contained in:
parent
13d3e5e25b
commit
9dda0fccdc
@ -35,6 +35,7 @@ class Config
|
||||
bool bDuplicateHandler;
|
||||
bool bSaveConfig;
|
||||
bool bResetConfig;
|
||||
bool bReport;
|
||||
std::string sGameRegex;
|
||||
std::string sDirectory;
|
||||
std::string sXMLFile;
|
||||
|
@ -77,6 +77,7 @@ class Downloader
|
||||
std::string coverXML;
|
||||
|
||||
size_t resume_position;
|
||||
std::vector< std::string > report;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADER_H
|
||||
|
1
main.cpp
1
main.cpp
@ -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")
|
||||
("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")
|
||||
("report", bpo::value<bool>(&config.bReport)->zero_tokens()->default_value(false), "Save report of downloaded/repaired files")
|
||||
;
|
||||
// Commandline options (config file)
|
||||
options_cli_cfg.add_options()
|
||||
|
@ -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<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;
|
||||
}
|
||||
|
||||
@ -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; i<chunks; 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
|
||||
this->beginDownload(); //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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user