- use TArray and FString in resource file management.

This commit is contained in:
Christoph Oelckers 2018-11-10 14:19:55 +01:00
parent 4d06c17a44
commit 191f2d9d76
13 changed files with 55 additions and 73 deletions

View file

@ -257,7 +257,7 @@ FIWadManager::FIWadManager(const char *fn)
if (lmp->Namespace == ns_global && !stricmp(lmp->Name, "IWADINFO"))
{
// Found one!
ParseIWadInfo(resfile->Filename, (const char*)lmp->CacheLump(), lmp->LumpSize);
ParseIWadInfo(resfile->FileName, (const char*)lmp->CacheLump(), lmp->LumpSize);
break;
}
}
@ -349,7 +349,7 @@ int FIWadManager::CheckIWADInfo(const char *fn)
try
{
FIWADInfo result;
ParseIWadInfo(resfile->Filename, (const char*)lmp->CacheLump(), lmp->LumpSize, &result);
ParseIWadInfo(resfile->FileName, (const char*)lmp->CacheLump(), lmp->LumpSize, &result);
delete resfile;
for (unsigned i = 0, count = mIWadInfos.Size(); i < count; ++i)

View file

@ -1905,7 +1905,7 @@ static FString CheckGameInfo(TArray<FString> & pwads)
if (lmp->Namespace == ns_global && !stricmp(lmp->Name, "GAMEINFO"))
{
// Found one!
FString iwad = ParseGameInfo(pwads, resfile->Filename, (const char*)lmp->CacheLump(), lmp->LumpSize);
FString iwad = ParseGameInfo(pwads, resfile->FileName, (const char*)lmp->CacheLump(), lmp->LumpSize);
delete resfile;
return iwad;
}

View file

@ -230,7 +230,7 @@ bool F7ZFile::Open(bool quiet)
Archive = NULL;
if (!quiet)
{
Printf("\n" TEXTCOLOR_RED "%s: ", Filename);
Printf("\n" TEXTCOLOR_RED "%s: ", FileName.GetChars());
if (res == SZ_ERROR_UNSUPPORTED)
{
Printf("Decoder does not support this archive\n");
@ -309,7 +309,7 @@ bool F7ZFile::Open(bool quiet)
if (SZ_OK != Archive->Extract(Lumps[0].Position, &temp[0]))
{
if (!quiet) Printf("\n%s: unsupported 7z/LZMA file!\n", Filename);
if (!quiet) Printf("\n%s: unsupported 7z/LZMA file!\n", FileName.GetChars());
return false;
}
}

View file

@ -102,9 +102,9 @@ FDirectory::FDirectory(const char * directory)
#ifdef _WIN32
free((void *)directory);
#endif
dirname.ReplaceChars('\\', '/');
FixPathSeperator(dirname);
if (dirname[dirname.Len()-1] != '/') dirname += '/';
Filename = copystring(dirname);
FileName = dirname;
}
@ -248,7 +248,7 @@ int FDirectory::AddDirectory(const char *dirpath)
bool FDirectory::Open(bool quiet)
{
NumLumps = AddDirectory(Filename);
NumLumps = AddDirectory(FileName);
if (!quiet) Printf(", %d lumps\n", NumLumps);
PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump));
return true;
@ -268,7 +268,7 @@ void FDirectory::AddEntry(const char *fullpath, int size)
lump_p->mFullPath = fullpath;
// [mxd] Convert name to lowercase
FString name = fullpath + strlen(Filename);
FString name = fullpath + strlen(FileName);
name.ToLower();
// The lump's name is only the part relative to the main directory

View file

@ -85,7 +85,6 @@ public:
FGrpFile::FGrpFile(const char *filename, FileReader &file)
: FUncompressedFile(filename, file)
{
Lumps = NULL;
}
//==========================================================================
@ -104,7 +103,7 @@ bool FGrpFile::Open(bool quiet)
GrpLump *fileinfo = new GrpLump[NumLumps];
Reader.Read (fileinfo, NumLumps * sizeof(GrpLump));
Lumps = new FUncompressedLump[NumLumps];
Lumps.Resize(NumLumps);
int Position = sizeof(GrpInfo) + NumLumps * sizeof(GrpLump);

View file

