mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Save to log after each file instead of waiting until destructor is called
This commit is contained in:
parent
899bc566a2
commit
cfe4311209
@ -12,6 +12,7 @@
|
|||||||
#include "progressbar.h"
|
#include "progressbar.h"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
@ -77,7 +78,7 @@ class Downloader
|
|||||||
std::string coverXML;
|
std::string coverXML;
|
||||||
|
|
||||||
size_t resume_position;
|
size_t resume_position;
|
||||||
std::vector< std::string > report;
|
std::ofstream report_ofs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DOWNLOADER_H
|
#endif // DOWNLOADER_H
|
||||||
|
@ -32,23 +32,9 @@ Downloader::Downloader(Config &conf)
|
|||||||
|
|
||||||
Downloader::~Downloader()
|
Downloader::~Downloader()
|
||||||
{
|
{
|
||||||
if (config.bReport && !this->report.empty())
|
if (config.bReport)
|
||||||
{
|
if (this->report_ofs)
|
||||||
std::ofstream ofs("lgogdownloader-report.log");
|
this->report_ofs.close();
|
||||||
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);
|
||||||
@ -100,6 +86,16 @@ int Downloader::init()
|
|||||||
if (!config.bUpdateCheck) // updateCheck() calls getGameList() if needed
|
if (!config.bUpdateCheck) // updateCheck() calls getGameList() if needed
|
||||||
this->getGameList();
|
this->getGameList();
|
||||||
|
|
||||||
|
if (config.bReport && (config.bDownload || config.bRepair))
|
||||||
|
{
|
||||||
|
this->report_ofs.open("lgogdownloader-report.log");
|
||||||
|
if (!this->report_ofs)
|
||||||
|
{
|
||||||
|
std::cout << "Failed to create lgogdownloader-report.log" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +779,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
|
|||||||
if (bResume && res == CURLE_RANGE_ERROR) // CURLE_RANGE_ERROR on resume attempts is not an error that user needs to know about
|
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";
|
status = "No error";
|
||||||
std::string report_line = "Downloaded [" + status + "] " + filepath;
|
std::string report_line = "Downloaded [" + status + "] " + filepath;
|
||||||
this->report.push_back(report_line);
|
this->report_ofs << report_line << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -1007,7 +1003,7 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
|
|||||||
if (config.bReport)
|
if (config.bReport)
|
||||||
{
|
{
|
||||||
std::string report_line = "Repaired [" + std::to_string(iChunksRepaired) + "/" + std::to_string(chunks) + "] " + filepath;
|
std::string report_line = "Repaired [" + std::to_string(iChunksRepaired) + "/" + std::to_string(chunks) + "] " + filepath;
|
||||||
this->report.push_back(report_line);
|
this->report_ofs << report_line << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user