mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-14 00:20:51 +00:00
- use the string pool for storing resource file names.
This commit is contained in:
parent
6d2047eef6
commit
54dc687436
8 changed files with 35 additions and 33 deletions
|
@ -227,7 +227,7 @@ bool F7ZFile::Open(LumpFilterInfo *filter, FileSystemMessageFunc Printf)
|
||||||
Archive = NULL;
|
Archive = NULL;
|
||||||
if (res == SZ_ERROR_UNSUPPORTED)
|
if (res == SZ_ERROR_UNSUPPORTED)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: Decoder does not support this archive\n", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: Decoder does not support this archive\n", File_Name);
|
||||||
}
|
}
|
||||||
else if (res == SZ_ERROR_MEM)
|
else if (res == SZ_ERROR_MEM)
|
||||||
{
|
{
|
||||||
|
@ -300,7 +300,7 @@ bool F7ZFile::Open(LumpFilterInfo *filter, FileSystemMessageFunc Printf)
|
||||||
|
|
||||||
if (SZ_OK != Archive->Extract(Lumps[0].Position, &temp[0]))
|
if (SZ_OK != Archive->Extract(Lumps[0].Position, &temp[0]))
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: unsupported 7z/LZMA file!\n", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: unsupported 7z/LZMA file!\n", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "resourcefile.h"
|
#include "resourcefile.h"
|
||||||
#include "fs_findfile.h"
|
#include "fs_findfile.h"
|
||||||
|
#include "fs_stringpool.h"
|
||||||
|
|
||||||
std::string FS_FullPath(const char* directory);
|
std::string FS_FullPath(const char* directory);
|
||||||
|
|
||||||
|
@ -91,8 +92,9 @@ public:
|
||||||
FDirectory::FDirectory(const char * directory, StringPool* sp, bool nosubdirflag)
|
FDirectory::FDirectory(const char * directory, StringPool* sp, bool nosubdirflag)
|
||||||
: FResourceFile("", sp), nosubdir(nosubdirflag)
|
: FResourceFile("", sp), nosubdir(nosubdirflag)
|
||||||
{
|
{
|
||||||
FileName = FS_FullPath(directory);
|
auto fn = FS_FullPath(directory);
|
||||||
if (FileName[FileName.length()-1] != '/') FileName += '/';
|
if (fn.back() != '/') fn += '/';
|
||||||
|
File_Name = sp->Strdup(fn.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -148,7 +150,7 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy
|
||||||
|
|
||||||
bool FDirectory::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
bool FDirectory::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
{
|
{
|
||||||
NumLumps = AddDirectory(FileName.c_str(), filter, Printf);
|
NumLumps = AddDirectory(File_Name, filter, Printf);
|
||||||
PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump), filter);
|
PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump), filter);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +169,7 @@ void FDirectory::AddEntry(const char *fullpath, int size)
|
||||||
lump_p->mFullPath = fullpath;
|
lump_p->mFullPath = fullpath;
|
||||||
|
|
||||||
// [mxd] Convert name to lowercase
|
// [mxd] Convert name to lowercase
|
||||||
std::string name = fullpath + FileName.length();
|
std::string name = fullpath + strlen(File_Name);
|
||||||
for (auto& c : name) c = tolower(c);
|
for (auto& c : name) c = tolower(c);
|
||||||
|
|
||||||
// The lump's name is only the part relative to the main directory
|
// The lump's name is only the part relative to the main directory
|
||||||
|
|
|
@ -68,7 +68,7 @@ FLumpFile::FLumpFile(const char *filename, FileReader &file, StringPool* sp)
|
||||||
bool FLumpFile::Open(LumpFilterInfo*)
|
bool FLumpFile::Open(LumpFilterInfo*)
|
||||||
{
|
{
|
||||||
Lumps.Resize(1);
|
Lumps.Resize(1);
|
||||||
Lumps[0].LumpNameSetup(ExtractBaseName(FileName.c_str(), true).c_str(), stringpool);
|
Lumps[0].LumpNameSetup(ExtractBaseName(File_Name, true).c_str(), stringpool);
|
||||||
Lumps[0].Owner = this;
|
Lumps[0].Owner = this;
|
||||||
Lumps[0].Position = 0;
|
Lumps[0].Position = 0;
|
||||||
Lumps[0].LumpSize = (int)Reader.GetLength();
|
Lumps[0].LumpSize = (int)Reader.GetLength();
|
||||||
|
|
|
@ -183,7 +183,7 @@ bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf)
|
||||||
// Check again to detect broken wads
|
// Check again to detect broken wads
|
||||||
if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize)
|
if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: Bad directory offset.\n", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: Bad directory offset.\n", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf)
|
||||||
{
|
{
|
||||||
if (Lumps[i].LumpSize != 0)
|
if (Lumps[i].LumpSize != 0)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Warning, "%s: Lump %s contains invalid positioning info and will be ignored\n", FileName.c_str(), Lumps[i].getName());
|
Printf(FSMessageLevel::Warning, "%s: Lump %s contains invalid positioning info and will be ignored\n", File_Name, Lumps[i].getName());
|
||||||
Lumps[i].clearName();
|
Lumps[i].clearName();
|
||||||
}
|
}
|
||||||
Lumps[i].LumpSize = Lumps[i].Position = 0;
|
Lumps[i].LumpSize = Lumps[i].Position = 0;
|
||||||
|
@ -305,7 +305,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
||||||
{
|
{
|
||||||
if (numendmarkers == 0) return; // no markers found
|
if (numendmarkers == 0) return; // no markers found
|
||||||
|
|
||||||
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", FileName.c_str(), endmarker, startmarker);
|
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", File_Name, endmarker, startmarker);
|
||||||
|
|
||||||
|
|
||||||
if (flathack)
|
if (flathack)
|
||||||
|
@ -319,7 +319,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
||||||
{
|
{
|
||||||
// We can't add this to the flats namespace but
|
// We can't add this to the flats namespace but
|
||||||
// it needs to be flagged for the texture manager.
|
// it needs to be flagged for the texture manager.
|
||||||
Printf(FSMessageLevel::DebugNotify, "%s: Marking %s as potential flat\n", FileName.c_str(), Lumps[ii].getName());
|
Printf(FSMessageLevel::DebugNotify, "%s: Marking %s as potential flat\n", File_Name, Lumps[ii].getName());
|
||||||
Lumps[ii].Flags |= LUMPF_MAYBEFLAT;
|
Lumps[ii].Flags |= LUMPF_MAYBEFLAT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
||||||
int start, end;
|
int start, end;
|
||||||
if (markers[i].markertype != 0)
|
if (markers[i].markertype != 0)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", FileName.c_str(), endmarker, startmarker);
|
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", File_Name, endmarker, startmarker);
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -342,21 +342,21 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
||||||
// skip over subsequent x_START markers
|
// skip over subsequent x_START markers
|
||||||
while (i < markers.Size() && markers[i].markertype == 0)
|
while (i < markers.Size() && markers[i].markertype == 0)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Warning, "%s: duplicate %s marker found.\n", FileName.c_str(), startmarker);
|
Printf(FSMessageLevel::Warning, "%s: duplicate %s marker found.\n", File_Name, startmarker);
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// same for x_END markers
|
// same for x_END markers
|
||||||
while (i < markers.Size()-1 && (markers[i].markertype == 1 && markers[i+1].markertype == 1))
|
while (i < markers.Size()-1 && (markers[i].markertype == 1 && markers[i+1].markertype == 1))
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Warning, "%s: duplicate %s marker found.\n", FileName.c_str(), endmarker);
|
Printf(FSMessageLevel::Warning, "%s: duplicate %s marker found.\n", File_Name, endmarker);
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// We found a starting marker but no end marker. Ignore this block.
|
// We found a starting marker but no end marker. Ignore this block.
|
||||||
if (i >= markers.Size())
|
if (i >= markers.Size())
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", FileName.c_str(), startmarker, endmarker);
|
Printf(FSMessageLevel::Warning, "%s: %s marker without corresponding %s found.\n", File_Name, startmarker, endmarker);
|
||||||
end = NumLumps;
|
end = NumLumps;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -365,14 +365,14 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
||||||
}
|
}
|
||||||
|
|
||||||
// we found a marked block
|
// we found a marked block
|
||||||
Printf(FSMessageLevel::DebugNotify, "%s: Found %s block at (%d-%d)\n", FileName.c_str(), startmarker, markers[start].index, end);
|
Printf(FSMessageLevel::DebugNotify, "%s: Found %s block at (%d-%d)\n", File_Name, startmarker, markers[start].index, end);
|
||||||
for(int j = markers[start].index + 1; j < end; j++)
|
for(int j = markers[start].index + 1; j < end; j++)
|
||||||
{
|
{
|
||||||
if (Lumps[j].Namespace != ns_global)
|
if (Lumps[j].Namespace != ns_global)
|
||||||
{
|
{
|
||||||
if (!warned)
|
if (!warned)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Warning, "%s: Overlapping namespaces found (lump %d)\n", FileName.c_str(), j);
|
Printf(FSMessageLevel::Warning, "%s: Overlapping namespaces found (lump %d)\n", File_Name, j);
|
||||||
}
|
}
|
||||||
warned = true;
|
warned = true;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
||||||
// ignore sprite lumps smaller than 8 bytes (the smallest possible)
|
// ignore sprite lumps smaller than 8 bytes (the smallest possible)
|
||||||
// in size -- this was used by some dmadds wads
|
// in size -- this was used by some dmadds wads
|
||||||
// as an 'empty' graphics resource
|
// as an 'empty' graphics resource
|
||||||
Printf(FSMessageLevel::DebugWarn, "%s: Skipped empty sprite %s (lump %d)\n", FileName.c_str(), Lumps[j].getName(), j);
|
Printf(FSMessageLevel::DebugWarn, "%s: Skipped empty sprite %s (lump %d)\n", File_Name, Lumps[j].getName(), j);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -452,7 +452,7 @@ void FWadFile::SkinHack (FileSystemMessageFunc Printf)
|
||||||
}
|
}
|
||||||
if (skinned && hasmap)
|
if (skinned && hasmap)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Attention, "%s: The maps will not be loaded because it has a skin.\n", FileName.c_str());
|
Printf(FSMessageLevel::Attention, "%s: The maps will not be loaded because it has a skin.\n", File_Name);
|
||||||
Printf(FSMessageLevel::Attention, "You should remove the skin from the wad to play these maps.\n");
|
Printf(FSMessageLevel::Attention, "You should remove the skin from the wad to play these maps.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
|
|
||||||
if (centraldir == 0)
|
if (centraldir == 0)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: ZIP file corrupt!\n", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: ZIP file corrupt!\n", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
if (info.NumEntries != info.NumEntriesOnAllDisks ||
|
if (info.NumEntries != info.NumEntriesOnAllDisks ||
|
||||||
info.FirstDisk != 0 || info.DiskNumber != 0)
|
info.FirstDisk != 0 || info.DiskNumber != 0)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: Multipart Zip files are not supported.\n", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: Multipart Zip files are not supported.\n", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
if (info.NumEntries != info.NumEntriesOnAllDisks ||
|
if (info.NumEntries != info.NumEntriesOnAllDisks ||
|
||||||
info.FirstDisk != 0 || info.DiskNumber != 0)
|
info.FirstDisk != 0 || info.DiskNumber != 0)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: Multipart Zip files are not supported.\n", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: Multipart Zip files are not supported.\n", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
|
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
|
||||||
{
|
{
|
||||||
free(directory);
|
free(directory);
|
||||||
Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
|
if (dirptr > ((char*)directory) + dirsize) // This directory entry goes beyond the end of the file.
|
||||||
{
|
{
|
||||||
free(directory);
|
free(directory);
|
||||||
Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", FileName.c_str());
|
Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", File_Name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
zip_fh->Method != METHOD_IMPLODE &&
|
zip_fh->Method != METHOD_IMPLODE &&
|
||||||
zip_fh->Method != METHOD_SHRINK)
|
zip_fh->Method != METHOD_SHRINK)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: '%s' uses an unsupported compression algorithm (#%d).\n", FileName.c_str(), name.c_str(), zip_fh->Method);
|
Printf(FSMessageLevel::Error, "%s: '%s' uses an unsupported compression algorithm (#%d).\n", File_Name, name.c_str(), zip_fh->Method);
|
||||||
skipped++;
|
skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
zip_fh->Flags = LittleShort(zip_fh->Flags);
|
zip_fh->Flags = LittleShort(zip_fh->Flags);
|
||||||
if (zip_fh->Flags & ZF_ENCRYPTED)
|
if (zip_fh->Flags & ZF_ENCRYPTED)
|
||||||
{
|
{
|
||||||
Printf(FSMessageLevel::Error, "%s: '%s' is encrypted. Encryption is not supported.\n", FileName.c_str(), name.c_str());
|
Printf(FSMessageLevel::Error, "%s: '%s' is encrypted. Encryption is not supported.\n", File_Name, name.c_str());
|
||||||
skipped++;
|
skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
|
||||||
if (zip_64->CompressedSize > 0x7fffffff || zip_64->UncompressedSize > 0x7fffffff)
|
if (zip_64->CompressedSize > 0x7fffffff || zip_64->UncompressedSize > 0x7fffffff)
|
||||||
{
|
{
|
||||||
// The file system is limited to 32 bit file sizes;
|
// The file system is limited to 32 bit file sizes;
|
||||||
Printf(FSMessageLevel::Warning, "%s: '%s' is too large.\n", FileName.c_str(), name.c_str());
|
Printf(FSMessageLevel::Warning, "%s: '%s' is too large.\n", File_Name, name.c_str());
|
||||||
skipped++;
|
skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1419,7 +1419,7 @@ const char *FileSystem::GetResourceFileName (int rfnum) const noexcept
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = Files[rfnum]->FileName.c_str();
|
name = Files[rfnum]->File_Name;
|
||||||
slash = strrchr (name, '/');
|
slash = strrchr (name, '/');
|
||||||
return (slash != nullptr && slash[1] != 0) ? slash+1 : name;
|
return (slash != nullptr && slash[1] != 0) ? slash+1 : name;
|
||||||
}
|
}
|
||||||
|
@ -1485,7 +1485,7 @@ const char *FileSystem::GetResourceFileFullName (int rfnum) const noexcept
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Files[rfnum]->FileName.c_str();
|
return Files[rfnum]->File_Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ static bool IsWadInFolder(const FResourceFile* const archive, const char* const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto dirName = ExtractBaseName(archive->FileName.c_str());
|
const auto dirName = ExtractBaseName(archive->File_Name);
|
||||||
const auto fileName = ExtractBaseName(resPath, true);
|
const auto fileName = ExtractBaseName(resPath, true);
|
||||||
const std::string filePath = dirName + '/' + fileName;
|
const std::string filePath = dirName + '/' + fileName;
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ void *FResourceLump::Lock()
|
||||||
catch (const FileSystemException& err)
|
catch (const FileSystemException& err)
|
||||||
{
|
{
|
||||||
// enrich the message with info about this lump.
|
// enrich the message with info about this lump.
|
||||||
throw FileSystemException("%s, file '%s': %s", getName(), Owner->FileName.c_str(), err.what());
|
throw FileSystemException("%s, file '%s': %s", getName(), Owner->File_Name, err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Cache;
|
return Cache;
|
||||||
|
@ -328,9 +328,9 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, LumpFilterInfo
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FResourceFile::FResourceFile(const char *filename, StringPool* sp)
|
FResourceFile::FResourceFile(const char *filename, StringPool* sp)
|
||||||
: FileName(filename)
|
|
||||||
{
|
{
|
||||||
stringpool = sp ? sp : new StringPool;
|
stringpool = sp ? sp : new StringPool;
|
||||||
|
File_Name = stringpool->Strdup(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
FResourceFile::FResourceFile(const char *filename, FileReader &r, StringPool* sp)
|
FResourceFile::FResourceFile(const char *filename, FileReader &r, StringPool* sp)
|
||||||
|
|
|
@ -156,7 +156,7 @@ class FResourceFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReader Reader;
|
FileReader Reader;
|
||||||
std::string FileName;
|
const char* File_Name;
|
||||||
protected:
|
protected:
|
||||||
uint32_t NumLumps;
|
uint32_t NumLumps;
|
||||||
char Hash[48];
|
char Hash[48];
|
||||||
|
|
Loading…
Reference in a new issue