- put the entire filesystem code into a namespace and created some subdirectories.

This commit is contained in:
Christoph Oelckers 2023-08-22 21:20:28 +02:00
commit ebb71cebf1
108 changed files with 308 additions and 225 deletions

View file

@ -53,6 +53,7 @@
#include "s_music.h"
#include "filereadermusicinterface.h"
using namespace FileSys;
void I_InitSoundFonts();
@ -192,7 +193,7 @@ static void SetupWgOpn()
{
return;
}
FileData data = fileSystem.ReadFile(lump);
auto data = fileSystem.ReadFile(lump);
ZMusic_SetWgOpn(data.GetMem(), (uint32_t)data.GetSize());
}
@ -204,7 +205,7 @@ static void SetupDMXGUS()
{
return;
}
FileData data = fileSystem.ReadFile(lump);
auto data = fileSystem.ReadFile(lump);
ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize());
}

View file

@ -40,10 +40,9 @@
#include "i_system.h"
#include "filereadermusicinterface.h"
#include <zmusic.h>
#include "resourcefile.h"
#include "fs_filesystem.h"
#include "version.h"
#include "fs_findfile.h"
#include "resourcefile.h"
#include "i_interface.h"
#include "configfile.h"
#include "printf.h"
@ -402,7 +401,7 @@ void FSoundFontManager::CollectSoundfonts()
{
if (stricmp (key, "Path") == 0)
{
FileList list;
FileSys::FileList list;
FString dir;
@ -410,7 +409,7 @@ void FSoundFontManager::CollectSoundfonts()
FixPathSeperator(dir);
if (dir.IsNotEmpty())
{
if (ScanDirectory(list, dir.GetChars(), "*", true))
if (FileSys::ScanDirectory(list, dir.GetChars(), "*", true))
{
for(auto& entry : list)
{

View file

@ -55,6 +55,7 @@
#include "i_specialpaths.h"
#include "configfile.h"
#include "c_cvars.h"
#include "md5.h"
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

View file

@ -5,9 +5,9 @@
#include "zstring.h"
#include "tarray.h"
#include "name.h"
#include "files.h"
#include <zmusic.h>
class FileReader;
class SoundStream;

View file

@ -40,8 +40,8 @@
#include "i_soundinternal.h"
#include "zstring.h"
#include <zmusic.h>
#include "files.h"
class FileReader;
struct FSoundChan;
enum EStartSoundFlags

View file

@ -201,8 +201,8 @@ UNSAFE_CCMD (dir)
bpath = path;
}
FileList list;
if (!ScanDirectory(list, bpath, base, true))
FileSys::FileList list;
if (!FileSys::ScanDirectory(list, bpath, base, true))
{
Printf ("Nothing matching %s\n", path.GetChars());
}

View file

@ -0,0 +1,6 @@
#pragma once
#include "fs_files.h"
using FileSys::FileReader;
using FileSys::FileWriter;
using FileSys::BufferWriter;

View file

@ -0,0 +1,7 @@
#pragma once
#include "fs_filesystem.h"
using FileSys::FileSystem;
using FileSys::FResourceFile;
inline FileSys::FileSystem fileSystem;

View file

@ -3,8 +3,7 @@
#include <stdint.h>
#include "memarena.h"
#include "palentry.h"
class FileReader;
#include "files.h"
enum
{

View file

@ -57,6 +57,8 @@
#include "base64.h"
#include "vm.h"
using namespace FileSys;
extern DObject *WP_NOCHANGE;
bool save_full = false; // for testing. Should be removed afterward.

View file

@ -4,7 +4,6 @@
#include <stdint.h>
#include <type_traits>
#include "tarray.h"
#include "file_zip.h"
#include "tflags.h"
#include "vectors.h"
#include "palentry.h"
@ -80,7 +79,7 @@ public:
void SetUniqueSoundNames() { soundNamesAreUnique = true; }
bool OpenWriter(bool pretty = true);
bool OpenReader(const char *buffer, size_t length);
bool OpenReader(FCompressedBuffer *input);
bool OpenReader(FileSys::FCompressedBuffer *input);
void Close();
void ReadObjects(bool hubtravel);
bool BeginObject(const char *name);
@ -91,7 +90,7 @@ public:
unsigned GetSize(const char *group);
const char *GetKey();
const char *GetOutput(unsigned *len = nullptr);
FCompressedBuffer GetCompressedOutput();
FileSys::FCompressedBuffer GetCompressedOutput();
// The sprite serializer is a special case because it is needed by the VM to handle its 'spriteid' type.
virtual FSerializer &Sprite(const char *key, int32_t &spritenum, int32_t *def);
// This is only needed by the type system.

View file

@ -45,6 +45,8 @@
#include "tarray.h"
namespace FileSys {
class FileSystemException : public std::exception
{
protected:
@ -271,7 +273,7 @@ public:
{
uint16_t v = 0;
Read(&v, 2);
return fs_private::LittleShort(v);
return byteswap::LittleShort(v);
}
int16_t ReadInt16()
@ -283,7 +285,7 @@ public:
{
uint16_t v = 0;
Read(&v, 2);
return fs_private::BigShort(v);
return byteswap::BigShort(v);
}
int16_t ReadInt16BE()
@ -295,7 +297,7 @@ public:
{
uint32_t v = 0;
Read(&v, 4);
return fs_private::LittleLong(v);
return byteswap::LittleLong(v);
}
int32_t ReadInt32()
@ -307,7 +309,7 @@ public:
{
uint32_t v = 0;
Read(&v, 4);
return fs_private::BigLong(v);
return byteswap::BigLong(v);
}
int32_t ReadInt32BE()
@ -394,5 +396,6 @@ public:
TArray<unsigned char>&& TakeBuffer() { return std::move(mBuffer); }
};
}
#endif

View file

@ -8,10 +8,11 @@
#include "files.h"
#include "cmdlib.h"
#include "fs_files.h"
#include "resourcefile.h"
namespace FileSys {
class FResourceFile;
struct FResourceLump;
@ -92,31 +93,31 @@ public:
int GetLastEntry(int wadnum) const noexcept;
int GetEntryCount(int wadnum) const noexcept;
int CheckNumForName (const char *name, int namespc);
int CheckNumForName (const char *name, int namespc, int wadfile, bool exact = true);
int GetNumForName (const char *name, int namespc);
int CheckNumForName (const char *name, int namespc) const;
int CheckNumForName (const char *name, int namespc, int wadfile, bool exact = true) const;
int GetNumForName (const char *name, int namespc) const;
inline int CheckNumForName (const uint8_t *name) { return CheckNumForName ((const char *)name, ns_global); }
inline int CheckNumForName (const char *name) { return CheckNumForName (name, ns_global); }
inline int CheckNumForName (const uint8_t *name, int ns) { return CheckNumForName ((const char *)name, ns); }
inline int GetNumForName (const char *name) { return GetNumForName (name, ns_global); }
inline int GetNumForName (const uint8_t *name) { return GetNumForName ((const char *)name); }
inline int GetNumForName (const uint8_t *name, int ns) { return GetNumForName ((const char *)name, ns); }
inline int CheckNumForName (const uint8_t *name) const { return CheckNumForName ((const char *)name, ns_global); }
inline int CheckNumForName (const char *name) const { return CheckNumForName (name, ns_global); }
inline int CheckNumForName (const uint8_t *name, int ns) const { return CheckNumForName ((const char *)name, ns); }
inline int GetNumForName (const char *name) const { return GetNumForName (name, ns_global); }
inline int GetNumForName (const uint8_t *name) const { return GetNumForName ((const char *)name); }
inline int GetNumForName (const uint8_t *name, int ns) const { return GetNumForName ((const char *)name, ns); }
int CheckNumForFullName (const char *name, bool trynormal = false, int namespc = ns_global, bool ignoreext = false);
int CheckNumForFullName (const char *name, int wadfile);
int GetNumForFullName (const char *name);
int FindFile(const char* name)
int CheckNumForFullName (const char *cname, bool trynormal = false, int namespc = ns_global, bool ignoreext = false) const;
int CheckNumForFullName (const char *name, int wadfile) const;
int GetNumForFullName (const char *name) const;
int FindFile(const char* name) const
{
return CheckNumForFullName(name);
}
bool FileExists(const char* name)
bool FileExists(const char* name) const
{
return FindFile(name) >= 0;
}
bool FileExists(const std::string& name)
bool FileExists(const std::string& name) const
{
return FindFile(name.c_str()) >= 0;
}
@ -140,7 +141,7 @@ public:
int FindLumpFullName(const char* name, int* lastlump, bool noext = false);
bool CheckFileName (int lump, const char *name); // [RH] True if lump's name == name
int FindFileWithExtensions(const char* name, const char* const* exts, int count);
int FindFileWithExtensions(const char* name, const char* const* exts, int count) const;
int FindResource(int resid, const char* type, int filenum = -1) const noexcept;
int GetResource(int resid, const char* type, int filenum = -1) const;
@ -212,5 +213,4 @@ private:
};
extern FileSystem fileSystem;
}

View file

@ -5,6 +5,8 @@
#include <vector>
#include <string>
namespace FileSys {
struct FileListEntry
{
std::string FileName; // file name only
@ -34,3 +36,4 @@ inline void FixPathSeparator(char* path)
}
}
}

View file

@ -17,9 +17,9 @@
#include <libkern/OSByteOrder.h>
#endif
namespace fs_private
{
namespace FileSys {
namespace byteswap {
#ifdef __APPLE__
inline unsigned short LittleShort(unsigned short x)
@ -117,5 +117,6 @@ inline unsigned int BigLong (unsigned int x)
#endif // __BIG_ENDIAN__
}
}
#endif // __M_SWAP_H__

View file

@ -6,8 +6,10 @@
#include <limits.h>
#include <vector>
#include <string>
#include "files.h"
#include "fs_files.h"
namespace FileSys {
class StringPool;
std::string ExtractBaseName(const char* path, bool include_extension = false);
void strReplace(std::string& str, const char* from, const char* to);
@ -246,7 +248,6 @@ struct FMemoryLump : public FResourceLump
};
}
#endif

View file

@ -46,6 +46,8 @@
#include <stdlib.h>
#include "ancientzip.h"
namespace FileSys {
/****************************************************************
Bit-I/O variables and routines/macros
@ -433,3 +435,5 @@ int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &_In, unsign
}
return 0;
}
}

View file

@ -1,6 +1,8 @@
#pragma once
#include "files.h"
#include "fs_files.h"
namespace FileSys {
class FZipExploder
{
unsigned int Hold, Bits;
@ -41,4 +43,5 @@ public:
int Explode(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize, int flags);
};
int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize);
int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &in, unsigned int insize);
}

View file

@ -40,7 +40,8 @@
#include "fs_findfile.h"
namespace FileSys {
//-----------------------------------------------------------------------
//
// Interface classes to 7z library
@ -374,4 +375,4 @@ FResourceFile *Check7Z(const char *filename, FileReader &file, LumpFilterInfo* f
}
}

View file

@ -40,6 +40,8 @@
#include "fs_findfile.h"
#include "fs_stringpool.h"
namespace FileSys {
std::string FS_FullPath(const char* directory);
#ifdef _WIN32
@ -231,3 +233,4 @@ FResourceFile *CheckDir(const char *filename, bool nosubdirflag, LumpFilterInfo*
return nullptr;
}
}

View file

@ -36,7 +36,8 @@
#include "resourcefile.h"
#include "fs_swap.h"
using namespace fs_private;
namespace FileSys {
using namespace byteswap;
//==========================================================================
//
@ -152,3 +153,4 @@ FResourceFile *CheckGRP(const char *filename, FileReader &file, LumpFilterInfo*
return NULL;
}
}

View file

@ -34,6 +34,7 @@
#include "resourcefile.h"
namespace FileSys {
//==========================================================================
//
// Single lump
@ -93,3 +94,4 @@ FResourceFile *CheckLump(const char *filename, FileReader &file, LumpFilterInfo*
return NULL;
}
}

View file

@ -34,8 +34,9 @@
#include "resourcefile.h"
using namespace fs_private;
namespace FileSys {
using namespace byteswap;
//==========================================================================
//
//
@ -145,3 +146,4 @@ FResourceFile *CheckPak(const char *filename, FileReader &file, LumpFilterInfo*
return NULL;
}
}

View file

@ -36,7 +36,8 @@
#include "resourcefile.h"
#include "fs_swap.h"
using namespace fs_private;
namespace FileSys {
using namespace byteswap;
//==========================================================================
//
@ -260,4 +261,4 @@ FResourceFile *CheckRFF(const char *filename, FileReader &file, LumpFilterInfo*
}
}

View file

@ -35,6 +35,7 @@
#include "resourcefile.h"
namespace FileSys {
//==========================================================================
//
// Build GRP file
@ -152,3 +153,5 @@ FResourceFile* CheckSSI(const char* filename, FileReader& file, LumpFilterInfo*
}
return nullptr;
}
}

View file

@ -35,11 +35,11 @@
#include <ctype.h>
#include "resourcefile.h"
#include "filesystem.h"
#include "fs_filesystem.h"
#include "fs_swap.h"
using namespace fs_private;
namespace FileSys {
using namespace byteswap;
struct wadinfo_t
{
@ -485,3 +485,4 @@ FResourceFile *CheckWad(const char *filename, FileReader &file, LumpFilterInfo*
return NULL;
}
}

View file

@ -38,7 +38,8 @@
#include "fs_stringpool.h"
#include "fs_swap.h"
using namespace fs_private;
namespace FileSys {
using namespace byteswap;
//==========================================================================
//
@ -140,4 +141,5 @@ FResourceFile *CheckWHRes(const char *filename, FileReader &file, LumpFilterInfo
}
return NULL;
}
}

View file

@ -41,7 +41,8 @@
#include "fs_findfile.h"
#include "fs_swap.h"
using namespace fs_private;
namespace FileSys {
using namespace byteswap;
#define BUFREADCOMMENT (0x400)
@ -720,3 +721,5 @@ bool WriteZip(const char* filename, const FCompressedBuffer* content, size_t con
}
return false;
}
}

View file

@ -3,6 +3,7 @@
#include "resourcefile.h"
namespace FileSys {
//==========================================================================
//
// Zip Lump
@ -45,5 +46,6 @@ public:
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
};
}
#endif

View file

@ -34,10 +34,10 @@
*/
#include <string>
#include "files.h"
using namespace fs_private;
#include "fs_files.h"
namespace FileSys {
#ifdef _WIN32
std::wstring toWide(const char* str);
#endif
@ -494,3 +494,5 @@ size_t BufferWriter::Write(const void *buffer, size_t len)
memcpy(&mBuffer[ofs], buffer, len);
return len;
}
}

View file

@ -41,7 +41,10 @@
#include <algorithm>
#include <stdexcept>
#include "files.h"
#include "fs_files.h"
namespace FileSys {
using namespace byteswap;
//==========================================================================
//
@ -538,7 +541,7 @@ class DecompressorLZSS : public DecompressorBase
return false;
Stream.AvailIn -= 2;
uint16_t pos = fs_private::BigShort(*(uint16_t*)Stream.In);
uint16_t pos = BigShort(*(uint16_t*)Stream.In);
uint8_t len = (pos & 0xF)+1;
pos >>= 4;
Stream.In += 2;
@ -752,3 +755,4 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b
}
}
}

View file

@ -41,11 +41,13 @@
#include <ctype.h>
#include <string.h>
#include "filesystem.h"
#include "fs_filesystem.h"
#include "fs_findfile.h"
#include "md5.hpp"
#include "fs_stringpool.h"
namespace FileSys {
// MACROS ------------------------------------------------------------------
#define NULL_INDEX (0xffffffff)
@ -72,7 +74,7 @@ static uint32_t MakeHash(const char* str, size_t length = SIZE_MAX)
static void md5Hash(FileReader& reader, uint8_t* digest)
{
using namespace fs_private::md5;
using namespace md5;
md5_state_t state;
md5_init(&state);
@ -187,8 +189,6 @@ static void PrintLastError (FileSystemMessageFunc Printf);
// PUBLIC DATA DEFINITIONS -------------------------------------------------
FileSystem fileSystem;
// CODE --------------------------------------------------------------------
FileSystem::FileSystem()
@ -511,7 +511,7 @@ int FileSystem::CheckIfResourceFileLoaded (const char *name) noexcept
// and namespace parameter
//==========================================================================
int FileSystem::CheckNumForName (const char *name, int space)
int FileSystem::CheckNumForName (const char *name, int space) const
{
union
{
@ -556,7 +556,7 @@ int FileSystem::CheckNumForName (const char *name, int space)
return i != NULL_INDEX ? i : -1;
}
int FileSystem::CheckNumForName (const char *name, int space, int rfnum, bool exact)
int FileSystem::CheckNumForName (const char *name, int space, int rfnum, bool exact) const
{
union
{
@ -594,7 +594,7 @@ int FileSystem::CheckNumForName (const char *name, int space, int rfnum, bool ex
//
//==========================================================================
int FileSystem::GetNumForName (const char *name, int space)
int FileSystem::GetNumForName (const char *name, int space) const
{
int i;
@ -617,7 +617,7 @@ int FileSystem::GetNumForName (const char *name, int space)
//
//==========================================================================
int FileSystem::CheckNumForFullName (const char *name, bool trynormal, int namespc, bool ignoreext)
int FileSystem::CheckNumForFullName (const char *name, bool trynormal, int namespc, bool ignoreext) const
{
uint32_t i;
@ -650,7 +650,7 @@ int FileSystem::CheckNumForFullName (const char *name, bool trynormal, int names
return -1;
}
int FileSystem::CheckNumForFullName (const char *name, int rfnum)
int FileSystem::CheckNumForFullName (const char *name, int rfnum) const
{
uint32_t i;
@ -678,7 +678,7 @@ int FileSystem::CheckNumForFullName (const char *name, int rfnum)
//
//==========================================================================
int FileSystem::GetNumForFullName (const char *name)
int FileSystem::GetNumForFullName (const char *name) const
{
int i;
@ -698,7 +698,7 @@ int FileSystem::GetNumForFullName (const char *name)
//
//==========================================================================
int FileSystem::FindFileWithExtensions(const char* name, const char *const *exts, int count)
int FileSystem::FindFileWithExtensions(const char* name, const char *const *exts, int count) const
{
uint32_t i;
@ -1254,7 +1254,7 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, std::vector<FolderEntr
if (strncmp(FileInfo[i].LongName, path.c_str(), path.length()) == 0)
{
// Only if it hasn't been replaced.
if ((unsigned)fileSystem.CheckNumForFullName(FileInfo[i].LongName) == i)
if ((unsigned)CheckNumForFullName(FileInfo[i].LongName) == i)
{
FolderEntry fe{ FileInfo[i].LongName, (uint32_t)i };
result.push_back(fe);
@ -1269,13 +1269,13 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, std::vector<FolderEntr
// Find the highest resource file having content in the given folder.
for (auto & entry : result)
{
int thisfile = fileSystem.GetFileContainer(entry.lumpnum);
int thisfile = GetFileContainer(entry.lumpnum);
if (thisfile > maxfile) maxfile = thisfile;
}
// Delete everything from older files.
for (int i = (int)result.size() - 1; i >= 0; i--)
{
if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.erase(result.begin() + i);
if (GetFileContainer(result[i].lumpnum) != maxfile) result.erase(result.begin() + i);
}
}
qsort(result.data(), result.size(), sizeof(FolderEntry), folderentrycmp);
@ -1364,8 +1364,8 @@ FileReader FileSystem::ReopenFileReader(int lump, bool alwayscache)
if (rl->RefCount == 0 && rd != nullptr && !rd->GetBuffer() && !alwayscache && !(rl->Flags & LUMPF_COMPRESSED))
{
int fileno = fileSystem.GetFileContainer(lump);
const char *filename = fileSystem.GetResourceFileFullName(fileno);
int fileno = GetFileContainer(lump);
const char *filename = GetResourceFileFullName(fileno);
FileReader fr;
if (fr.OpenFile(filename, rl->GetFileOffset(), rl->LumpSize))
{
@ -1579,3 +1579,5 @@ FResourceLump* FileSystem::GetFileAt(int no)
{
return FileInfo[no].lump;
}
}

View file

@ -35,7 +35,8 @@
#include "fs_findfile.h"
#include <vector>
namespace FileSys {
enum
{
ZPATH_MAX = 260
@ -404,3 +405,4 @@ bool FS_DirEntryExists(const char* pathname, bool* isdir)
return res;
}
}

View file

@ -38,6 +38,8 @@
#include <string.h>
#include "fs_stringpool.h"
namespace FileSys {
struct StringPool::Block
{
Block *NextBlock;
@ -124,3 +126,5 @@ const char* StringPool::Strdup(const char* str)
strcpy(p, str);
return p;
}
}

View file

@ -1,5 +1,6 @@
#pragma once
namespace FileSys {
// Storage for all the static strings the file system must hold.
class StringPool
{
@ -25,3 +26,4 @@ public:
bool shared;
};
}

View file

@ -69,7 +69,7 @@
#include <stddef.h>
#include <cstring>
namespace fs_private {
namespace FileSys {
/// Provides MD5 hashing functionality
namespace md5 {

View file

@ -39,6 +39,8 @@
#include "md5.hpp"
#include "fs_stringpool.h"
namespace FileSys {
std::string ExtractBaseName(const char* path, bool include_extension)
{
const char* src, * dot;
@ -364,7 +366,7 @@ int lumpcmp(const void * a, const void * b)
void FResourceFile::GenerateHash()
{
// hash the lump directory after sorting
using namespace fs_private::md5;
using namespace FileSys::md5;
auto n = snprintf(Hash, 48, "%08X-%04X-", (unsigned)Reader.GetLength(), NumLumps);
@ -745,4 +747,4 @@ int FExternalLump::FillCache()
}
}

View file

@ -7,6 +7,8 @@
#define FORCE_PACKED
#endif
namespace FileSys {
#pragma pack(1)
// FZipCentralInfo
struct FZipEndOfCentralDirectory
@ -105,4 +107,5 @@ struct FZipLocalFileHeader
// File header flags.
#define ZF_ENCRYPTED 0x1
}
#endif

View file

@ -91,7 +91,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
// Read the font's configuration.
// This will not be done for the default fonts, because they are not atomic and the default content does not need it.
std::vector<FolderEntry> folderdata;
std::vector<FileSys::FolderEntry> folderdata;
if (filetemplate != nullptr)
{
FStringf path("fonts/%s/", filetemplate);
@ -398,7 +398,7 @@ public:
}
};
void FFont::ReadSheetFont(std::vector<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
void FFont::ReadSheetFont(std::vector<FileSys::FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
{
TMap<int, FGameTexture*> charMap;
int minchar = INT_MAX;

View file

@ -58,7 +58,7 @@ struct HexDataSource
//
//==========================================================================
void ParseDefinition(FResourceLump* font)
void ParseDefinition(FileSys::FResourceLump* font)
{
FScanner sc;

View file

@ -124,7 +124,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
FontName = name;
FileData data1 = fileSystem.ReadFile (lump);
auto data1 = fileSystem.ReadFile (lump);
auto data = data1.GetBytes();
if (data[0] == 0xE1 && data[1] == 0xE6 && data[2] == 0xD5 && data[3] == 0x1A)
@ -474,7 +474,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data)
void FSingleLumpFont::CheckFON1Chars()
{
FileData memLump = fileSystem.ReadFile(Lump);
auto memLump = fileSystem.ReadFile(Lump);
auto data = memLump.GetBytes();
const uint8_t* data_p;

View file

@ -109,7 +109,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
int lump = -1;
int folderfile = -1;
std::vector<FolderEntry> folderdata;
std::vector<FileSys::FolderEntry> folderdata;
FStringf path("fonts/%s/", name);
// Use a folder-based font only if it comes from a later file than the single lump version.

View file

@ -175,7 +175,7 @@ protected:
void FixXMoves();
void ReadSheetFont(std::vector<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
void ReadSheetFont(std::vector<FileSys::FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
EFontType Type = EFontType::Unknown;
FName AltFontName = NAME_None;

View file

@ -1519,7 +1519,7 @@ void M_ParseMenuDefs()
DefaultOptionMenuSettings->Reset();
OptionSettings.mLinespacing = 17;
int IWADMenu = fileSystem.CheckNumForName("MENUDEF", ns_global, fileSystem.GetIwadNum());
int IWADMenu = fileSystem.CheckNumForName("MENUDEF", FileSys::ns_global, fileSystem.GetIwadNum());
while ((lump = fileSystem.FindLump ("MENUDEF", &lastlump)) != -1)
{

View file

@ -297,7 +297,7 @@ unsigned FSavegameManagerBase::ExtractSaveData(int index)
!node->bOldVersion &&
(resf = FResourceFile::OpenResourceFile(node->Filename.GetChars(), true)) != nullptr)
{
FResourceLump *info = resf->FindLump("info.json");
auto info = resf->FindLump("info.json");
if (info == nullptr)
{
// this should not happen because the file has already been verified.
@ -315,7 +315,7 @@ unsigned FSavegameManagerBase::ExtractSaveData(int index)
SaveCommentString = ExtractSaveComment(arc);
FResourceLump *pic = resf->FindLump("savepic.png");
auto pic = resf->FindLump("savepic.png");
if (pic != nullptr)
{
FileReader picreader;

View file

@ -172,7 +172,7 @@ unsigned FindModel(const char * path, const char * modelfile, bool silent)
}
int len = fileSystem.FileLength(lump);
FileData lumpd = fileSystem.ReadFile(lump);
auto lumpd = fileSystem.ReadFile(lump);
const char * buffer = lumpd.GetString();
if ( (size_t)fullname.LastIndexOf("_d.3d") == fullname.Len()-5 )

View file

@ -270,7 +270,7 @@ void IQMModel::LoadGeometry()
{
try
{
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
auto lumpdata = fileSystem.ReadFile(mLumpNum);
IQMFileReader reader(lumpdata.GetMem(), (int)lumpdata.GetSize());
Vertices.Resize(NumVertices);

View file

@ -177,7 +177,7 @@ bool FDMDModel::Load(const char * path, int lumpnum, const char * buffer, int le
void FDMDModel::LoadGeometry()
{
static int axis[3] = { VX, VY, VZ };
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
auto lumpdata = fileSystem.ReadFile(mLumpNum);
auto buffer = lumpdata.GetString();
texCoords = new FTexCoord[info.numTexCoords];
memcpy(texCoords, buffer + info.offsetTexCoords, info.numTexCoords * sizeof(FTexCoord));
@ -501,7 +501,7 @@ void FMD2Model::LoadGeometry()
{
static int axis[3] = { VX, VY, VZ };
uint8_t *md2_frames;
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
auto lumpdata = fileSystem.ReadFile(mLumpNum);
auto buffer = lumpdata.GetString();
texCoords = new FTexCoord[info.numTexCoords];

View file

@ -189,7 +189,7 @@ bool FMD3Model::Load(const char * path, int lumpnum, const char * buffer, int le
void FMD3Model::LoadGeometry()
{
FileData lumpdata = fileSystem.ReadFile(mLumpNum);
auto lumpdata = fileSystem.ReadFile(mLumpNum);
auto buffer = lumpdata.GetString();
md3_header_t * hdr = (md3_header_t *)buffer;
md3_surface_t * surf = (md3_surface_t*)(buffer + LittleLong(hdr->Ofs_Surfaces));

View file

@ -70,9 +70,9 @@ bool FUE1Model::Load( const char *filename, int lumpnum, const char *buffer, int
void FUE1Model::LoadGeometry()
{
const char *buffer, *buffer2;
FileData lump = fileSystem.ReadFile(mDataLump);
auto lump = fileSystem.ReadFile(mDataLump);
buffer = lump.GetString();
FileData lump2 = fileSystem.ReadFile(mAnivLump);
auto lump2 = fileSystem.ReadFile(mAnivLump);
buffer2 = lump2.GetString();
// map structures
dhead = (const d3dhead*)(buffer);

View file

@ -161,7 +161,7 @@ FVoxel *R_LoadKVX(int lumpnum)
int mip, maxmipsize;
int i, j, n;
FileData lump = fileSystem.ReadFile(lumpnum); // FileData adds an extra 0 byte to the end.
auto lump = fileSystem.ReadFile(lumpnum); // FileData adds an extra 0 byte to the end.
auto rawvoxel = lump.GetBytes();
int voxelsize = (int)(lump.GetSize()-1);

View file

@ -383,11 +383,11 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump.GetChars());
FileData vp_data = fileSystem.ReadFile(vp_lump);
auto vp_data = fileSystem.ReadFile(vp_lump);
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump, 0);
if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump.GetChars());
FileData fp_data = fileSystem.ReadFile(fp_lump);
auto fp_data = fileSystem.ReadFile(fp_lump);

View file

@ -45,6 +45,7 @@
#include "hw_shadowmap.h"
#include "hw_levelmesh.h"
#include "buffers.h"
#include "files.h"
struct FPortalSceneState;
@ -90,7 +91,6 @@ EXTERN_CVAR(Int, win_h)
EXTERN_CVAR(Bool, win_maximized)
struct FColormap;
class FileWriter;
enum FTextureFormat : uint32_t;
class FModelRenderer;
struct SamplerUniform;

View file

@ -473,7 +473,7 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
{
int lump = fileSystem.CheckNumForFullName(lumpname, 0);
if (lump == -1) I_Error("Unable to load '%s'", lumpname);
FileData data = fileSystem.ReadFile(lump);
auto data = fileSystem.ReadFile(lump);
return GetStringFromLump(lump);
}

View file

@ -72,7 +72,7 @@ FGenericStartScreen::FGenericStartScreen(int max_progress)
: FStartScreen(max_progress)
{
// at this point we do not have a working texture manager yet, so we have to do the lookup via the file system
int startup_lump = fileSystem.CheckNumForName("GZDOOM", ns_graphics);
int startup_lump = fileSystem.CheckNumForName("GZDOOM", FileSys::ns_graphics);
StartupBitmap.Create(640, 480);
ClearBlock(StartupBitmap, { 0, 0, 0, 255 }, 0, 0, 640, 480);

View file

@ -81,9 +81,9 @@ FHexenStartScreen::FHexenStartScreen(int max_progress)
: FStartScreen(max_progress)
{
// at this point we do not have a working texture manager yet, so we have to do the lookup via the file system
int startup_lump = fileSystem.CheckNumForName("STARTUP", ns_graphics);
int netnotch_lump = fileSystem.CheckNumForName("NETNOTCH", ns_graphics);
int notch_lump = fileSystem.CheckNumForName("NOTCH", ns_graphics);
int startup_lump = fileSystem.CheckNumForName("STARTUP", FileSys::ns_graphics);
int netnotch_lump = fileSystem.CheckNumForName("NETNOTCH", FileSys::ns_graphics);
int notch_lump = fileSystem.CheckNumForName("NOTCH", FileSys::ns_graphics);
// For backwards compatibility we also need to look in the default namespace, because these were previously not handled as graphics.
if (startup_lump == -1) startup_lump = fileSystem.CheckNumForName("STARTUP");

View file

@ -119,7 +119,7 @@ FStrifeStartScreen::FStrifeStartScreen(int max_progress)
// Load the animated overlays.
for (size_t i = 0; i < countof(StrifeStartupPicNames); ++i)
{
int lumpnum = fileSystem.CheckNumForName(StrifeStartupPicNames[i], ns_graphics);
int lumpnum = fileSystem.CheckNumForName(StrifeStartupPicNames[i], FileSys::ns_graphics);
if (lumpnum < 0) lumpnum = fileSystem.CheckNumForName(StrifeStartupPicNames[i]);
if (lumpnum >= 0)

View file

@ -103,7 +103,7 @@ FAnmTexture::FAnmTexture (int lumpnum, int w, int h)
void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
anim_t anim;

View file

@ -92,7 +92,7 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion)
{
int x, y;
FileData data = fileSystem.ReadFile (SourceLump);
auto data = fileSystem.ReadFile (SourceLump);
auto indata = data.GetBytes();
PalettedPixels Pixels(Width * Height);

View file

@ -120,7 +120,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto imgz = (const ImageHeader *)lump.GetMem();
const uint8_t *data = (const uint8_t *)&imgz[1];

View file

@ -174,7 +174,7 @@ PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion)
const column_t *maxcol;
int x;
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
const patch_t *patch = (const patch_t *)lump.GetMem();
maxcol = (const column_t *)((const uint8_t *)patch + fileSystem.FileLength (SourceLump) - 3);
@ -284,7 +284,7 @@ void FPatchTexture::DetectBadPatches ()
// Check if this patch is likely to be a problem.
// It must be 256 pixels tall, and all its columns must have exactly
// one post, where each post has a supposed length of 0.
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
const patch_t *realpatch = (patch_t *)lump.GetMem();
const uint32_t *cofs = realpatch->columnofs;
int x, x2 = LittleShort(realpatch->width);

View file

@ -172,7 +172,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
const uint8_t *source_p = source;
uint8_t *dest_p;
@ -204,8 +204,8 @@ int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion)
if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion);
else
{
FileData lump = fileSystem.ReadFile(SourceLump);
FileData plump = fileSystem.ReadFile(mPaletteLump);
auto lump = fileSystem.ReadFile(SourceLump);
auto plump = fileSystem.ReadFile(mPaletteLump);
auto source = lump.GetBytes();
auto psource = plump.GetBytes();
PalEntry paldata[256];

View file

@ -164,7 +164,7 @@ FStartupTexture::FStartupTexture (int lumpnum)
Height = 480;
bUseGamePalette = false;
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
// Initialize the bitmap palette.
@ -233,7 +233,7 @@ void PlanarToChunky(T* dest, const uint8_t* src, const T* remap, int width, int
PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
@ -253,7 +253,7 @@ PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
int FStartupTexture::CopyPixels(FBitmap *bmp, int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
PlanarToChunky((uint32_t*)bmp->GetPixels(), source + 48, startuppalette32, Width, Height);
return 0;
@ -281,7 +281,7 @@ FNotchTexture::FNotchTexture (int lumpnum, int width, int height)
PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
@ -304,7 +304,7 @@ PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
int FNotchTexture::CopyPixels(FBitmap *bmp, int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
auto Work = (uint32_t*)bmp->GetPixels();
@ -338,7 +338,7 @@ FStrifeStartupTexture::FStrifeStartupTexture (int lumpnum, int w, int h)
PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes();
PalettedPixels Pixels(Width*Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);

View file

@ -182,7 +182,7 @@ void FGameTexture::AddAutoMaterials()
if (this->*(layer.pointer) == nullptr) // only if no explicit assignment had been done.
{
FStringf lookup("%s%s%s", layer.path, fullname ? "" : "auto/", searchname.GetChars());
auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true);
auto lump = fileSystem.CheckNumForFullName(lookup, false, FileSys::ns_global, true);
if (lump != -1)
{
auto bmtex = TexMan.FindGameTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny);
@ -199,7 +199,7 @@ void FGameTexture::AddAutoMaterials()
if (!this->Layers || this->Layers.get()->*(layer.pointer) == nullptr) // only if no explicit assignment had been done.
{
FStringf lookup("%s%s%s", layer.path, fullname ? "" : "auto/", searchname.GetChars());
auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true);
auto lump = fileSystem.CheckNumForFullName(lookup, false, FileSys::ns_global, true);
if (lump != -1)
{
auto bmtex = TexMan.FindGameTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny);

View file

@ -47,7 +47,6 @@ enum ESSType
SS_BGRA
};
class FileWriter;
// PNG Writing --------------------------------------------------------------
// Start writing an 8-bit palettized PNG file.
@ -82,13 +81,13 @@ struct PNGHandle
uint32_t Size;
};
FileReader File;
FileSys::FileReader File;
bool bDeleteFilePtr;
TArray<Chunk> Chunks;
TArray<char *> TextChunks;
unsigned int ChunkPt;
PNGHandle(FileReader &file);
PNGHandle(FileSys::FileReader &file);
~PNGHandle();
};
@ -96,7 +95,7 @@ struct PNGHandle
// the signature, but also checking for the IEND chunk. CRC checking of
// each chunk is not done. If it is valid, you get a PNGHandle to pass to
// the following functions.
PNGHandle *M_VerifyPNG (FileReader &file);
PNGHandle *M_VerifyPNG (FileSys::FileReader &file);
// Finds a chunk in a PNG file. The file pointer will be positioned at the
// beginning of the chunk data, and its length will be returned. A return
@ -115,7 +114,7 @@ bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buf
// The file must be positioned at the start of the first IDAT. It reads
// image data into the provided buffer. Returns true on success.
bool M_ReadIDAT (FileReader &file, uint8_t *buffer, int width, int height, int pitch,
bool M_ReadIDAT (FileSys::FileReader &file, uint8_t *buffer, int width, int height, int pitch,
uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int idatlen);

View file

@ -397,12 +397,12 @@ void FMultipatchTextureBuilder::AddTexturesLumps(int lump1, int lump2, int patch
if (lump1 >= 0)
{
FileData texdir = fileSystem.ReadFile(lump1);
auto texdir = fileSystem.ReadFile(lump1);
AddTexturesLump(texdir.GetMem(), fileSystem.FileLength(lump1), lump1, patcheslump, firstdup, true);
}
if (lump2 >= 0)
{
FileData texdir = fileSystem.ReadFile(lump2);
auto texdir = fileSystem.ReadFile(lump2);
AddTexturesLump(texdir.GetMem(), fileSystem.FileLength(lump2), lump2, patcheslump, firstdup, false);
}
}

View file

@ -50,6 +50,7 @@
#include "basics.h"
#include "cmdlib.h"
using namespace FileSys;
FTextureManager TexMan;

View file

@ -1018,7 +1018,7 @@ void uppercopy(char* to, const char* from)
FString GetStringFromLump(int lump)
{
FileData fd = fileSystem.ReadFile(lump);
auto fd = fileSystem.ReadFile(lump);
FString ScriptBuffer(fd.GetString(), fd.GetSize());
ScriptBuffer.Truncate(strlen(ScriptBuffer.GetChars())); // this is necessary to properly truncate the generated string to not contain 0 bytes.
return ScriptBuffer;

View file

@ -12,6 +12,7 @@
#include <stdarg.h>
#include <time.h>
#include "zstring.h"
#include "files.h"
#if !defined(GUID_DEFINED)
#define GUID_DEFINED
@ -82,7 +83,6 @@ inline constexpr double Scale(double a, double b, double c)
return (a * b) / c;
}
class FileReader;
struct MD5Context;
void md5Update(FileReader& file, MD5Context& md5, unsigned len);

View file

@ -6,6 +6,7 @@
inline ZMusicCustomReader *GetMusicReader(FileReader& fr)
{
using FileSys::FileReaderInterface;
auto zcr = new ZMusicCustomReader;
zcr->handle = fr.GetInterface();

View file

@ -139,11 +139,11 @@ void D_AddWildFile(std::vector<std::string>& wadfiles, const char* value, const
else
{
// Try pattern matching
FileList list;
FileSys::FileList list;
auto path = ExtractFilePath(value);
auto name = ExtractFileBase(value, true);
if (path.IsEmpty()) path = ".";
if (ScanDirectory(list, path, name, true))
if (FileSys::ScanDirectory(list, path, name, true))
{
for(auto& entry : list)
{
@ -193,8 +193,8 @@ void D_AddConfigFiles(std::vector<std::string>& wadfiles, const char* section, c
void D_AddDirectory(std::vector<std::string>& wadfiles, const char* dir, const char *filespec, FConfigFile* config)
{
FileList list;
if (ScanDirectory(list, dir, "*.wad", true))
FileSys::FileList list;
if (FileSys::ScanDirectory(list, dir, "*.wad", true))
{
for (auto& entry : list)
{

View file

@ -929,7 +929,7 @@ int ReadPalette(int lumpnum, uint8_t* buffer)
{
return 0;
}
FileData lump = fileSystem.ReadFile(lumpnum);
auto lump = fileSystem.ReadFile(lumpnum);
auto lumpmem = lump.GetBytes();
memset(buffer, 0, 768);

View file

@ -34,7 +34,7 @@
#ifndef __S_PLAYLIST_H__
#define __S_PLAYLIST_H__
class FileReader;
#include "files.h"
class FPlayList
{

View file

@ -40,6 +40,7 @@
#include <string>
#include "tarray.h"
#include "utf8.h"
#include "filesystem.h"
#ifdef __GNUC__
#define PRINTFISH(x) __attribute__((format(printf, 2, x)))
@ -117,8 +118,6 @@ enum ELumpNum
{
};
class FileSystem;
class FString
{
public: