Continued replacing size_t with uintmax_t in order to handle file larger than 2GB on 32 bit platforms.

This commit is contained in:
Erik Fleischer 2015-07-03 22:09:50 +02:00
parent 095492942e
commit 23df30d7be
4 changed files with 25 additions and 25 deletions

View File

@ -74,7 +74,7 @@ class Downloader
Timer timer; Timer timer;
Config config; Config config;
ProgressBar* progressbar; ProgressBar* progressbar;
std::deque< std::pair<time_t, size_t> > TimeAndSize; std::deque< std::pair<time_t, uintmax_t> > TimeAndSize;
protected: protected:
private: private:
CURLcode downloadFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string()); CURLcode downloadFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string());
@ -82,7 +82,7 @@ class Downloader
int downloadCovers(const std::string& gamename, const std::string& directory, const std::string& cover_xml_data); int downloadCovers(const std::string& gamename, const std::string& directory, const std::string& cover_xml_data);
int getGameDetails(); int getGameDetails();
void getGameList(); void getGameList();
size_t getResumePosition(); uintmax_t getResumePosition();
CURLcode beginDownload(); CURLcode beginDownload();
std::string getResponse(const std::string& url); std::string getResponse(const std::string& url);
std::string getLocalFileHash(const std::string& filepath, const std::string& gamename = std::string()); std::string getLocalFileHash(const std::string& filepath, const std::string& gamename = std::string());
@ -99,9 +99,9 @@ class Downloader
void saveSerials(const std::string& serials, const std::string& filepath); void saveSerials(const std::string& serials, const std::string& filepath);
static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
static size_t writeMemoryCallback(char *ptr, size_t size, size_t nmemb, void *userp); static uintmax_t writeMemoryCallback(char *ptr, uintmax_t size, uintmax_t nmemb, void *userp);
static size_t writeData(void *ptr, size_t size, size_t nmemb, FILE *stream); static uintmax_t writeData(void *ptr, uintmax_t size, uintmax_t nmemb, FILE *stream);
static size_t readData(void *ptr, size_t size, size_t nmemb, FILE *stream); static uintmax_t readData(void *ptr, uintmax_t size, uintmax_t nmemb, FILE *stream);
API *gogAPI; API *gogAPI;
@ -109,7 +109,7 @@ class Downloader
std::vector<gameDetails> games; std::vector<gameDetails> games;
std::string coverXML; std::string coverXML;
size_t resume_position; uintmax_t resume_position;
int retries; int retries;
std::ofstream report_ofs; std::ofstream report_ofs;
}; };

View File

@ -32,7 +32,7 @@ namespace Util
std::string makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename, std::string subdirectory = "", const unsigned int& platformId = 0, const std::string& dlcname = ""); std::string makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename, std::string subdirectory = "", const unsigned int& platformId = 0, const std::string& dlcname = "");
std::string makeRelativeFilepath(const std::string& path, const std::string& gamename, std::string subdirectory = ""); std::string makeRelativeFilepath(const std::string& path, const std::string& gamename, std::string subdirectory = "");
std::string getFileHash(const std::string& filename, unsigned hash_id); std::string getFileHash(const std::string& filename, unsigned hash_id);
std::string getChunkHash(unsigned char* chunk, size_t chunk_size, unsigned hash_id); std::string getChunkHash(unsigned char* chunk, uintmax_t chunk_size, unsigned hash_id);
int createXML(std::string filepath, size_t chunk_size, std::string xml_dir = std::string()); int createXML(std::string filepath, size_t chunk_size, std::string xml_dir = std::string());
int getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory = std::string()); int getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory = std::string());
int replaceString(std::string& str, const std::string& to_replace, const std::string& replace_with); int replaceString(std::string& str, const std::string& to_replace, const std::string& replace_with);

View File

@ -1158,7 +1158,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
CURLcode res = CURLE_RECV_ERROR; // assume network error CURLcode res = CURLE_RECV_ERROR; // assume network error
bool bResume = false; bool bResume = false;
FILE *outfile; FILE *outfile;
size_t offset=0; uintmax_t offset=0;
// Get directory from filepath // Get directory from filepath
boost::filesystem::path pathname = filepath; boost::filesystem::path pathname = filepath;
@ -1226,7 +1226,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
bResume = true; bResume = true;
fseek(outfile, 0, SEEK_END); fseek(outfile, 0, SEEK_END);
offset = ftell(outfile); offset = ftell(outfile);
curl_easy_setopt(curlhandle, CURLOPT_RESUME_FROM, offset); curl_easy_setopt(curlhandle, CURLOPT_RESUME_FROM_LARGE, offset);
this->resume_position = offset; this->resume_position = offset;
} }
else else
@ -1366,10 +1366,10 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
{ {
int res = 0; int res = 0;
FILE *outfile; FILE *outfile;
size_t offset=0, from_offset, to_offset, filesize; uintmax_t offset=0, from_offset, to_offset, filesize;
std::string filehash; std::string filehash;
int chunks; int chunks;
std::vector<size_t> chunk_from, chunk_to; std::vector<uintmax_t> chunk_from, chunk_to;
std::vector<std::string> chunk_hash; std::vector<std::string> chunk_hash;
bool bParsingFailed = false; bool bParsingFailed = false;
@ -1561,9 +1561,9 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
int iChunksRepaired = 0; 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); uintmax_t chunk_begin = chunk_from.at(i);
size_t chunk_end = chunk_to.at(i); uintmax_t chunk_end = chunk_to.at(i);
size_t size=0, chunk_size = chunk_end - chunk_begin + 1; uintmax_t size=0, chunk_size = chunk_end - chunk_begin + 1;
std::string range = std::to_string(chunk_begin) + "-" + std::to_string(chunk_end); // Download range string for curl std::string range = std::to_string(chunk_begin) + "-" + std::to_string(chunk_end); // Download range string for curl
std::cout << "\033[0K\rChunk " << i << " (" << chunk_size << " bytes): "; std::cout << "\033[0K\rChunk " << i << " (" << chunk_size << " bytes): ";
@ -1799,7 +1799,7 @@ int Downloader::progressCallback(void *clientp, double dltotal, double dlnow, do
// 10 second average download speed // 10 second average download speed
// Don't use static value of 10 seconds because update interval depends on when and how often progress callback is called // Don't use static value of 10 seconds because update interval depends on when and how often progress callback is called
downloader->TimeAndSize.push_back(std::make_pair(time(NULL), static_cast<size_t>(dlnow))); downloader->TimeAndSize.push_back(std::make_pair(time(NULL), static_cast<uintmax_t>(dlnow)));
if (downloader->TimeAndSize.size() > 100) // 100 * 100ms = 10s if (downloader->TimeAndSize.size() > 100) // 100 * 100ms = 10s
{ {
downloader->TimeAndSize.pop_front(); downloader->TimeAndSize.pop_front();
@ -1870,24 +1870,24 @@ int Downloader::progressCallback(void *clientp, double dltotal, double dlnow, do
return 0; return 0;
} }
size_t Downloader::writeMemoryCallback(char *ptr, size_t size, size_t nmemb, void *userp) { uintmax_t Downloader::writeMemoryCallback(char *ptr, uintmax_t size, uintmax_t nmemb, void *userp) {
std::ostringstream *stream = (std::ostringstream*)userp; std::ostringstream *stream = (std::ostringstream*)userp;
size_t count = size * nmemb; uintmax_t count = size * nmemb;
stream->write(ptr, count); stream->write(ptr, count);
return count; return count;
} }
size_t Downloader::writeData(void *ptr, size_t size, size_t nmemb, FILE *stream) uintmax_t Downloader::writeData(void *ptr, uintmax_t size, uintmax_t nmemb, FILE *stream)
{ {
return fwrite(ptr, size, nmemb, stream); return fwrite(ptr, size, nmemb, stream);
} }
size_t Downloader::readData(void *ptr, size_t size, size_t nmemb, FILE *stream) uintmax_t Downloader::readData(void *ptr, uintmax_t size, uintmax_t nmemb, FILE *stream)
{ {
return fread(ptr, size, nmemb, stream); return fread(ptr, size, nmemb, stream);
} }
size_t Downloader::getResumePosition() uintmax_t Downloader::getResumePosition()
{ {
return this->resume_position; return this->resume_position;
} }

View File

@ -71,7 +71,7 @@ std::string Util::getFileHash(const std::string& filename, unsigned hash_id)
return result; return result;
} }
std::string Util::getChunkHash(unsigned char *chunk, size_t chunk_size, unsigned hash_id) std::string Util::getChunkHash(unsigned char *chunk, uintmax_t chunk_size, unsigned hash_id)
{ {
unsigned char digest[rhash_get_digest_size(hash_id)]; unsigned char digest[rhash_get_digest_size(hash_id)];
char result[rhash_get_hash_length(hash_id)]; char result[rhash_get_hash_length(hash_id)];
@ -87,12 +87,12 @@ std::string Util::getChunkHash(unsigned char *chunk, size_t chunk_size, unsigned
} }
// Create GOG XML // Create GOG XML
int Util::createXML(std::string filepath, size_t chunk_size, std::string xml_dir) int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_dir)
{ {
int res = 0; int res = 0;
FILE *infile; FILE *infile;
FILE *xmlfile; FILE *xmlfile;
size_t filesize, size; uintmax_t filesize, size;
int chunks, i; int chunks, i;
if (xml_dir.empty()) if (xml_dir.empty())
@ -158,11 +158,11 @@ int Util::createXML(std::string filepath, size_t chunk_size, std::string xml_dir
char rhash_result[rhash_get_hash_length(RHASH_MD5)]; char rhash_result[rhash_get_hash_length(RHASH_MD5)];
for (i = 0; i < chunks; i++) { for (i = 0; i < chunks; i++) {
size_t range_begin = i*chunk_size; uintmax_t range_begin = i*chunk_size;
fseek(infile, range_begin, SEEK_SET); fseek(infile, range_begin, SEEK_SET);
if ((i == chunks-1) && (remaining != 0)) if ((i == chunks-1) && (remaining != 0))
chunk_size = remaining; chunk_size = remaining;
size_t range_end = range_begin + chunk_size - 1; uintmax_t range_end = range_begin + chunk_size - 1;
unsigned char *chunk = (unsigned char *) malloc(chunk_size * sizeof(unsigned char *)); unsigned char *chunk = (unsigned char *) malloc(chunk_size * sizeof(unsigned char *));
if (chunk == NULL) if (chunk == NULL)
{ {