mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- added a FileReader wrapper for kopen4load.
Needed when transitioning the hightile loader to GZDoom's texture loader.
This commit is contained in:
parent
3fb5154dc9
commit
bedfc262c4
3 changed files with 57 additions and 6 deletions
|
@ -10,6 +10,7 @@
|
|||
#define cache1d_h_
|
||||
|
||||
#include "compat.h"
|
||||
#include "files.h"
|
||||
|
||||
#include "vfs.h"
|
||||
|
||||
|
@ -151,5 +152,55 @@ extern int32_t lz4CompressionLevel;
|
|||
int32_t kdfread_LZ4(void *buffer, int dasizeof, int count, buildvfs_kfd fil);
|
||||
void dfwrite_LZ4(const void *buffer, int dasizeof, int count, buildvfs_FILE fil);
|
||||
|
||||
class KFileReaderInterface : public FileReaderInterface
|
||||
{
|
||||
buildvfs_kfd khandle = buildvfs_kfd_invalid;
|
||||
public:
|
||||
|
||||
KFileReaderInterface(int handle)
|
||||
{
|
||||
khandle = handle;
|
||||
Length = 0;
|
||||
if (khandle != buildvfs_kfd_invalid)
|
||||
{
|
||||
klseek(khandle, 0, SEEK_END);
|
||||
Length = ktell(khandle);
|
||||
klseek(khandle, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
~KFileReaderInterface()
|
||||
{
|
||||
if (khandle != buildvfs_kfd_invalid)
|
||||
{
|
||||
kclose(khandle);
|
||||
}
|
||||
}
|
||||
virtual long Tell() const
|
||||
{
|
||||
return ktell(khandle);
|
||||
}
|
||||
virtual long Seek(long offset, int origin)
|
||||
{
|
||||
return klseek(khandle, offset, origin);
|
||||
}
|
||||
virtual long Read(void* buffer, long len)
|
||||
{
|
||||
return kread(khandle, buffer, (int32_t)len);
|
||||
}
|
||||
virtual char* Gets(char* strbuf, int len)
|
||||
{
|
||||
// Not supported by the underlying system, so we do not need it anyway.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline FileReader kopenFileReader(const char* name, int where)
|
||||
{
|
||||
int handle = where == 0 ? kopen4loadfrommod(name, 0) : kopen4load(name, where);
|
||||
KFileReaderInterface *fri = handle == buildvfs_kfd_invalid? nullptr : new KFileReaderInterface(handle);
|
||||
return FileReader(fri);
|
||||
}
|
||||
|
||||
#endif // cache1d_h_
|
||||
|
||||
|
|
|
@ -301,16 +301,15 @@ void scriptfile_preparse(scriptfile *sf, char *tx, int32_t flen)
|
|||
|
||||
scriptfile *scriptfile_fromfile(const char *fn)
|
||||
{
|
||||
buildvfs_kfd fp = kopen4load(fn, 0);
|
||||
if (fp == buildvfs_kfd_invalid) return nullptr;
|
||||
auto fr = kopenFileReader(fn, 0);
|
||||
if (!fr.isOpen()) return nullptr;
|
||||
|
||||
uint32_t flen = kfilelength(fp);
|
||||
uint32_t flen = fr.GetLength();
|
||||
char * tx = (char *)Xmalloc(flen + 2);
|
||||
|
||||
scriptfile *sf = (scriptfile *)Xmalloc(sizeof(scriptfile));
|
||||
|
||||
kread(fp, tx, flen);
|
||||
kclose(fp);
|
||||
fr.Read(tx, flen);
|
||||
|
||||
tx[flen] = tx[flen+1] = 0;
|
||||
|
||||
|
|
|
@ -123,12 +123,13 @@ class FileReader
|
|||
FileReader(const FileReader &r) = delete;
|
||||
FileReader &operator=(const FileReader &r) = delete;
|
||||
|
||||
public:
|
||||
|
||||
explicit FileReader(FileReaderInterface *r)
|
||||
{
|
||||
mReader = r;
|
||||
}
|
||||
|
||||
public:
|
||||
enum ESeek
|
||||
{
|
||||
SeekSet = SEEK_SET,
|
||||
|
|
Loading…
Reference in a new issue