diff --git a/src/common/filesystem/include/fs_files.h b/src/common/filesystem/include/fs_files.h index e732824974..c3404a5689 100644 --- a/src/common/filesystem/include/fs_files.h +++ b/src/common/filesystem/include/fs_files.h @@ -101,31 +101,6 @@ public: long GetLength () const { return Length; } }; -class MemoryReader : public FileReaderInterface -{ -protected: - const char * bufptr = nullptr; - long FilePos = 0; - - MemoryReader() - {} - -public: - MemoryReader(const char *buffer, long length) - { - bufptr = buffer; - Length = length; - FilePos = 0; - } - - long Tell() const override; - long Seek(long offset, int origin) override; - long Read(void *buffer, long len) override; - char *Gets(char *strbuf, int len) override; - virtual const char *GetBuffer() const override { return bufptr; } -}; - - struct FResourceLump; class FileReader @@ -329,24 +304,6 @@ public: friend class FileSystem; }; -class DecompressorBase : public FileReaderInterface -{ - bool exceptions = false; -public: - // These do not work but need to be defined to satisfy the FileReaderInterface. - // They will just error out when called. - long Tell() const override; - long Seek(long offset, int origin) override; - char* Gets(char* strbuf, int len) override; - void DecompressionError(const char* error, ...) const; - void SetOwnsReader(); - void EnableExceptions(bool on) { exceptions = on; } - -protected: - FileReader* File = nullptr; - FileReader OwnedFile; -}; - class FileWriter { diff --git a/src/common/filesystem/include/fs_filesystem.h b/src/common/filesystem/include/fs_filesystem.h index e976733143..b559494084 100644 --- a/src/common/filesystem/include/fs_filesystem.h +++ b/src/common/filesystem/include/fs_filesystem.h @@ -13,9 +13,6 @@ namespace FileSys { -class FResourceFile; -struct FResourceLump; - union LumpShortName { char String[9]; diff --git a/src/common/filesystem/include/resourcefile.h b/src/common/filesystem/include/resourcefile.h index 91d437d388..f714c79954 100644 --- a/src/common/filesystem/include/resourcefile.h +++ b/src/common/filesystem/include/resourcefile.h @@ -197,56 +197,6 @@ public: FResourceLump *FindLump(const char *name); }; -struct FUncompressedLump : public FResourceLump -{ - int Position; - - virtual FileReader *GetReader(); - virtual int FillCache() override; - virtual int GetFileOffset() { return Position; } - -}; - - -// Base class for uncompressed resource files (WAD, GRP, PAK and single lumps) -class FUncompressedFile : public FResourceFile -{ -protected: - TArray Lumps; - - FUncompressedFile(const char *filename, StringPool* sp); - FUncompressedFile(const char *filename, FileReader &r, StringPool* sp); - virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } -}; - - -// should only be used internally. -struct FExternalLump : public FResourceLump -{ - const char* FileName; - - FExternalLump(const char *_filename, int filesize, StringPool* sp); - virtual int FillCache() override; - -}; - -struct FMemoryLump : public FResourceLump -{ - FMemoryLump(const void* data, int length) - { - RefCount = INT_MAX / 2; - LumpSize = length; - Cache = new char[length]; - memcpy(Cache, data, length); - } - - virtual int FillCache() override - { - RefCount = INT_MAX / 2; // Make sure it never counts down to 0 by resetting it to something high each time it is used. - return 1; - } -}; - } diff --git a/src/common/filesystem/source/file_grp.cpp b/src/common/filesystem/source/file_grp.cpp index bd543a5592..b289b121d6 100644 --- a/src/common/filesystem/source/file_grp.cpp +++ b/src/common/filesystem/source/file_grp.cpp @@ -33,7 +33,7 @@ ** */ -#include "resourcefile.h" +#include "resourcefile_internal.h" #include "fs_swap.h" namespace FileSys { diff --git a/src/common/filesystem/source/file_lump.cpp b/src/common/filesystem/source/file_lump.cpp index c9885a1269..ad4406a0f4 100644 --- a/src/common/filesystem/source/file_lump.cpp +++ b/src/common/filesystem/source/file_lump.cpp @@ -32,7 +32,7 @@ ** */ -#include "resourcefile.h" +#include "resourcefile_internal.h" namespace FileSys { //========================================================================== diff --git a/src/common/filesystem/source/file_pak.cpp b/src/common/filesystem/source/file_pak.cpp index c8c039209c..4e3b3ef931 100644 --- a/src/common/filesystem/source/file_pak.cpp +++ b/src/common/filesystem/source/file_pak.cpp @@ -32,7 +32,7 @@ ** */ -#include "resourcefile.h" +#include "resourcefile_internal.h" namespace FileSys { diff --git a/src/common/filesystem/source/file_rff.cpp b/src/common/filesystem/source/file_rff.cpp index edb003810c..1d3cf15bf0 100644 --- a/src/common/filesystem/source/file_rff.cpp +++ b/src/common/filesystem/source/file_rff.cpp @@ -33,7 +33,7 @@ ** */ -#include "resourcefile.h" +#include "resourcefile_internal.h" #include "fs_swap.h" namespace FileSys { diff --git a/src/common/filesystem/source/file_ssi.cpp b/src/common/filesystem/source/file_ssi.cpp index 0e48ef49d7..4b68997f0f 100644 --- a/src/common/filesystem/source/file_ssi.cpp +++ b/src/common/filesystem/source/file_ssi.cpp @@ -33,7 +33,7 @@ ** */ -#include "resourcefile.h" +#include "resourcefile_internal.h" namespace FileSys { //========================================================================== diff --git a/src/common/filesystem/source/file_whres.cpp b/src/common/filesystem/source/file_whres.cpp index 41e418773e..efdfd5d395 100644 --- a/src/common/filesystem/source/file_whres.cpp +++ b/src/common/filesystem/source/file_whres.cpp @@ -34,7 +34,7 @@ ** */ -#include "resourcefile.h" +#include "resourcefile_internal.h" #include "fs_stringpool.h" #include "fs_swap.h" diff --git a/src/common/filesystem/source/files.cpp b/src/common/filesystem/source/files.cpp index 4d92cc25cd..5cb1bd3439 100644 --- a/src/common/filesystem/source/files.cpp +++ b/src/common/filesystem/source/files.cpp @@ -34,7 +34,7 @@ */ #include -#include "fs_files.h" +#include "files_internal.h" namespace FileSys { diff --git a/src/common/filesystem/source/files_decompress.cpp b/src/common/filesystem/source/files_decompress.cpp index 5948177cf5..86529716a5 100644 --- a/src/common/filesystem/source/files_decompress.cpp +++ b/src/common/filesystem/source/files_decompress.cpp @@ -46,6 +46,26 @@ namespace FileSys { using namespace byteswap; + +class DecompressorBase : public FileReaderInterface +{ + bool exceptions = false; +public: + // These do not work but need to be defined to satisfy the FileReaderInterface. + // They will just error out when called. + long Tell() const override; + long Seek(long offset, int origin) override; + char* Gets(char* strbuf, int len) override; + void DecompressionError(const char* error, ...) const; + void SetOwnsReader(); + void EnableExceptions(bool on) { exceptions = on; } + +protected: + FileReader* File = nullptr; + FileReader OwnedFile; +}; + + //========================================================================== // // DecompressionError diff --git a/src/common/filesystem/source/files_internal.h b/src/common/filesystem/source/files_internal.h new file mode 100644 index 0000000000..34e73a0701 --- /dev/null +++ b/src/common/filesystem/source/files_internal.h @@ -0,0 +1,31 @@ +#pragma once + +#include "fs_files.h" + +namespace FileSys { + +class MemoryReader : public FileReaderInterface +{ +protected: + const char * bufptr = nullptr; + long FilePos = 0; + + MemoryReader() + {} + +public: + MemoryReader(const char *buffer, long length) + { + bufptr = buffer; + Length = length; + FilePos = 0; + } + + long Tell() const override; + long Seek(long offset, int origin) override; + long Read(void *buffer, long len) override; + char *Gets(char *strbuf, int len) override; + virtual const char *GetBuffer() const override { return bufptr; } +}; + +} diff --git a/src/common/filesystem/source/filesystem.cpp b/src/common/filesystem/source/filesystem.cpp index c8623765e1..2344f09cc4 100644 --- a/src/common/filesystem/source/filesystem.cpp +++ b/src/common/filesystem/source/filesystem.cpp @@ -41,6 +41,7 @@ #include #include +#include "resourcefile_internal.h" #include "fs_filesystem.h" #include "fs_findfile.h" #include "md5.hpp" @@ -320,10 +321,21 @@ int FileSystem::AddExternalFile(const char *filename) // //========================================================================== +struct FMemoryLump : public FResourceLump +{ + FMemoryLump(const void* data, int length) + { + RefCount = -1; + LumpSize = length; + Cache = new char[length]; + memcpy(Cache, data, length); + } +}; + int FileSystem::AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags) { std::string fullname = name; - fullname += ':'; + fullname += '.'; fullname += type; auto newlump = new FMemoryLump(data, size); newlump->LumpNameSetup(fullname.c_str(), stringpool); diff --git a/src/common/filesystem/source/resourcefile.cpp b/src/common/filesystem/source/resourcefile.cpp index 8a17c09a0a..079998df9c 100644 --- a/src/common/filesystem/source/resourcefile.cpp +++ b/src/common/filesystem/source/resourcefile.cpp @@ -35,9 +35,10 @@ */ #include -#include "resourcefile.h" +#include "resourcefile_internal.h" #include "md5.hpp" #include "fs_stringpool.h" +#include "files_internal.h" namespace FileSys { diff --git a/src/common/filesystem/source/resourcefile_internal.h b/src/common/filesystem/source/resourcefile_internal.h new file mode 100644 index 0000000000..4371a7460a --- /dev/null +++ b/src/common/filesystem/source/resourcefile_internal.h @@ -0,0 +1,38 @@ +#pragma once + +#include "resourcefile.h" + +namespace FileSys { +struct FUncompressedLump : public FResourceLump +{ + int Position; + + virtual FileReader *GetReader(); + virtual int FillCache() override; + virtual int GetFileOffset() { return Position; } + +}; + +// Base class for uncompressed resource files (WAD, GRP, PAK and single lumps) +class FUncompressedFile : public FResourceFile +{ +protected: + TArray Lumps; + + FUncompressedFile(const char *filename, StringPool* sp); + FUncompressedFile(const char *filename, FileReader &r, StringPool* sp); + virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } +}; + + +// should only be used internally. +struct FExternalLump : public FResourceLump +{ + const char* FileName; + + FExternalLump(const char *_filename, int filesize, StringPool* sp); + virtual int FillCache() override; + +}; + +} \ No newline at end of file