singe/src/vfs.h

64 lines
2.1 KiB
C

/*
*
* Singe 3
* Copyright (C) 2006-2026 Scott Duensing <scott@kangaroopunch.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
/*
* Singe virtual filesystem: one lookup for every file a game names.
*
* A name resolves to a loose file in the game directory, to a copy-on-write
* overlay in the data directory, or to an asset inside the game's SQLite
* database, in that order. Loose games with no database see exactly the
* filesystem they always did.
*/
#ifndef VFS_H
#define VFS_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <SDL3/SDL.h>
#define VFS_DATABASE_EXTENSION ".game"
#define VFS_FORMAT_VERSION 1
#define VFS_CHUNK_BYTES (4 * 1024 * 1024)
typedef struct VfsStreamS VfsStreamT;
bool vfsExists(const char *name);
char *vfsFilePath(const char *name, bool forWriting);
void vfsInit(const char *container, const char *dataDirBase, const char *dataDir);
bool vfsIsDatabase(const char *path);
SDL_IOStream *vfsOpenIO(const char *name);
void vfsQuit(void);
char *vfsRead(const char *name, size_t *bytes);
bool vfsStat(const char *name, int64_t *size, int64_t *modified);
void vfsStreamClose(VfsStreamT *stream);
VfsStreamT *vfsStreamOpen(const char *name);
int64_t vfsStreamRead(VfsStreamT *stream, void *buffer, int64_t bytes);
int64_t vfsStreamSeek(VfsStreamT *stream, int64_t offset, int32_t whence);
int64_t vfsStreamSize(VfsStreamT *stream);
#endif