- FString is always gone.

This commit is contained in:
Christoph Oelckers 2023-08-21 22:36:25 +02:00
parent 3e3526f1ec
commit 5433430767
3 changed files with 46 additions and 24 deletions

View file

@ -311,9 +311,11 @@ int FileSystem::AddExternalFile(const char *filename)
int FileSystem::AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags)
{
FStringf fullname("%s.%s", name, type);
std::string fullname = name;
fullname += ':';
fullname += type;
auto newlump = new FMemoryLump(data, size);
newlump->LumpNameSetup(fullname);
newlump->LumpNameSetup(fullname.c_str());
AddLump(newlump);
FileInfo.back().resourceId = id;
return (int)FileInfo.size()-1;
@ -338,7 +340,7 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
if (filer == nullptr)
{
// Does this exist? If so, is it a directory?
if (!DirEntryExists(filename, &isdir))
if (!FS_DirEntryExists(filename, &isdir))
{
if (Printf)
{
@ -396,10 +398,11 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
FResourceLump *lump = resfile->GetLump(i);
if (lump->Flags & LUMPF_EMBEDDED)
{
FString path;
path.Format("%s:%s", filename, lump->getName());
std::string path = filename;
path += ':';
path += lump->getName();
auto embedded = lump->NewReader();
AddFile(path, &embedded, filter, Printf, hashfile);
AddFile(path.c_str(), &embedded, filter, Printf, hashfile);
}
}
@ -476,8 +479,8 @@ int FileSystem::CheckIfResourceFileLoaded (const char *name) noexcept
{
for (i = 0; i < Files.Size(); ++i)
{
auto pth = ExtractFileBase(GetResourceFileName(i), true);
if (stricmp (pth.GetChars(), name) == 0)
auto pth = ExtractBaseName(GetResourceFileName(i), true);
if (stricmp (pth.c_str(), name) == 0)
{
return i;
}
@ -1255,10 +1258,10 @@ static int folderentrycmp(const void *a, const void *b)
unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &result, bool atomic) const
{
FString path = inpath;
FixPathSeperator(path);
path.ToLower();
if (path[path.Len() - 1] != '/') path += '/';
std::string path = inpath;
FixPathSeparator(&path.front());
for (auto& c : path) c = tolower(c);
if (path.back() != '/') path += '/';
result.Clear();
for (size_t i = 0; i < FileInfo.size(); i++)
{
@ -1507,11 +1510,11 @@ const char *FileSystem::GetResourceFileFullName (int rfnum) const noexcept
bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)
{
FString name2=name, type2, path;
std::string name2 = name, type2, path;
// The old code said 'filename' and ignored the path, this looked like a bug.
FixPathSeperator(name2);
auto lump = FindFile(name2);
FixPathSeparator(&name2.front());
auto lump = FindFile(name2.c_str());
if (lump < 0) return false; // Does not exist.
auto oldlump = FileInfo[lump];

View file

@ -157,15 +157,6 @@ static int FS_FindClose(void *const handle)
return 0;
}
static bool DirEntryExists(const char* pathname, bool* isdir)
{
if (isdir) *isdir = false;
struct stat info;
bool res = stat(pathname, &info) == 0;
if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
return res;
}
static int FS_FindAttr(findstate_t *const fileinfo)
{
dirent *const ent = fileinfo->namelist[fileinfo->current];
@ -386,3 +377,30 @@ bool ScanDirectory(std::vector<FileListEntry>& list, const char* dirpath, const
return DoScanDirectory(list, dirpath, match, "", nosubdir, readhidden);
}
//==========================================================================
//
// DirEntryExists
//
// Returns true if the given path exists, be it a directory or a file.
//
//==========================================================================
bool FS_DirEntryExists(const char* pathname, bool* isdir)
{
if (isdir) *isdir = false;
if (pathname == NULL || *pathname == 0)
return false;
#ifndef _WIN32
struct stat info;
bool res = stat(pathname, &info) == 0;
#else
// Windows must use the wide version of stat to preserve non-standard paths.
auto wstr = toWide(pathname);
struct _stat64 info;
bool res = _wstat64(wstr.c_str(), &info) == 0;
#endif
if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
return res;
}

View file

@ -22,6 +22,7 @@ using FileList = std::vector<FileListEntry>;
struct FCompressedBuffer;
bool ScanDirectory(std::vector<FileListEntry>& list, const char* dirpath, const char* match, bool nosubdir = false, bool readhidden = false);
bool WriteZip(const char* filename, const FCompressedBuffer* content, size_t contentcount);
bool FS_DirEntryExists(const char* pathname, bool* isdir);
inline void FixPathSeparator(char* path)
{