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

Method AfterDownload

src/network/network_content.cpp:521–551  ·  view source on GitHub ↗

* Handle the closing and extracting of a file after * downloading it has been done. */

Source from the content-addressed store, hash-verified

519 * downloading it has been done.
520 */
521void ClientNetworkContentSocketHandler::AfterDownload()
522{
523 /* We read nothing; that's our marker for end-of-stream.
524 * Now gunzip the tar and make it known. */
525 this->cur_file.reset();
526
527 if (GunzipFile(*this->cur_info)) {
528 FioRemove(GetFullFilename(*this->cur_info, true));
529
530 Subdirectory sd = GetContentInfoSubDir(this->cur_info->type);
531 if (sd == NO_DIRECTORY) NOT_REACHED();
532
533 TarScanner ts;
534 std::string fname = GetFullFilename(*this->cur_info, false);
535 ts.AddFile(sd, fname);
536
537 if (this->cur_info->type == CONTENT_TYPE_BASE_MUSIC) {
538 /* Music can't be in a tar. So extract the tar! */
539 ExtractTar(fname, BASESET_DIR);
540 FioRemove(fname);
541 }
542
543#ifdef __EMSCRIPTEN__
544 EM_ASM(if (window["openttd_syncfs"]) openttd_syncfs());
545#endif
546
547 this->OnDownloadComplete(this->cur_info->id);
548 } else {
549 ShowErrorMessage(GetEncodedString(STR_CONTENT_ERROR_COULD_NOT_EXTRACT), {}, WL_ERROR);
550 }
551}
552
553bool ClientNetworkContentSocketHandler::IsCancelled() const
554{

Callers 2

OnReceiveDataMethod · 0.95

Calls 12

OnDownloadCompleteMethod · 0.95
GunzipFileFunction · 0.85
FioRemoveFunction · 0.85
GetFullFilenameFunction · 0.85
GetContentInfoSubDirFunction · 0.85
NOT_REACHEDFunction · 0.85
ExtractTarFunction · 0.85
ifFunction · 0.85
ShowErrorMessageFunction · 0.85
GetEncodedStringFunction · 0.50
resetMethod · 0.45
AddFileMethod · 0.45

Tested by

no test coverage detected