|
|
@ -369,6 +369,7 @@ exit:
|
|
|
|
DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
|
|
|
|
DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this->curFile == NULL) {
|
|
|
|
if (this->curFile == NULL) {
|
|
|
|
|
|
|
|
delete this->curInfo;
|
|
|
|
/* When we haven't opened a file this must be our first packet with metadata. */
|
|
|
|
/* When we haven't opened a file this must be our first packet with metadata. */
|
|
|
|
this->curInfo = new ContentInfo;
|
|
|
|
this->curInfo = new ContentInfo;
|
|
|
|
this->curInfo->type = (ContentType)p->Recv_uint8();
|
|
|
|
this->curInfo->type = (ContentType)p->Recv_uint8();
|
|
|
@ -376,10 +377,40 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
|
|
|
|
this->curInfo->filesize = p->Recv_uint32();
|
|
|
|
this->curInfo->filesize = p->Recv_uint32();
|
|
|
|
p->Recv_string(this->curInfo->filename, lengthof(this->curInfo->filename));
|
|
|
|
p->Recv_string(this->curInfo->filename, lengthof(this->curInfo->filename));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!this->BeforeDownload()) {
|
|
|
|
|
|
|
|
this->Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* We have a file opened, thus are downloading internal content */
|
|
|
|
|
|
|
|
size_t toRead = (size_t)(p->size - p->pos);
|
|
|
|
|
|
|
|
if (fwrite(p->buffer + p->pos, 1, toRead, this->curFile) != toRead) {
|
|
|
|
|
|
|
|
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
|
|
|
|
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, 0, 0);
|
|
|
|
|
|
|
|
this->Close();
|
|
|
|
|
|
|
|
fclose(this->curFile);
|
|
|
|
|
|
|
|
this->curFile = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this->OnDownloadProgress(this->curInfo, (uint)toRead);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (toRead == 0) this->AfterDownload();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Handle the opening of the file before downloading.
|
|
|
|
|
|
|
|
* @return false on any error.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ClientNetworkContentSocketHandler::BeforeDownload()
|
|
|
|
|
|
|
|
{
|
|
|
|
if (!this->curInfo->IsValid()) {
|
|
|
|
if (!this->curInfo->IsValid()) {
|
|
|
|
delete this->curInfo;
|
|
|
|
delete this->curInfo;
|
|
|
|
this->curInfo = NULL;
|
|
|
|
this->curInfo = NULL;
|
|
|
|
this->Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -390,28 +421,20 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
|
|
|
|
/* Unless that fails ofcourse... */
|
|
|
|
/* Unless that fails ofcourse... */
|
|
|
|
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
|
|
|
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, 0, 0);
|
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, 0, 0);
|
|
|
|
this->Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this->curFile = fopen(filename, "wb");
|
|
|
|
this->curFile = fopen(filename, "wb");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
/* We have a file opened, thus are downloading internal content */
|
|
|
|
}
|
|
|
|
size_t toRead = (size_t)(p->size - p->pos);
|
|
|
|
|
|
|
|
if (fwrite(p->buffer + p->pos, 1, toRead, this->curFile) != toRead) {
|
|
|
|
|
|
|
|
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
|
|
|
|
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, 0, 0);
|
|
|
|
|
|
|
|
this->Close();
|
|
|
|
|
|
|
|
fclose(this->curFile);
|
|
|
|
|
|
|
|
this->curFile = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this->OnDownloadProgress(this->curInfo, (uint)toRead);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (toRead == 0) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Handle the closing and extracting of a file after
|
|
|
|
|
|
|
|
* downloading it has been done.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ClientNetworkContentSocketHandler::AfterDownload()
|
|
|
|
|
|
|
|
{
|
|
|
|
/* We read nothing; that's our marker for end-of-stream.
|
|
|
|
/* We read nothing; that's our marker for end-of-stream.
|
|
|
|
* Now gunzip the tar and make it known. */
|
|
|
|
* Now gunzip the tar and make it known. */
|
|
|
|
fclose(this->curFile);
|
|
|
|
fclose(this->curFile);
|
|
|
@ -426,16 +449,6 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_EXTRACT, INVALID_STRING_ID, 0, 0);
|
|
|
|
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_EXTRACT, INVALID_STRING_ID, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* We ended this file, so clean up the mess */
|
|
|
|
|
|
|
|
if (this->curFile == NULL) {
|
|
|
|
|
|
|
|
delete this->curInfo;
|
|
|
|
|
|
|
|
this->curInfo = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|