Changeset - r17444:de3de14c6d35
[Not reviewed]
master
0 3 0
rubidium - 13 years ago 2011-03-06 10:11:59
rubidium@openttd.org
(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
3 files changed with 10 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/network/network_content.cpp
Show inline comments
 
@@ -450,13 +450,13 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACK
 
			fclose(this->curFile);
 
			this->curFile = NULL;
 

	
 
			return false;
 
		}
 

	
 
		this->OnDownloadProgress(this->curInfo, (uint)toRead);
 
		this->OnDownloadProgress(this->curInfo, (int)toRead);
 

	
 
		if (toRead == 0) this->AfterDownload();
 
	}
 

	
 
	return true;
 
}
 
@@ -523,12 +523,16 @@ void ClientNetworkContentSocketHandler::
 
	this->DownloadSelectedContent(files, bytes, true);
 

	
 
	this->http_response.Reset();
 
	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;
 
	}
 
}
 

	
 
void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t length)
 
@@ -556,13 +560,13 @@ void ClientNetworkContentSocketHandler::
 
		/* We have data, so write it to the file. */
 
		if (fwrite(data, 1, length, this->curFile) != length) {
 
			/* Writing failed somehow, let try via the old method. */
 
			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;
 
	}
 

	
 
	if (this->curFile != NULL) {
 
@@ -1020,13 +1024,13 @@ void ClientNetworkContentSocketHandler::
 
		ContentCallback *cb = *iter;
 
		cb->OnReceiveContentInfo(ci);
 
		if (iter != this->callbacks.End() && *iter == cb) iter++;
 
	}
 
}
 

	
 
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;
 
		cb->OnDownloadProgress(ci, bytes);
 
		if (iter != this->callbacks.End() && *iter == cb) iter++;
 
	}
src/network/network_content.h
Show inline comments
 
@@ -46,13 +46,13 @@ struct ContentCallback {
 

	
 
	/**
 
	 * We have progress in the download of a file
 
	 * @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
 
	 * @param cid the ContentID of the downloaded file
 
	 */
 
	virtual void OnDownloadComplete(ContentID cid) {}
 
@@ -86,13 +86,13 @@ protected:
 
	ContentInfo *GetContent(ContentID cid);
 
	void DownloadContentInfo(ContentID cid);
 

	
 
	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();
 
	void OnReceiveData(const char *data, size_t length);
 

	
 
	bool BeforeDownload();
src/network/network_content_gui.cpp
Show inline comments
 
@@ -172,13 +172,13 @@ public:
 
		if (widget == NCDSWW_CANCELOK) {
 
			if (this->downloaded_bytes != this->total_bytes) _network_content_client.Close();
 
			delete this;
 
		}
 
	}
 

	
 
	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));
 
			this->cur_id = ci->id;
 
			this->downloaded_files++;
 
			this->receivedTypes.Include(ci->type);
0 comments (0 inline, 0 general)