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-03-01 08:51:50 +00:00
|
|
|
#include "vfs.h"
|
|
|
|
|
2014-11-26 04:39:23 +00:00
|
|
|
#ifdef __cplusplus
|
2006-04-13 20:47:06 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-05-03 07:04:11 +00:00
|
|
|
extern char *kpzbuf;
|
2015-05-27 08:47:03 +00:00
|
|
|
extern int32_t kpzbufsiz;
|
2015-05-03 07:04:11 +00:00
|
|
|
extern int32_t kpzbufload(const char *);
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize);
|
|
|
|
void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, char *newlockptr);
|
|
|
|
void cacheAgeEntries(void);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
#ifdef USE_PHYSFS
|
|
|
|
using buildvfs_kfd = PHYSFS_File *;
|
|
|
|
#define buildvfs_kfd_invalid (nullptr)
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
|
2019-03-01 08:51:50 +00:00
|
|
|
|
2015-01-08 15:14:47 +00:00
|
|
|
#define addsearchpath(a) addsearchpath_user(a, 0)
|
2019-03-01 08:51:50 +00:00
|
|
|
static inline int32_t addsearchpath_user(const char *p, int32_t)
|
|
|
|
{
|
|
|
|
return PHYSFS_mount(p, NULL, 1) == 0 ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int32_t removesearchpath(const char *p)
|
|
|
|
{
|
|
|
|
return PHYSFS_unmount(p);
|
|
|
|
}
|
|
|
|
static inline void removesearchpaths_withuser(int32_t)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t findfrompath(const char *fn, char **where);
|
|
|
|
buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode);
|
|
|
|
buildvfs_FILE fopenfrompath(const char *fn, const char *mode);
|
|
|
|
|
|
|
|
|
|
|
|
extern int32_t numgroupfiles;
|
|
|
|
void uninitgroupfile(void);
|
|
|
|
|
|
|
|
|
|
|
|
static inline int initgroupfile(const char *filename)
|
|
|
|
{
|
|
|
|
return PHYSFS_mount(filename, NULL, 1) == 0 ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define kread(fd, p, s) PHYSFS_readBytes((fd), (p), (s))
|
|
|
|
#define kwrite(fd, p, s) PHYSFS_writeBytes((fd), (p), (s))
|
|
|
|
#define kopen4load(fn, searchfirst) PHYSFS_openRead(fn)
|
|
|
|
#define ktell(fd) PHYSFS_tell(fd)
|
|
|
|
#define kfilelength(fd) PHYSFS_fileLength(fd)
|
|
|
|
|
|
|
|
|
|
|
|
static inline void kclose(buildvfs_kfd handle)
|
|
|
|
{
|
|
|
|
PHYSFS_close(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define kread_and_test(handle, buffer, leng) EDUKE32_PREDICT_FALSE(kread((handle), (buffer), (leng)) != (leng))
|
|
|
|
extern int32_t klseek(buildvfs_kfd handle, int32_t offset, int32_t whence);
|
|
|
|
#define klseek_and_test(handle, offset, whence) EDUKE32_PREDICT_FALSE(klseek((handle), (offset), (whence)) < 0)
|
|
|
|
|
|
|
|
static inline void krename(int32_t, int32_t, const char *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
using buildvfs_kfd = int32_t;
|
|
|
|
#define buildvfs_kfd_invalid (-1)
|
|
|
|
|
|
|
|
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
|
|
|
|
char *listsearchpath(int32_t initp);
|
2015-01-08 15:14:47 +00:00
|
|
|
int32_t addsearchpath_user(const char *p, int32_t user);
|
2019-03-01 08:51:50 +00:00
|
|
|
#define addsearchpath(a) addsearchpath_user(a, 0)
|
2013-04-05 07:48:20 +00:00
|
|
|
int32_t removesearchpath(const char *p);
|
2015-01-08 15:14:47 +00:00
|
|
|
void removesearchpaths_withuser(int32_t usermask);
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t findfrompath(const char *fn, char **where);
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode);
|
|
|
|
buildvfs_FILE fopenfrompath(const char *fn, const char *mode);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-01-03 20:07:24 +00:00
|
|
|
extern int32_t numgroupfiles;
|
2016-08-27 01:41:33 +00:00
|
|
|
int initgroupfile(const char *filename);
|
2006-04-13 20:47:06 +00:00
|
|
|
void uninitgroupfile(void);
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_kfd kopen4load(const char *filename, char searchfirst); // searchfirst: 0 = anywhere, 1 = first group, 2 = any group
|
|
|
|
int32_t kread(buildvfs_kfd handle, void *buffer, int32_t leng);
|
2015-09-23 17:54:50 +00:00
|
|
|
#define kread_and_test(handle, buffer, leng) EDUKE32_PREDICT_FALSE(kread((handle), (buffer), (leng)) != (leng))
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t klseek(buildvfs_kfd handle, int32_t offset, int32_t whence);
|
2015-09-23 17:55:19 +00:00
|
|
|
#define klseek_and_test(handle, offset, whence) EDUKE32_PREDICT_FALSE(klseek((handle), (offset), (whence)) < 0)
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t kfilelength(buildvfs_kfd handle);
|
|
|
|
int32_t ktell(buildvfs_kfd handle);
|
|
|
|
void kclose(buildvfs_kfd handle);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-03-23 08:30:41 +00:00
|
|
|
void krename(int32_t crcval, int32_t filenum, const char *newname);
|
2015-11-25 12:08:00 +00:00
|
|
|
char const * kfileparent(int32_t handle);
|
2019-03-01 08:51:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int32_t kpzbufloadfil(buildvfs_kfd);
|
|
|
|
|
|
|
|
#ifdef WITHKPLIB
|
|
|
|
int32_t cache1d_file_fromzip(buildvfs_kfd fil);
|
|
|
|
#endif
|
2015-03-23 06:28:08 +00:00
|
|
|
|
2018-04-05 04:39:30 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
intptr_t *hand;
|
|
|
|
int32_t leng;
|
|
|
|
char * lock;
|
|
|
|
} cactype;
|
2010-08-02 08:13:51 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
enum {
|
2018-04-05 04:39:30 +00:00
|
|
|
CACHE1D_FIND_FILE = 1,
|
|
|
|
CACHE1D_FIND_DIR = 2,
|
|
|
|
CACHE1D_FIND_DRIVE = 4,
|
|
|
|
CACHE1D_FIND_NOCURDIR = 8,
|
|
|
|
|
|
|
|
CACHE1D_OPT_NOSTACK = 0x100,
|
|
|
|
|
|
|
|
// the lower the number, the higher the priority
|
|
|
|
CACHE1D_SOURCE_DRIVE = 0,
|
|
|
|
CACHE1D_SOURCE_CURDIR = 1,
|
|
|
|
CACHE1D_SOURCE_PATH = 2, // + path stack depth
|
|
|
|
CACHE1D_SOURCE_ZIP = 0x7ffffffe,
|
|
|
|
CACHE1D_SOURCE_GRP = 0x7fffffff,
|
2006-04-13 20:47:06 +00:00
|
|
|
};
|
|
|
|
typedef struct _CACHE1D_FIND_REC {
|
2018-04-05 04:39:30 +00:00
|
|
|
char *name;
|
|
|
|
int32_t type, source;
|
|
|
|
struct _CACHE1D_FIND_REC *next, *prev, *usera, *userb;
|
2006-04-13 20:47:06 +00:00
|
|
|
} CACHE1D_FIND_REC;
|
|
|
|
void klistfree(CACHE1D_FIND_REC *rec);
|
2009-01-09 09:29:17 +00:00
|
|
|
CACHE1D_FIND_REC *klistpath(const char *path, const char *mask, int32_t type);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-05 04:39:30 +00:00
|
|
|
extern int32_t lz4CompressionLevel;
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil);
|
|
|
|
int32_t kdfread_LZ4(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil);
|
2012-02-18 22:15:04 +00:00
|
|
|
#if 0
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t dfread(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil);
|
|
|
|
void kdfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil);
|
2012-02-18 22:15:04 +00:00
|
|
|
#endif
|
2019-03-01 08:51:50 +00:00
|
|
|
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil);
|
|
|
|
void dfwrite_LZ4(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-26 04:39:23 +00:00
|
|
|
#ifdef __cplusplus
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#endif // cache1d_h_
|
2006-04-13 20:47:06 +00:00
|
|
|
|