mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-10 23:01:59 +00:00
- file system update from Raze
* support for SSI container format - this is an obscure format used by a few Duke Nukem mods - added to have this subsystem identical between both engines. * removed some dead wrapper code * made the Open methods local to their implementations, this was never called virtually.
This commit is contained in:
parent
79ac41c5b3
commit
8a0634ed0d
15 changed files with 171 additions and 98 deletions
|
@ -1106,6 +1106,7 @@ set (PCH_SOURCES
|
|||
common/filesystem/file_zip.cpp
|
||||
common/filesystem/file_pak.cpp
|
||||
common/filesystem/file_whres.cpp
|
||||
common/filesystem/file_ssi.cpp
|
||||
common/filesystem/file_directory.cpp
|
||||
common/filesystem/resourcefile.cpp
|
||||
common/engine/cycler.cpp
|
||||
|
|
|
@ -367,7 +367,7 @@ FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet, LumpF
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
if (!memcmp(head, k7zSignature, k7zSignatureSize))
|
||||
{
|
||||
FResourceFile *rf = new F7ZFile(filename, file);
|
||||
auto rf = new F7ZFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
|
|
|
@ -254,9 +254,9 @@ int FDirectoryLump::FillCache()
|
|||
|
||||
FResourceFile *CheckDir(const char *filename, bool quiet, bool nosubdirflag, LumpFilterInfo* filter)
|
||||
{
|
||||
FResourceFile *rf = new FDirectory(filename, nosubdirflag);
|
||||
auto rf = new FDirectory(filename, nosubdirflag);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
delete rf;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet, Lump
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
if (!memcmp(head, "KenSilverman", 12))
|
||||
{
|
||||
FResourceFile *rf = new FGrpFile(filename, file);
|
||||
auto rf = new FGrpFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
|
|
|
@ -94,7 +94,7 @@ bool FLumpFile::Open(bool quiet, LumpFilterInfo*)
|
|||
FResourceFile *CheckLump(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter)
|
||||
{
|
||||
// always succeeds
|
||||
FResourceFile *rf = new FLumpFile(filename, file);
|
||||
auto rf = new FLumpFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
delete rf;
|
||||
|
|
|
@ -134,7 +134,7 @@ FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet, Lump
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
if (!memcmp(head, "PACK", 4))
|
||||
{
|
||||
FResourceFile *rf = new FPakFile(filename, file);
|
||||
auto rf = new FPakFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
|
|
|
@ -248,7 +248,7 @@ FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet, Lump
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
if (!memcmp(head, "RFF\x1a", 4))
|
||||
{
|
||||
FResourceFile *rf = new FRFFFile(filename, file);
|
||||
auto rf = new FRFFFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
|
|
155
src/common/filesystem/file_ssi.cpp
Normal file
155
src/common/filesystem/file_ssi.cpp
Normal file
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
** file_grp.cpp
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 1998-2009 Randy Heit
|
||||
** Copyright 2005-2020 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
**
|
||||
*/
|
||||
|
||||
#include "resourcefile.h"
|
||||
#include "printf.h"
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Build GRP file
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
class FSSIFile : public FUncompressedFile
|
||||
{
|
||||
public:
|
||||
FSSIFile(const char * filename, FileReader &file);
|
||||
bool Open(bool quiet, int version, int lumpcount, LumpFilterInfo* filter);
|
||||
};
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Initializes a Build GRP file
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FSSIFile::FSSIFile(const char *filename, FileReader &file)
|
||||
: FUncompressedFile(filename, file)
|
||||
{
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Open it
|
||||
// Note that SSIs can contain embedded GRPs which must be flagged accordingly.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FSSIFile::Open(bool quiet, int version, int lumpcount, LumpFilterInfo*)
|
||||
{
|
||||
NumLumps = lumpcount*2;
|
||||
Lumps.Resize(lumpcount*2);
|
||||
|
||||
|
||||
int32_t j = (version == 2 ? 267 : 254) + (lumpcount * 121);
|
||||
for (int i = 0; i < NumLumps; i+=2)
|
||||
{
|
||||
char fn[13];
|
||||
int strlength = Reader.ReadUInt8();
|
||||
if (strlength > 12) strlength = 12;
|
||||
|
||||
Reader.Read(fn, 12);
|
||||
fn[strlength] = 0;
|
||||
int flength = Reader.ReadInt32();
|
||||
|
||||
|
||||
Lumps[i].LumpNameSetup(fn);
|
||||
Lumps[i].Position = j;
|
||||
Lumps[i].LumpSize = flength;
|
||||
Lumps[i].Owner = this;
|
||||
if (strstr(fn, ".GRP")) Lumps[i].Flags |= LUMPF_EMBEDDED;
|
||||
|
||||
// SSI files can swap the order of the extension's characters - but there's no reliable detection for this and it can be mixed inside the same container,
|
||||
// so we have no choice but to create another file record for the altered name.
|
||||
std::swap(fn[strlength - 1], fn[strlength - 3]);
|
||||
Lumps[i+1].LumpNameSetup(fn);
|
||||
Lumps[i+1].Position = j;
|
||||
Lumps[i+1].LumpSize = flength;
|
||||
Lumps[i+1].Owner = this;
|
||||
if (strstr(fn, ".GRP")) Lumps[i+1].Flags |= LUMPF_EMBEDDED;
|
||||
|
||||
j += flength;
|
||||
|
||||
Reader.Seek(104, FileReader::SeekCur);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// File open
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FResourceFile* CheckSSI(const char* filename, FileReader& file, bool quiet, LumpFilterInfo* filter)
|
||||
{
|
||||
char zerobuf[72];
|
||||
char buf[72];
|
||||
memset(zerobuf, 0, 72);
|
||||
|
||||
auto skipstring = [&](int length)
|
||||
{
|
||||
int strlength = file.ReadUInt8();
|
||||
if (strlength > length) return false;
|
||||
int count = file.Read(buf, length);
|
||||
buf[length] = 0;
|
||||
if (count != length || strlen(buf) != strlength) return false;
|
||||
if (length != strlength && memcmp(buf + strlength, zerobuf, length - strlength)) return false;
|
||||
return true;
|
||||
};
|
||||
if (file.GetLength() >= 12)
|
||||
{
|
||||
// check if SSI
|
||||
// this performs several checks because there is no "SSI" magic
|
||||
int version = file.ReadInt32();
|
||||
if (version == 1 || version == 2) // if
|
||||
{
|
||||
int numfiles = file.ReadInt32();
|
||||
if (!skipstring(32)) return nullptr;
|
||||
if (version == 2 && !skipstring(12)) return nullptr;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (!skipstring(70)) return nullptr;
|
||||
}
|
||||
auto ssi = new FSSIFile(filename, file);
|
||||
if (ssi->Open(filename, version, numfiles, filter)) return ssi;
|
||||
file = std::move(ssi->Reader); // to avoid destruction of reader
|
||||
delete ssi;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
|
@ -70,8 +70,8 @@ public:
|
|||
|
||||
int GetNamespace() const override { return Namespace; }
|
||||
|
||||
int GetFileOffset() { return Position; }
|
||||
FileReader *GetReader()
|
||||
int GetFileOffset() override { return Position; }
|
||||
FileReader *GetReader() override
|
||||
{
|
||||
if(!Compressed)
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
int FillCache()
|
||||
int FillCache() override
|
||||
{
|
||||
if(!Compressed)
|
||||
{
|
||||
|
@ -472,7 +472,7 @@ FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet, Lump
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4))
|
||||
{
|
||||
FResourceFile *rf = new FWadFile(filename, file);
|
||||
auto rf = new FWadFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
|
|
|
@ -148,7 +148,7 @@ FResourceFile *CheckWHRes(const char *filename, FileReader &file, bool quiet, Lu
|
|||
if (offset != checkpos || length <= 0) return nullptr;
|
||||
checkpos += (length+4095) / 4096;
|
||||
}
|
||||
FResourceFile *rf = new FWHResFile(filename, file);
|
||||
auto rf = new FWHResFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
delete rf;
|
||||
|
|
|
@ -464,7 +464,7 @@ FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet, Lump
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
if (!memcmp(head, "PK\x3\x4", 4))
|
||||
{
|
||||
FResourceFile *rf = new FZipFile(filename, file);
|
||||
auto rf = new FZipFile(filename, file);
|
||||
if (rf->Open(quiet, filter)) return rf;
|
||||
|
||||
file = std::move(rf->Reader); // to avoid destruction of reader
|
||||
|
|
|
@ -1634,79 +1634,8 @@ static void PrintLastError ()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FResourceLump *FileSystem::Lookup(const char *name, const char *type)
|
||||
{
|
||||
FStringf fname("%s.%s", name, type);
|
||||
auto lump = FindFile(fname);
|
||||
if (lump >= 0) return FileInfo[lump].lump;
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
FResourceLump *FileSystem::Lookup(unsigned int id, const char *type)
|
||||
{
|
||||
auto lump = FindResource(id, type);
|
||||
if (lump >= 0) return FileInfo[lump].lump;
|
||||
else return nullptr;
|
||||
}
|
||||
FResourceLump* FileSystem::GetFileAt(int no)
|
||||
{
|
||||
return FileInfo[no].lump;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Stand-ins for Blood's resource class
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
const void *FileSystem::Lock(int lump)
|
||||
{
|
||||
if ((size_t)lump >= FileInfo.Size()) return nullptr;
|
||||
auto lumpp = FileInfo[lump].lump;
|
||||
return lumpp->Lock();
|
||||
}
|
||||
|
||||
void FileSystem::Unlock(int lump)
|
||||
{
|
||||
if ((size_t)lump >= FileInfo.Size()) return;
|
||||
auto lumpp = FileInfo[lump].lump;
|
||||
lumpp->Unlock();
|
||||
}
|
||||
|
||||
const void *FileSystem::Get(int lump)
|
||||
{
|
||||
if ((size_t)lump >= FileInfo.Size()) return nullptr;
|
||||
auto lumpp = FileInfo[lump].lump;
|
||||
auto p = lumpp->Lock();
|
||||
lumpp->RefCount = INT_MAX/2; // lock forever.
|
||||
return p;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Stand-ins for Blood's resource class
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
const void *FileSystem::Lock(FResourceLump *lump)
|
||||
{
|
||||
if (lump) return lump->Lock();
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
void FileSystem::Unlock(FResourceLump *lump)
|
||||
{
|
||||
if (lump) lump->Unlock();
|
||||
}
|
||||
|
||||
const void *FileSystem::Load(FResourceLump *lump)
|
||||
{
|
||||
if (lump)
|
||||
{
|
||||
auto p = lump->Lock();
|
||||
lump->RefCount = INT_MAX/2; // lock forever.
|
||||
return p;
|
||||
}
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -187,20 +187,8 @@ public:
|
|||
int AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags);
|
||||
FileReader* GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
|
||||
void InitHashChains();
|
||||
|
||||
// Blood stuff
|
||||
FResourceLump* Lookup(const char* name, const char* type);
|
||||
FResourceLump* Lookup(unsigned int id, const char* type);
|
||||
|
||||
FResourceLump* GetFileAt(int no);
|
||||
|
||||
const void* Lock(int lump);
|
||||
void Unlock(int lump);
|
||||
const void* Get(int lump);
|
||||
static const void* Lock(FResourceLump* lump);
|
||||
static void Unlock(FResourceLump* lump);
|
||||
static const void* Load(FResourceLump* lump);;
|
||||
|
||||
protected:
|
||||
|
||||
struct LumpRecord;
|
||||
|
|
|
@ -240,10 +240,11 @@ FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet, Lump
|
|||
FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter);
|
||||
FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter);
|
||||
FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter);
|
||||
FResourceFile* CheckSSI(const char* filename, FileReader& file, bool quiet, LumpFilterInfo* filter);
|
||||
FResourceFile *CheckLump(const char *filename,FileReader &file, bool quiet, LumpFilterInfo* filter);
|
||||
FResourceFile *CheckDir(const char *filename, bool quiet, bool nosub, LumpFilterInfo* filter);
|
||||
|
||||
static CheckFunc funcs[] = { CheckWad, CheckZip, Check7Z, CheckPak, CheckGRP, CheckRFF, CheckLump };
|
||||
static CheckFunc funcs[] = { CheckWad, CheckZip, Check7Z, CheckPak, CheckGRP, CheckRFF, CheckSSI, CheckLump };
|
||||
|
||||
FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly, LumpFilterInfo* filter)
|
||||
{
|
||||
|
|
|
@ -164,7 +164,6 @@ public:
|
|||
const FString &GetHash() const { return Hash; }
|
||||
|
||||
|
||||
virtual bool Open(bool quiet, LumpFilterInfo* filter) = 0;
|
||||
virtual FResourceLump *GetLump(int no) = 0;
|
||||
FResourceLump *FindLump(const char *name);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue