diff --git a/src/common/filesystem/file_7z.cpp b/src/common/filesystem/file_7z.cpp index 391a8aab2..262dd370d 100644 --- a/src/common/filesystem/file_7z.cpp +++ b/src/common/filesystem/file_7z.cpp @@ -227,7 +227,7 @@ bool F7ZFile::Open(LumpFilterInfo *filter, FileSystemMessageFunc Printf) Archive = NULL; 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) { @@ -300,7 +300,7 @@ bool F7ZFile::Open(LumpFilterInfo *filter, FileSystemMessageFunc Printf) 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; } } diff --git a/src/common/filesystem/file_directory.cpp b/src/common/filesystem/file_directory.cpp index a99e6fb56..cbb79b446 100644 --- a/src/common/filesystem/file_directory.cpp +++ b/src/common/filesystem/file_directory.cpp @@ -38,6 +38,7 @@ #include "resourcefile.h" #include "fs_findfile.h" +#include "fs_stringpool.h" std::string FS_FullPath(const char* directory); @@ -91,8 +92,9 @@ public: FDirectory::FDirectory(const char * directory, StringPool* sp, bool nosubdirflag) : FResourceFile("", sp), nosubdir(nosubdirflag) { - FileName = FS_FullPath(directory); - if (FileName[FileName.length()-1] != '/') FileName += '/'; + auto fn = FS_FullPath(directory); + 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) { - NumLumps = AddDirectory(FileName.c_str(), filter, Printf); + NumLumps = AddDirectory(File_Name, filter, Printf); PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump), filter); return true; } @@ -167,7 +169,7 @@ void FDirectory::AddEntry(const char *fullpath, int size) lump_p->mFullPath = fullpath; // [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); // The lump's name is only the part relative to the main directory diff --git a/src/common/filesystem/file_lump.cpp b/src/common/filesystem/file_lump.cpp index 540ee6dd7..962482c83 100644 --- a/src/common/filesystem/file_lump.cpp +++ b/src/common/filesystem/file_lump.cpp @@ -68,7 +68,7 @@ FLumpFile::FLumpFile(const char *filename, FileReader &file, StringPool* sp) bool FLumpFile::Open(LumpFilterInfo*) { 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].Position = 0; Lumps[0].LumpSize = (int)Reader.GetLength(); diff --git a/src/common/filesystem/file_wad.cpp b/src/common/filesystem/file_wad.cpp index badcc271f..b79c13cb0 100644 --- a/src/common/filesystem/file_wad.cpp +++ b/src/common/filesystem/file_wad.cpp @@ -183,7 +183,7 @@ bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf) // Check again to detect broken wads 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; } } @@ -220,7 +220,7 @@ bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf) { 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].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 - 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) @@ -319,7 +319,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name { // We can't add this to the flats namespace but // 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; } } @@ -333,7 +333,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name int start, end; 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++; continue; } @@ -342,21 +342,21 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name // skip over subsequent x_START markers 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++; continue; } // same for x_END markers 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++; continue; } // We found a starting marker but no end marker. Ignore this block. 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; } else @@ -365,14 +365,14 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name } // 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++) { if (Lumps[j].Namespace != ns_global) { 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; } @@ -382,7 +382,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name // ignore sprite lumps smaller than 8 bytes (the smallest possible) // in size -- this was used by some dmadds wads // 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 { @@ -452,7 +452,7 @@ void FWadFile::SkinHack (FileSystemMessageFunc Printf) } 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"); } } diff --git a/src/common/filesystem/file_zip.cpp b/src/common/filesystem/file_zip.cpp index 175c53e18..c2acb10f7 100644 --- a/src/common/filesystem/file_zip.cpp +++ b/src/common/filesystem/file_zip.cpp @@ -180,7 +180,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) 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; } @@ -196,7 +196,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) if (info.NumEntries != info.NumEntriesOnAllDisks || 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; } @@ -215,7 +215,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) if (info.NumEntries != info.NumEntriesOnAllDisks || 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; } @@ -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. { free(directory); - Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", FileName.c_str()); + Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", File_Name); 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. { free(directory); - Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", FileName.c_str()); + Printf(FSMessageLevel::Error, "%s: Central directory corrupted.", File_Name); return false; } @@ -350,7 +350,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) zip_fh->Method != METHOD_IMPLODE && 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++; continue; } @@ -358,7 +358,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) zip_fh->Flags = LittleShort(zip_fh->Flags); 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++; continue; } @@ -385,7 +385,7 @@ bool FZipFile::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf) if (zip_64->CompressedSize > 0x7fffffff || zip_64->UncompressedSize > 0x7fffffff) { // 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++; continue; } diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index 6a0049fc8..39a730b7d 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -1419,7 +1419,7 @@ const char *FileSystem::GetResourceFileName (int rfnum) const noexcept return NULL; } - name = Files[rfnum]->FileName.c_str(); + name = Files[rfnum]->File_Name; slash = strrchr (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 Files[rfnum]->FileName.c_str(); + return Files[rfnum]->File_Name; } diff --git a/src/common/filesystem/resourcefile.cpp b/src/common/filesystem/resourcefile.cpp index 5f044371f..0a92fe7da 100644 --- a/src/common/filesystem/resourcefile.cpp +++ b/src/common/filesystem/resourcefile.cpp @@ -154,7 +154,7 @@ static bool IsWadInFolder(const FResourceFile* const archive, const char* const return false; } - const auto dirName = ExtractBaseName(archive->FileName.c_str()); + const auto dirName = ExtractBaseName(archive->File_Name); const auto fileName = ExtractBaseName(resPath, true); const std::string filePath = dirName + '/' + fileName; @@ -239,7 +239,7 @@ void *FResourceLump::Lock() catch (const FileSystemException& err) { // 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; @@ -328,9 +328,9 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, LumpFilterInfo //========================================================================== FResourceFile::FResourceFile(const char *filename, StringPool* sp) - : FileName(filename) { stringpool = sp ? sp : new StringPool; + File_Name = stringpool->Strdup(filename); } FResourceFile::FResourceFile(const char *filename, FileReader &r, StringPool* sp) diff --git a/src/common/filesystem/resourcefile.h b/src/common/filesystem/resourcefile.h index 6acf0b89b..b73d082c1 100644 --- a/src/common/filesystem/resourcefile.h +++ b/src/common/filesystem/resourcefile.h @@ -156,7 +156,7 @@ class FResourceFile { public: FileReader Reader; - std::string FileName; + const char* File_Name; protected: uint32_t NumLumps; char Hash[48];