Mercurial > hg > openttd
changeset 17454:462b0ebbbcfd draft
(svn r22208) -Fix [FS#4543]: When downloading a file via HTTP failed mid-way and OpenTTD fell back to the old system the partial downloaded amount would be counted twice
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 06 Mar 2011 10:11:59 +0000 |
parents | 5fe3ac651010 |
children | 5f4a2ff8dec6 |
files | src/network/network_content.cpp src/network/network_content.h src/network/network_content_gui.cpp |
diffstat | 3 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -453,7 +453,7 @@ return false; } - this->OnDownloadProgress(this->curInfo, (uint)toRead); + this->OnDownloadProgress(this->curInfo, (int)toRead); if (toRead == 0) this->AfterDownload(); } @@ -526,6 +526,10 @@ this->http_response_index = -2; if (this->curFile != NULL) { + /* Revert the download progress when we are going for the old system. */ + long size = ftell(this->curFile); + if (size > 0) this->OnDownloadProgress(this->curInfo, (int)-size); + fclose(this->curFile); this->curFile = NULL; } @@ -559,7 +563,7 @@ this->OnFailure(); } else { /* Just received the data. */ - this->OnDownloadProgress(this->curInfo, (uint)length); + this->OnDownloadProgress(this->curInfo, (int)length); } /* Nothing more to do now. */ return; @@ -1023,7 +1027,7 @@ } } -void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, uint bytes) +void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, int bytes) { for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) { ContentCallback *cb = *iter;
--- a/src/network/network_content.h +++ b/src/network/network_content.h @@ -49,7 +49,7 @@ * @param ci the content info of the file * @param bytes the number of bytes downloaded since the previous call */ - virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes) {} + virtual void OnDownloadProgress(const ContentInfo *ci, int bytes) {} /** * We have finished downloading a file @@ -89,7 +89,7 @@ void OnConnect(bool success); void OnDisconnect(); void OnReceiveContentInfo(const ContentInfo *ci); - void OnDownloadProgress(const ContentInfo *ci, uint bytes); + void OnDownloadProgress(const ContentInfo *ci, int bytes); void OnDownloadComplete(ContentID cid); void OnFailure();
--- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -175,7 +175,7 @@ } } - virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes) + virtual void OnDownloadProgress(const ContentInfo *ci, int bytes) { if (ci->id != this->cur_id) { strecpy(this->name, ci->filename, lastof(this->name));