2018-11-05 07:28:01 +00:00
|
|
|
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
|
|
|
|
// Ken Silverman's official web site: "http://www.advsys.net/ken"
|
|
|
|
// See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
//
|
|
|
|
// This file has been modified from Ken Silverman's original release
|
|
|
|
// by Jonathon Fowler (jf@jonof.id.au)
|
|
|
|
// by the EDuke32 team (development@voidpoint.com)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#ifndef cache1d_h_
|
|
|
|
#define cache1d_h_
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-02-16 22:27:08 +00:00
|
|
|
#include "compat.h"
|
2019-10-05 15:30:23 +00:00
|
|
|
#include "files.h"
|
2008-02-16 22:27:08 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
#include "vfs.h"
|
|
|
|
|
2019-09-22 21:15:46 +00:00
|
|
|
void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, uint8_t *newlockptr);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
using buildvfs_kfd = int32_t;
|
|
|
|
|
|
|
|
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2019-11-01 21:17:15 +00:00
|
|
|
// compression disabled pending a better process for saving. Per-block compression as done here was not that great.
|
|
|
|
int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, buildvfs_kfd fil) = delete;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-11-01 21:17:15 +00:00
|
|
|
inline int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, FileReader& fil)
|
2019-10-05 15:30:23 +00:00
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
return fil.Read(buffer, dasizeof * count);
|
|
|
|
}
|
2019-10-05 15:30:23 +00:00
|
|
|
|
2019-11-01 21:17:15 +00:00
|
|
|
inline void dfwrite_LZ4(const void* buffer, int dasizeof, int count, buildvfs_FILE fil)
|
|
|
|
{
|
|
|
|
fwrite(buffer, dasizeof, count, fil);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "filesystem/filesystem.h"
|
2019-10-05 15:30:23 +00:00
|
|
|
|
2019-10-20 18:08:17 +00:00
|
|
|
// Wrappers for the handle based API to get rid of the direct calls without any actual changes to the implementation.
|
2019-11-01 21:17:15 +00:00
|
|
|
// These are now getting redirected to the file system so that the implementation here can be gutted without making changes to the calling code.
|
2019-10-05 15:30:23 +00:00
|
|
|
inline FileReader kopenFileReader(const char* name, int where)
|
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
auto lump = fileSystem.FindFile(name);
|
|
|
|
if (lump < 0) return FileReader();
|
|
|
|
else return fileSystem.OpenFileReader(lump);
|
2019-10-05 15:30:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 19:04:55 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
FileReader fr;
|
|
|
|
fr.OpenFile(name);
|
|
|
|
return fr;
|
2019-10-20 19:04:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 18:08:17 +00:00
|
|
|
inline bool testkopen(const char* name, int where)
|
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
// todo: if backed by a single file, we must actually open it to make sure.
|
|
|
|
return fileSystem.FindFile(name) >= 0;
|
2019-10-20 18:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline TArray<uint8_t> kloadfile(const char* name, int where)
|
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
auto lump = fileSystem.FindFile(name);
|
|
|
|
if (lump < 0) return TArray<uint8_t>();
|
|
|
|
return fileSystem.GetFileData(lump);
|
2019-10-20 18:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int32_t kfilesize(const char* name, int where)
|
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
auto lump = fileSystem.FindFile(name);
|
|
|
|
if (lump < 0) return -1;
|
|
|
|
return fileSystem.FileLength(lump);
|
2019-10-20 18:08:17 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 21:17:15 +00:00
|
|
|
// checks from path and in ZIPs, returns 1 if NOT found
|
|
|
|
inline int32_t check_file_exist(const char* fn)
|
2019-10-20 19:56:13 +00:00
|
|
|
{
|
2019-11-01 21:17:15 +00:00
|
|
|
return fileSystem.FindFile(fn) >= 0;
|
2019-10-20 19:56:13 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#endif // cache1d_h_
|
2006-04-13 20:47:06 +00:00
|
|
|
|