@ -69,17 +69,17 @@ FLumpFile::FLumpFile(const char *filename, FileReader &file)
bool FLumpFile::Open(bool quiet)
{
FString name(ExtractFileBase (Filename));
FString name(ExtractFileBase (FileName));
Lumps = new FUncompressedLump[1]; // must use array allocator
uppercopy(Lumps->Name, name);
Lumps->Name[8] = 0;
Lumps->Owner = this;
Lumps->Position = 0;
Lumps->LumpSize = (int)Reader.GetLength();
Lumps->Namespace = ns_global;
Lumps->Flags = 0;
Lumps->FullName = NULL;
Lumps.Resize(1);
uppercopy(Lumps[0].Name, name);
Lumps[0].Name[8] = 0;
Lumps[0].Owner = this;
Lumps[0].Position = 0;
Lumps[0].LumpSize = (int)Reader.GetLength();
Lumps[0].Namespace = ns_global;
Lumps[0].Flags = 0;
Lumps[0].FullName = NULL;
NumLumps = 1;
if (!quiet)
{

View file

@ -80,7 +80,6 @@ public:
FPakFile::FPakFile(const char *filename, FileReader &file)
: FUncompressedFile(filename, file)
{
Lumps = NULL;
}
//==========================================================================
@ -101,7 +100,7 @@ bool FPakFile::Open(bool quiet)
Reader.Seek (header.dirofs, FileReader::SeekSet);
Reader.Read (fileinfo, NumLumps * sizeof(dpackfile_t));
Lumps = new FUncompressedLump[NumLumps];
Lumps.Resize(NumLumps);
if (!quiet && !batchrun) Printf(", %d lumps\n", NumLumps);

View file

@ -165,7 +165,7 @@ bool FWadFile::Open(bool quiet)
// Check again to detect broken wads
if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize)
{
I_Error("Cannot load broken WAD file %s\n", Filename);
I_Error("Cannot load broken WAD file %s\n", FileName.GetChars());
}
}
@ -194,7 +194,7 @@ bool FWadFile::Open(bool quiet)
{
if (Lumps[i].LumpSize != 0)
{
Printf(PRINT_HIGH, "%s: Lump %s contains invalid positioning info and will be ignored\n", Filename, Lumps[i].Name);
Printf(PRINT_HIGH, "%s: Lump %s contains invalid positioning info and will be ignored\n", FileName.GetChars(), Lumps[i].Name);
Lumps[i].Name[0] = 0;
}
Lumps[i].LumpSize = Lumps[i].Position = 0;
@ -439,7 +439,7 @@ void FWadFile::SkinHack ()
"The maps in %s will not be loaded because it has a skin.\n"
TEXTCOLOR_BLUE
"You should remove the skin from the wad to play these maps.\n",
Filename);
FileName.GetChars());
}
}

View file

@ -181,7 +181,7 @@ bool FZipFile::Open(bool quiet)
if (centraldir == 0)
{
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: ZIP file corrupt!\n", Filename);
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: ZIP file corrupt!\n", FileName.GetChars());
return false;
}
@ -193,7 +193,7 @@ bool FZipFile::Open(bool quiet)
if (info.NumEntries != info.NumEntriesOnAllDisks ||
info.FirstDisk != 0 || info.DiskNumber != 0)
{
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Multipart Zip files are not supported.\n", Filename);
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Multipart Zip files are not supported.\n", FileName.GetChars());
return false;
}
@ -229,7 +229,7 @@ bool FZipFile::Open(bool quiet)
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
{
free(directory);
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Central directory corrupted.", Filename);
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Central directory corrupted.", FileName.GetChars());
return false;
}
@ -300,7 +300,7 @@ bool FZipFile::Open(bool quiet)
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
{
free(directory);
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Central directory corrupted.", Filename);
if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Central directory corrupted.", FileName.GetChars());
return false;
}
@ -320,7 +320,7 @@ bool FZipFile::Open(bool quiet)
zip_fh->Method != METHOD_IMPLODE &&
zip_fh->Method != METHOD_SHRINK)
{
if (!quiet) Printf(TEXTCOLOR_YELLOW "\n%s: '%s' uses an unsupported compression algorithm (#%d).\n", Filename, name.GetChars(), zip_fh->Method);
if (!quiet) Printf(TEXTCOLOR_YELLOW "\n%s: '%s' uses an unsupported compression algorithm (#%d).\n", FileName.GetChars(), name.GetChars(), zip_fh->Method);
skipped++;
continue;
}
@ -328,7 +328,7 @@ bool FZipFile::Open(bool quiet)
zip_fh->Flags = LittleShort(zip_fh->Flags);
if (zip_fh->Flags & ZF_ENCRYPTED)
{
if (!quiet) Printf(TEXTCOLOR_YELLOW "\n%s: '%s' is encrypted. Encryption is not supported.\n", Filename, name.GetChars());
if (!quiet) Printf(TEXTCOLOR_YELLOW "\n%s: '%s' is encrypted. Encryption is not supported.\n", FileName.GetChars(), name.GetChars());
skipped++;
continue;
}

View file

@ -156,7 +156,7 @@ static bool IsWadInFolder(const FResourceFile* const archive, const char* const
return false;
}
const FString dirName = ExtractFileBase(archive->Filename);
const FString dirName = ExtractFileBase(archive->FileName);
const FString fileName = ExtractFileBase(resPath, true);
const FString filePath = dirName + '/' + fileName;
@ -323,9 +323,8 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet)
//==========================================================================
FResourceFile::FResourceFile(const char *filename)
: FileName(filename)
{
if (filename != NULL) Filename = copystring(filename);
else Filename = NULL;
}
FResourceFile::FResourceFile(const char *filename, FileReader &r)
@ -336,7 +335,6 @@ FResourceFile::FResourceFile(const char *filename, FileReader &r)
FResourceFile::~FResourceFile()
{
if (Filename != NULL) delete [] Filename;
}
int lumpcmp(const void * a, const void * b)
@ -653,12 +651,6 @@ FUncompressedFile::FUncompressedFile(const char *filename, FileReader &r)
: FResourceFile(filename, r)
{}
FUncompressedFile::~FUncompressedFile()
{
if (Lumps != NULL) delete [] Lumps;
}
//==========================================================================
//
@ -667,9 +659,8 @@ FUncompressedFile::~FUncompressedFile()
//==========================================================================
FExternalLump::FExternalLump(const char *_filename, int filesize)
: Filename(_filename)
{
filename = _filename? copystring(_filename) : NULL;
if (filesize == -1)
{
FileReader f;
@ -690,11 +681,6 @@ FExternalLump::FExternalLump(const char *_filename, int filesize)
}
FExternalLump::~FExternalLump()
{
if (filename != NULL) delete [] filename;
}
//==========================================================================
//
// Caches a lump's content and increases the reference counter
@ -707,7 +693,7 @@ int FExternalLump::FillCache()
Cache = new char[LumpSize];
FileReader f;
if (f.OpenFile(filename))
if (f.OpenFile(Filename))
{
f.Read(Cache, LumpSize);
}
@ -722,19 +708,19 @@ int FExternalLump::FillCache()
bool FMemoryFile::Open(bool quiet)
{
FString name(ExtractFileBase(Filename));
FString fname(ExtractFileBase(Filename, true));
FString name(ExtractFileBase(FileName));
FString fname(ExtractFileBase(FileName, true));
Lumps = new FUncompressedLump[1]; // must use array allocator
uppercopy(Lumps->Name, name);
Lumps->Name[8] = 0;
Lumps->FullName = fname;
Lumps->Owner = this;
Lumps->Position = 0;
Lumps->LumpSize = (int)Reader.GetLength();
Lumps->Namespace = ns_global;
Lumps->Flags = 0;
Lumps->FullName = NULL;
Lumps.Resize(1);
uppercopy(Lumps[0].Name, name);
Lumps[0].Name[8] = 0;
Lumps[0].FullName = fname;
Lumps[0].Owner = this;
Lumps[0].Position = 0;
Lumps[0].LumpSize = (int)Reader.GetLength();
Lumps[0].Namespace = ns_global;
Lumps[0].Flags = 0;
Lumps[0].FullName = nullptr;
NumLumps = 1;
return true;
}

View file

@ -82,7 +82,7 @@ class FResourceFile
{
public:
FileReader Reader;
const char *Filename;
FString FileName;
protected:
uint32_t NumLumps;
@ -133,21 +133,19 @@ struct FUncompressedLump : public FResourceLump
class FUncompressedFile : public FResourceFile
{
protected:
FUncompressedLump * Lumps = nullptr;
TArray<FUncompressedLump> Lumps;
FUncompressedFile(const char *filename);
FUncompressedFile(const char *filename, FileReader &r);
virtual ~FUncompressedFile();
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
};
struct FExternalLump : public FResourceLump
{
const char *filename; // the actual file name. This is not necessarily the same as the lump name!
FString Filename;
FExternalLump(const char *_filename, int filesize = -1);
~FExternalLump();
virtual int FillCache();
};

View file

@ -431,11 +431,11 @@ public:
}
// Reserves amount entries at the end of the array, but does nothing
// with them.
unsigned int Reserve (unsigned int amount)
unsigned int Reserve (size_t amount)
{
Grow (amount);
Grow ((unsigned)amount);
unsigned int place = Count;
Count += amount;
Count += (unsigned)amount;
if (Count > 0) ConstructEmpty(place, Count - 1);
return place;
}

View file

@ -1413,7 +1413,7 @@ const char *FWadCollection::GetWadName (int wadnum) const
return NULL;
}
name = Files[wadnum]->Filename;
name = Files[wadnum]->FileName;
slash = strrchr (name, '/');
return slash != NULL ? slash+1 : name;
}
@ -1476,10 +1476,10 @@ const char *FWadCollection::GetWadFullName (int wadnum) const
{
if ((unsigned int)wadnum >= Files.Size())
{
return NULL;
return nullptr;
}
return Files[wadnum]->Filename;
return Files[wadnum]->FileName;
}