mirror of https://github.com/OpenTTD/OpenTTD
(svn r23234) -Fix [FS#4840]: crash when after downloading content
parent
6548ec6e9e
commit
a3a2fdcfc2
|
@ -682,6 +682,18 @@ uint TarScanner::DoScan(Subdirectory sd)
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a single file to the scanned files of a tar, circumventing the scanning code.
|
||||||
|
* @param sd The sub directory the file is in.
|
||||||
|
* @param filename The name of the file to add.
|
||||||
|
* @return True if the additions went correctly.
|
||||||
|
*/
|
||||||
|
bool TarScanner::AddFile(Subdirectory sd, const char *filename)
|
||||||
|
{
|
||||||
|
this->subdir = sd;
|
||||||
|
return this->AddFile(filename, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool TarScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
|
bool TarScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
|
||||||
{
|
{
|
||||||
/* No tar within tar. */
|
/* No tar within tar. */
|
||||||
|
|
|
@ -105,6 +105,8 @@ public:
|
||||||
|
|
||||||
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL);
|
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL);
|
||||||
|
|
||||||
|
bool AddFile(Subdirectory sd, const char *filename);
|
||||||
|
|
||||||
/** Do the scan for Tars. */
|
/** Do the scan for Tars. */
|
||||||
static uint DoScan(TarScanner::Mode mode);
|
static uint DoScan(TarScanner::Mode mode);
|
||||||
};
|
};
|
||||||
|
|
|
@ -530,13 +530,41 @@ void ClientNetworkContentSocketHandler::AfterDownload()
|
||||||
if (GunzipFile(this->curInfo)) {
|
if (GunzipFile(this->curInfo)) {
|
||||||
unlink(GetFullFilename(this->curInfo, true));
|
unlink(GetFullFilename(this->curInfo, true));
|
||||||
|
|
||||||
TarScanner ts;
|
|
||||||
ts.AddFile(GetFullFilename(this->curInfo, false), 0);
|
|
||||||
|
|
||||||
if (this->curInfo->type == CONTENT_TYPE_BASE_MUSIC) {
|
if (this->curInfo->type == CONTENT_TYPE_BASE_MUSIC) {
|
||||||
/* Music can't be in a tar. So extract the tar! */
|
/* Music can't be in a tar. So extract the tar! */
|
||||||
ExtractTar(GetFullFilename(this->curInfo, false), BASESET_DIR);
|
ExtractTar(GetFullFilename(this->curInfo, false), BASESET_DIR);
|
||||||
unlink(GetFullFilename(this->curInfo, false));
|
unlink(GetFullFilename(this->curInfo, false));
|
||||||
|
} else {
|
||||||
|
Subdirectory sd = NO_DIRECTORY;
|
||||||
|
switch (this->curInfo->type) {
|
||||||
|
case CONTENT_TYPE_AI:
|
||||||
|
sd = AI_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_TYPE_AI_LIBRARY:
|
||||||
|
sd = AI_LIBRARY_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_TYPE_BASE_GRAPHICS:
|
||||||
|
case CONTENT_TYPE_BASE_SOUNDS:
|
||||||
|
case CONTENT_TYPE_BASE_MUSIC:
|
||||||
|
sd = BASESET_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_TYPE_NEWGRF:
|
||||||
|
sd = NEWGRF_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_TYPE_SCENARIO:
|
||||||
|
case CONTENT_TYPE_HEIGHTMAP:
|
||||||
|
sd = SCENARIO_DIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
TarScanner ts;
|
||||||
|
ts.AddFile(sd, GetFullFilename(this->curInfo, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
this->OnDownloadComplete(this->curInfo->id);
|
this->OnDownloadComplete(this->curInfo->id);
|
||||||
|
|
Loading…
Reference in New Issue