MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BeforeDownload

Method BeforeDownload

src/network/network_content.cpp:494–515  ·  view source on GitHub ↗

* Handle the opening of the file before downloading. * @return false on any error. */

Source from the content-addressed store, hash-verified

492 * @return false on any error.
493 */
494bool ClientNetworkContentSocketHandler::BeforeDownload()
495{
496 if (!this->cur_info->IsValid()) {
497 this->cur_info.reset();
498 return false;
499 }
500
501 if (this->cur_info->filesize != 0) {
502 /* The filesize is > 0, so we are going to download it */
503 std::string filename = GetFullFilename(*this->cur_info, true);
504 if (filename.empty() || !(this->cur_file = FileHandle::Open(filename, "wb")).has_value()) {
505 /* Unless that fails of course... */
506 CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
507 ShowErrorMessage(
508 GetEncodedString(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD),
509 GetEncodedString(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE),
510 WL_ERROR);
511 return false;
512 }
513 }
514 return true;
515}
516
517/**
518 * Handle the closing and extracting of a file after

Callers 2

OnReceiveDataMethod · 0.95

Calls 7

GetFullFilenameFunction · 0.85
CloseWindowByIdFunction · 0.85
ShowErrorMessageFunction · 0.85
GetEncodedStringFunction · 0.50
IsValidMethod · 0.45
resetMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected