- moved kopenfilereader into the FileSystem class.

This commit is contained in:
Christoph Oelckers 2019-12-07 10:14:51 +01:00
parent ef87d2d4f9
commit 749eda32c5
39 changed files with 70 additions and 71 deletions

View file

@ -166,7 +166,7 @@ int RFS::Open(const char *fileName)
{
strcpy(_fileName, fileName);
auto hFile = kopenFileReader(fileName, 0);
auto hFile = fileSystem.OpenFileReader(fileName, 0);
if (!hFile.isOpen()) {
initprintf("BARF: Error opening file %s", _fileName);
return 1;

View file

@ -160,14 +160,14 @@ FileReader credKOpen4Load(char *&pzFile)
if (pzFile[i] == '\\')
pzFile[i] = '/';
}
auto nHandle = kopenFileReader(pzFile, 0);
auto nHandle = fileSystem.OpenFileReader(pzFile, 0);
if (!nHandle.isOpen())
{
// Hack
if (nLen >= 3 && isalpha(pzFile[0]) && pzFile[1] == ':' && pzFile[2] == '/')
{
pzFile += 3;
nHandle = kopenFileReader(pzFile, 0);
nHandle = fileSystem.OpenFileReader(pzFile, 0);
}
}
return nHandle;

View file

@ -130,7 +130,7 @@ void IniFile::Load()
curNode = &head;
auto fp = kopenFileReader(fileName, 0);
auto fp = fileSystem.OpenFileReader(fileName, 0);
if (fp.isOpen())
{
int nSize = fp.GetLength();

View file

@ -216,7 +216,7 @@ void sndStartWavDisk(const char *pzFile, int nVolume, int nChannel)
pChannel = &Channel[nChannel];
if (pChannel->at0 > 0)
sndKillSound(pChannel);
auto hFile = kopenFileReader(pzFile, 0);
auto hFile = fileSystem.OpenFileReader(pzFile, 0);
if (!hFile.isOpen())
return;
int nLength = hFile.GetLength();

View file

@ -86,12 +86,12 @@ int tileInit(char a1, const char *a2)
for (int i = 0; i < kMaxTiles; i++)
voxelIndex[i] = 0;
auto hFile = kopenFileReader("SURFACE.DAT", 0);
auto hFile = fileSystem.OpenFileReader("SURFACE.DAT", 0);
if (hFile.isOpen())
{
hFile.Read(surfType, sizeof(surfType));
}
hFile = kopenFileReader("VOXEL.DAT", 0);
hFile = fileSystem.OpenFileReader("VOXEL.DAT", 0);
if (hFile.isOpen())
{
hFile.Read(voxelIndex, sizeof(voxelIndex));
@ -100,7 +100,7 @@ int tileInit(char a1, const char *a2)
voxelIndex[i] = B_LITTLE16(voxelIndex[i]);
#endif
}
hFile = kopenFileReader("SHADE.DAT", 0);
hFile = fileSystem.OpenFileReader("SHADE.DAT", 0);
if (hFile.isOpen())
{
hFile.Read(tileShade, sizeof(tileShade));

View file

@ -18,15 +18,6 @@ extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (e
#include "filesystem/filesystem.h"
// Wrappers for the handle based API to get rid of the direct calls without any actual changes to the implementation.
// These are now getting redirected to the file system so that the implementation here can be gutted without making changes to the calling code.
inline FileReader kopenFileReader(const char* name, int where)
{
auto lump = fileSystem.FindFile(name);
if (lump < 0) return FileReader();
else return fileSystem.OpenFileReader(lump);
}
// This is only here to mark a file as not being part of the game assets (e.g. savegames)
// These should be handled differently (e.g read from a userdata directory or similar things.)
inline FileReader fopenFileReader(const char* name, int where)

View file

@ -2596,7 +2596,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
FileReader fil = kopenFileReader(fn, 0);
FileReader fil = fileSystem.OpenFileReader(fn, 0);
if (!fil.isOpen())
{
initprintf("Error: basepalette: Failed opening \"%s\" on line %s:%d\n", fn,
@ -2770,7 +2770,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
FileReader fil = kopenFileReader(fn, 0);
FileReader fil = fileSystem.OpenFileReader(fn, 0);
if (!fil.isOpen())
{
initprintf("Error: palookup: Failed opening \"%s\" on line %s:%d\n", fn,
@ -3063,7 +3063,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
FileReader fil = kopenFileReader(fn, 0);
FileReader fil = fileSystem.OpenFileReader(fn, 0);
if (!fil.isOpen())
{
initprintf("Error: blendtable: Failed opening \"%s\" on line %s:%d\n", fn,

View file

@ -9447,7 +9447,7 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t
flags &= 3;
FileReader fr = kopenFileReader(filename, 0);
FileReader fr = fileSystem.OpenFileReader(filename, 0);
if (!fr.isOpen())
{ mapversion = 7; return -1; }
@ -9639,7 +9639,7 @@ int32_t engineLoadBoardV5V6(const char *filename, char fromwhere, vec3_t *dapos,
struct walltypev6 v6wall;
struct spritetypev6 v6spr;
FileReader fr = kopenFileReader(filename, fromwhere);
FileReader fr = fileSystem.OpenFileReader(filename, fromwhere);
if (!fr.isOpen())
{ mapversion = 5L; return -1; }
@ -10109,7 +10109,7 @@ void videoNextPage(void)
int32_t qloadkvx(int32_t voxindex, const char *filename)
{
auto fil = kopenFileReader(filename, 0);
auto fil = fileSystem.OpenFileReader(filename, 0);
if (!fil.isOpen())
return -1;

View file

@ -1862,7 +1862,7 @@ mdmodel_t *mdload(const char *filnam)
vm = (mdmodel_t *)voxload(filnam);
if (vm) return vm;
auto fil = kopenFileReader(filnam,0);
auto fil = fileSystem.OpenFileReader(filnam,0);
if (!fil.isOpen())
return NULL;

View file

@ -179,7 +179,7 @@ void paletteLoadFromDisk(void)
return;
}
auto fil = kopenFileReader("palette.dat", 0);
auto fil = fileSystem.OpenFileReader("palette.dat", 0);
if (!fil.isOpen())
return;

View file

@ -299,7 +299,7 @@ void scriptfile_preparse(scriptfile *sf, char *tx, int32_t flen)
scriptfile *scriptfile_fromfile(const char *fn)
{
auto fr = kopenFileReader(fn, 0);
auto fr = fileSystem.OpenFileReader(fn, 0);
if (!fr.isOpen()) return nullptr;
uint32_t flen = fr.GetLength();

View file

@ -607,7 +607,7 @@ static void read_pal(FileReader &fil, int32_t pal[256])
static int32_t loadvox(const char *filnam)
{
auto fil = kopenFileReader(filnam, 0);
auto fil = fileSystem.OpenFileReader(filnam, 0);
if (!fil.isOpen())
return -1;
@ -683,7 +683,7 @@ static int32_t loadkvx(const char *filnam)
{
int32_t i, mip1leng;
auto fil = kopenFileReader(filnam, 0);
auto fil = fileSystem.OpenFileReader(filnam, 0);
if (!fil.isOpen())
return -1;
@ -767,7 +767,7 @@ static int32_t loadkv6(const char *filnam)
{
int32_t i;
auto fil = kopenFileReader(filnam, 0);
auto fil = fileSystem.OpenFileReader(filnam, 0);
if (!fil.isOpen())
return -1;

View file

@ -770,6 +770,13 @@ FileReader FileSystem::ReopenFileReader(int lump, bool alwayscache)
return rl->NewReader(); // This always gets a reader to the cache
}
FileReader FileSystem::OpenFileReader(const char* name, int where)
{
auto lump = FindFile(name);
if (lump < 0) return FileReader();
else return OpenFileReader(lump);
}
//==========================================================================
//
// GetAllFilesOfType

View file

@ -127,6 +127,7 @@ public:
FileReader OpenFileReader(int file); // opens a reader that redirects to the containing file's one.
FileReader ReopenFileReader(int file, bool alwayscache = false); // opens an independent reader.
FileReader OpenFileReader(const char* name, int where);
int Iterate (const char *name, int *lastfile, ELookupMode lookupmode = ELookupMode::FullName); // [RH] Find files with duplication

View file

@ -93,7 +93,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
FFont *font = FFont::FindFont (name);
if (font == nullptr)
{
auto lumpy = kopenFileReader(fontlumpname, 0);
auto lumpy = fileSystem.OpenFileReader(fontlumpname, 0);
if (!lumpy.isOpen()) return nullptr;
uint32_t head;
lumpy.Read (&head, 4);

View file

@ -13,7 +13,7 @@ static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char
#ifdef HAVE_FLAC
{
Bstrcpy(fn_suffix, ".flac");
auto fp = kopenFileReader(testfn, searchfirst);
auto fp = fileSystem.OpenFileReader(testfn, searchfirst);
if (fp.isOpen())
return fp;
}
@ -22,7 +22,7 @@ static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char
#ifdef HAVE_VORBIS
{
Bstrcpy(fn_suffix, ".ogg");
auto fp = kopenFileReader(testfn, searchfirst);
auto fp = fileSystem.OpenFileReader(testfn, searchfirst);
if (fp.isOpen())
return fp;
}
@ -64,7 +64,7 @@ static FileReader S_TryExtensionReplacements(char * const testfn, char const sea
FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
{
auto origfp = kopenFileReader(fn, searchfirst);
auto origfp = fileSystem.OpenFileReader(fn, searchfirst);
if (!snd_tryformats) return origfp;
return origfp;
#if 0 // this needs to be redone

View file

@ -80,7 +80,7 @@ bool RTS_IsInitialized()
{
if (LumpInfo.Size() > 0) return true;
if (RTSName.IsEmpty()) return false;
auto fr = kopenFileReader(RTSName, 0);
auto fr = fileSystem.OpenFileReader(RTSName, 0);
RTSName = ""; // don't try ever again.
if (!fr.isOpen()) return false;
RTSFile = fr.Read();

View file

@ -287,7 +287,7 @@ int BuildTiles::LoadArtFile(const char *fn, bool mapart, int firsttile)
auto old = FindFile(fn);
if (old >= ArtFiles.Size()) // Do not process if already loaded.
{
FileReader fr = kopenFileReader(fn, 0);
FileReader fr = fileSystem.OpenFileReader(fn, 0);
if (fr.isOpen())
{
auto artdata = fr.Read();
@ -565,7 +565,7 @@ void artSetupMapArt(const char* filename)
artClearMapArt();
FStringf firstname("%s_00.art", filename);
auto fr = kopenFileReader(firstname, 0);
auto fr = fileSystem.OpenFileReader(firstname, 0);
if (!fr.isOpen()) return;
for (bssize_t i = 0; i < MAXARTFILES_TOTAL - MAXARTFILES_BASE; i++)

View file

@ -118,7 +118,7 @@ FArtTexture::FArtTexture(int width, int height, int p)
void FArtTexture::CreatePalettedPixels(uint8_t* buffer)
{
FileReader fr = kopenFileReader(Name, 0);
FileReader fr = fileSystem.OpenFileReader(Name, 0);
if (!fr.isOpen()) return;
int numpixels = Width * Height;
fr.Read(buffer, numpixels);
@ -139,7 +139,7 @@ int FArtTexture::CopyPixels(FBitmap *bmp, int conversion)
// Both Src and Dst are ordered the same with no padding.
int numpixels = Width * Height;
bool hasalpha = false;
FileReader fr = kopenFileReader(Name, 0);
FileReader fr = fileSystem.OpenFileReader(Name, 0);
if (!fr.isOpen()) return 0;
TArray<uint8_t> source(numpixels, true);
fr.Read(source.Data(), numpixels);

View file

@ -374,7 +374,7 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift
void FDDSTexture::CreatePalettedPixels(uint8_t *buffer)
{
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return; // Just leave the texture blank.
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet);
@ -781,7 +781,7 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t
int FDDSTexture::CopyPixels(FBitmap *bmp, int conversion)
{
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return -1; // Just leave the texture blank.
uint8_t *TexBuffer = bmp->GetPixels();

View file

@ -262,7 +262,7 @@ FJPEGTexture::FJPEGTexture (int width, int height)
void FJPEGTexture::CreatePalettedPixels(uint8_t *buffer)
{
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return; // Just leave the texture blank.
JSAMPLE *buff = NULL;
@ -385,7 +385,7 @@ int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion)
{
PalEntry pe[256];
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return -1; // Just leave the texture blank.
jpeg_decompress_struct cinfo;

View file

@ -350,7 +350,7 @@ void FPCXTexture::CreatePalettedPixels(uint8_t *buffer)
PCXHeader header;
int bitcount;
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return; // Just leave the texture blank.
lump.Read(&header, sizeof(header));
@ -436,7 +436,7 @@ int FPCXTexture::CopyPixels(FBitmap *bmp, int conversion)
int bitcount;
TArray<uint8_t> Pixels;
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return -1; // Just leave the texture blank.
lump.Read(&header, sizeof(header));

View file

@ -291,7 +291,7 @@ void FPNGTexture::CreatePalettedPixels(uint8_t *buffer)
FileReader *lump;
FileReader lfr;
lfr = kopenFileReader(Name, 0);
lfr = fileSystem.OpenFileReader(Name, 0);
if (!lfr.isOpen()) return;
lump = &lfr;
@ -408,7 +408,7 @@ int FPNGTexture::CopyPixels(FBitmap *bmp, int conversion)
FileReader *lump;
FileReader lfr;
lfr = kopenFileReader(Name, 0);
lfr = fileSystem.OpenFileReader(Name, 0);
if (!lfr.isOpen()) return -1; // Just leave the texture blank.
lump = &lfr;

View file

@ -154,7 +154,7 @@ void FStbTexture::CreatePalettedPixels(uint8_t *buffer)
int FStbTexture::CopyPixels(FBitmap *bmp, int conversion)
{
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return -1; // Just leave the texture blank.
int x, y, chan;
auto image = stbi_load_from_callbacks(&callbacks, &lump, &x, &y, &chan, STBI_rgb_alpha);

View file

@ -179,7 +179,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe
void FTGATexture::CreatePalettedPixels(uint8_t *buffer)
{
uint8_t PaletteMap[256];
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return;
TGAHeader hdr;
uint16_t w;
@ -385,7 +385,7 @@ void FTGATexture::CreatePalettedPixels(uint8_t *buffer)
int FTGATexture::CopyPixels(FBitmap *bmp, int conversion)
{
PalEntry pe[256];
auto lump = kopenFileReader(Name, 0);
auto lump = fileSystem.OpenFileReader(Name, 0);
if (!lump.isOpen()) return -1;
TGAHeader hdr;
uint16_t w;

View file

@ -79,7 +79,7 @@ FImageSource * FImageSource::GetImage(const char *name)
{ nullptr }
};
auto data = kopenFileReader(name, 0);
auto data = fileSystem.OpenFileReader(name, 0);
if (!data.isOpen()) return nullptr;
for (size_t i = 0; CreateInfo[i].TryCreate; i++)

View file

@ -143,7 +143,7 @@ FScanner &FScanner::operator=(const FScanner &other)
void FScanner::Open (const char *name)
{
auto fr = kopenFileReader(name, 0);
auto fr = fileSystem.OpenFileReader(name, 0);
if (!fr.isOpen())
{
I_Error("Could not find script lump '%s'\n", name);

View file

@ -253,7 +253,7 @@ int32_t Anim_Play(const char *fn)
FileReader handle;
if (!Bstrcmp(dot, ".ivf"))
{
handle = kopenFileReader(fn, 0);
handle = fileSystem.OpenFileReader(fn, 0);
if (!handle.isOpen())
break;
}
@ -272,7 +272,7 @@ int32_t Anim_Play(const char *fn)
vpxfndot[3] = 'f';
vpxfndot[4] = '\0';
handle = kopenFileReader(vpxfn, 0);
handle = fileSystem.OpenFileReader(vpxfn, 0);
if (!handle.isOpen())
break;
@ -420,7 +420,7 @@ int32_t Anim_Play(const char *fn)
int32_t ogltexfiltermode = hw_texfilter;
#endif
TArray<uint8_t> buffer;
auto fr = kopenFileReader(fn, 0);
auto fr = fileSystem.OpenFileReader(fn, 0);
if (!fr.isOpen())
goto end_anim;

View file

@ -106,7 +106,7 @@ void G_LoadLookups(void)
{
int32_t j;
auto fr = kopenFileReader("lookup.dat", 0);
auto fr = fileSystem.OpenFileReader("lookup.dat", 0);
if (!fr.isOpen())
return;

View file

@ -1908,7 +1908,7 @@ static int C_CountCaseStatements()
static void C_Include(const char *confile)
{
auto fp = kopenFileReader(confile,0);
auto fp = fileSystem.OpenFileReader(confile,0);
if (!fp.isOpen())
{
@ -5922,7 +5922,7 @@ void C_Compile(const char *fileName)
Gv_Init();
C_InitProjectiles();
auto kFile = kopenFileReader(fileName,0);
auto kFile = fileSystem.OpenFileReader(fileName,0);
if (!kFile.isOpen())
{

View file

@ -49,7 +49,7 @@ extern int ydim;
FileReader GetResource(const char* fn)
{
auto fr = kopenFileReader(fn, 0);
auto fr = fileSystem.OpenFileReader(fn, 0);
if (!fr.isOpen())
{
I_Error("Fatal: '%s' not found", fn);

View file

@ -25,7 +25,7 @@ namespace SmackerCommon {
bool FileStream::Open(const std::string &fileName)
{
file = kopenFileReader(fileName.c_str(), 0);
file = fileSystem.OpenFileReader(fileName.c_str(), 0);
if (!file.isOpen())
{
// log error

View file

@ -289,7 +289,7 @@ int32_t Anim_Play(const char *fn)
FileReader handle;
if (!Bstrcmp(dot, ".ivf"))
{
handle = kopenFileReader(fn, 0);
handle = fileSystem.OpenFileReader(fn, 0);
if (!handle.isOpen())
break;
}
@ -308,7 +308,7 @@ int32_t Anim_Play(const char *fn)
vpxfndot[3] = 'f';
vpxfndot[4] = '\0';
handle = kopenFileReader(vpxfn, 0);
handle = fileSystem.OpenFileReader(vpxfn, 0);
if (!handle.isOpen())
break;
@ -451,7 +451,7 @@ int32_t Anim_Play(const char *fn)
#ifdef USE_OPENGL
int32_t ogltexfiltermode = hw_texfilter;
#endif
auto fr = kopenFileReader(fn, 0);
auto fr = fileSystem.OpenFileReader(fn, 0);
if (!fr.isOpen())
return 0;

View file

@ -105,7 +105,7 @@ void G_LoadLookups(void)
{
int32_t j;
auto fr = kopenFileReader("lookup.dat", 0);
auto fr = fileSystem.OpenFileReader("lookup.dat", 0);
if (!fr.isOpen())
return;

View file

@ -780,7 +780,7 @@ static int32_t C_CheckEmptyBranch(int32_t tw, intptr_t lastScriptPtr)
static void C_Include(const char *confile)
{
auto fp = kopenFileReader(confile,0);
auto fp = fileSystem.OpenFileReader(confile,0);
if (!fp.isOpen())
{
@ -2220,7 +2220,7 @@ void C_Compile(const char *fileName)
C_InitHashes();
auto kFile = kopenFileReader(fileName,0);
auto kFile = fileSystem.OpenFileReader(fileName,0);
if (!kFile.isOpen())
{

View file

@ -243,7 +243,7 @@ unsigned char *LoadAnm(short anim_num)
if (anm_ptr[anim_num] == 0)
{
auto handle = kopenFileReader(ANIMname[ANIMnum], 0);
auto handle = fileSystem.OpenFileReader(ANIMname[ANIMnum], 0);
if (!handle.isOpen())
return NULL;
length = handle.GetLength();

View file

@ -55,7 +55,7 @@ extern int DemoRecCnt; // Can only record 1-player game
#if DEMO_FILE_TYPE == DEMO_FILE_GROUP
typedef FileReader DFILE;
#define DREAD(ptr, size, num, handle) (handle).Read((ptr),(size)*(num))
#define DOPEN_READ(name) kopenFileReader(name,0)
#define DOPEN_READ(name) fileSystem.OpenFileReader(name,0)
#define DCLOSE(handle) ((handle).Close())
#define DF_ERR(f) (!(f).isOpen())
#else

View file

@ -81,7 +81,7 @@ SWBOOL LoadScriptFile(const char *filename)
if (!(fp = kopenFileReader(filename, 0)).isOpen())
if (!(fp = fileSystem.OpenFileReader(filename, 0)).isOpen())
{
// If there's no script file, forget it.
return FALSE;

View file

@ -1055,7 +1055,7 @@ void PlaySoundRTS(int rts_num)
SWBOOL
OpenSound(VOC_INFOp vp, FileReader &handle, int *length)
{
handle = kopenFileReader(vp->name, 0);
handle = fileSystem.OpenFileReader(vp->name, 0);
if (!handle.isOpen())
{
@ -1085,7 +1085,7 @@ ReadSound(FileReader &handle, VOC_INFOp vp, int length)
SWBOOL
LoadSong(const char *filename)
{
auto fr = kopenFileReader(filename, 0);
auto fr = fileSystem.OpenFileReader(filename, 0);
if (!fr.isOpen())
{
return FALSE;
@ -1170,7 +1170,7 @@ SoundShutdown(void)
void MusicStartup(void)
{
#if 0
auto fil = kopenFileReader("swtimbr.tmb", 0);
auto fil = fileSystem.OpenFileReader("swtimbr.tmb", 0);
if (fil.isOpen())
{