diff --git a/include/downloader.h b/include/downloader.h index 3f676da..e4287fc 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -74,7 +74,7 @@ class Downloader Timer timer; Config config; ProgressBar* progressbar; - std::deque< std::pair > TimeAndSize; + std::deque< std::pair > TimeAndSize; protected: private: 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 getGameDetails(); void getGameList(); - size_t getResumePosition(); + uintmax_t getResumePosition(); CURLcode beginDownload(); std::string getResponse(const std::string& url); 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); 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 size_t writeData(void *ptr, size_t size, size_t nmemb, FILE *stream); - static size_t readData(void *ptr, size_t size, size_t nmemb, FILE *stream); + static uintmax_t writeMemoryCallback(char *ptr, uintmax_t size, uintmax_t nmemb, void *userp); + static uintmax_t writeData(void *ptr, uintmax_t size, uintmax_t nmemb, FILE *stream); + static uintmax_t readData(void *ptr, uintmax_t size, uintmax_t nmemb, FILE *stream); API *gogAPI; @@ -109,7 +109,7 @@ class Downloader std::vector games; std::string coverXML; - size_t resume_position; + uintmax_t resume_position; int retries; std::ofstream report_ofs; }; diff --git a/include/util.h b/include/util.h index 25e9f78..f6904dc 100644 --- a/include/util.h +++ b/include/util.h @@ -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 makeRelativeFilepath(const std::string& path, const std::string& gamename, std::string subdirectory = ""); 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 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); diff --git a/src/downloader.cpp b/src/downloader.cpp index 684c1be..f784886 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -1158,7 +1158,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil CURLcode res = CURLE_RECV_ERROR; // assume network error bool bResume = false; FILE *outfile; - size_t offset=0; + uintmax_t offset=0; // Get directory from filepath boost::filesystem::path pathname = filepath; @@ -1226,7 +1226,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil bResume = true; fseek(outfile, 0, SEEK_END); offset = ftell(outfile); - curl_easy_setopt(curlhandle, CURLOPT_RESUME_FROM, offset); + curl_easy_setopt(curlhandle, CURLOPT_RESUME_FROM_LARGE, offset); this->resume_position = offset; } else @@ -1366,10 +1366,10 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, { int res = 0; FILE *outfile; - size_t offset=0, from_offset, to_offset, filesize; + uintmax_t offset=0, from_offset, to_offset, filesize; std::string filehash; int chunks; - std::vector chunk_from, chunk_to; + std::vector chunk_from, chunk_to; std::vector chunk_hash; bool bParsingFailed = false; @@ -1561,9 +1561,9 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, int iChunksRepaired = 0; for (int i=0; iTimeAndSize.push_back(std::make_pair(time(NULL), static_cast(dlnow))); + downloader->TimeAndSize.push_back(std::make_pair(time(NULL), static_cast(dlnow))); if (downloader->TimeAndSize.size() > 100) // 100 * 100ms = 10s { downloader->TimeAndSize.pop_front(); @@ -1870,24 +1870,24 @@ int Downloader::progressCallback(void *clientp, double dltotal, double dlnow, do 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; - size_t count = size * nmemb; + uintmax_t count = size * nmemb; stream->write(ptr, 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); } -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); } -size_t Downloader::getResumePosition() +uintmax_t Downloader::getResumePosition() { return this->resume_position; } diff --git a/src/util.cpp b/src/util.cpp index 2d57807..40e5208 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -71,7 +71,7 @@ std::string Util::getFileHash(const std::string& filename, unsigned hash_id) 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)]; 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 -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; FILE *infile; FILE *xmlfile; - size_t filesize, size; + uintmax_t filesize, size; int chunks, i; 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)]; 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); if ((i == chunks-1) && (remaining != 0)) 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 *)); if (chunk == NULL) {