mirror of https://github.com/OpenTTD/OpenTTD
(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
parent
bbde7766d2
commit
db6121f361
|
@ -453,7 +453,7 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->OnDownloadProgress(this->curInfo, (uint)toRead);
|
this->OnDownloadProgress(this->curInfo, (int)toRead);
|
||||||
|
|
||||||
if (toRead == 0) this->AfterDownload();
|
if (toRead == 0) this->AfterDownload();
|
||||||
}
|
}
|
||||||
|
@ -526,6 +526,10 @@ void ClientNetworkContentSocketHandler::OnFailure()
|
||||||
this->http_response_index = -2;
|
this->http_response_index = -2;
|
||||||
|
|
||||||
if (this->curFile != NULL) {
|
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);
|
fclose(this->curFile);
|
||||||
this->curFile = NULL;
|
this->curFile = NULL;
|
||||||
}
|
}
|
||||||
|
@ -559,7 +563,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
|
||||||
this->OnFailure();
|
this->OnFailure();
|
||||||
} else {
|
} else {
|
||||||
/* Just received the data. */
|
/* Just received the data. */
|
||||||
this->OnDownloadProgress(this->curInfo, (uint)length);
|
this->OnDownloadProgress(this->curInfo, (int)length);
|
||||||
}
|
}
|
||||||
/* Nothing more to do now. */
|
/* Nothing more to do now. */
|
||||||
return;
|
return;
|
||||||
|
@ -1023,7 +1027,7 @@ void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 */) {
|
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
|
||||||
ContentCallback *cb = *iter;
|
ContentCallback *cb = *iter;
|
||||||
|
|
|
@ -49,7 +49,7 @@ struct ContentCallback {
|
||||||
* @param ci the content info of the file
|
* @param ci the content info of the file
|
||||||
* @param bytes the number of bytes downloaded since the previous call
|
* @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
|
* We have finished downloading a file
|
||||||
|
@ -89,7 +89,7 @@ protected:
|
||||||
void OnConnect(bool success);
|
void OnConnect(bool success);
|
||||||
void OnDisconnect();
|
void OnDisconnect();
|
||||||
void OnReceiveContentInfo(const ContentInfo *ci);
|
void OnReceiveContentInfo(const ContentInfo *ci);
|
||||||
void OnDownloadProgress(const ContentInfo *ci, uint bytes);
|
void OnDownloadProgress(const ContentInfo *ci, int bytes);
|
||||||
void OnDownloadComplete(ContentID cid);
|
void OnDownloadComplete(ContentID cid);
|
||||||
|
|
||||||
void OnFailure();
|
void OnFailure();
|
||||||
|
|
|
@ -175,7 +175,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes)
|
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes)
|
||||||
{
|
{
|
||||||
if (ci->id != this->cur_id) {
|
if (ci->id != this->cur_id) {
|
||||||
strecpy(this->name, ci->filename, lastof(this->name));
|
strecpy(this->name, ci->filename, lastof(this->name));
|
||||||
|
|
Loading…
Reference in New Issue