1 /* 2 * This software is licensed under the terms of the MIT License. 3 * See COPYING for further information. 4 * --- 5 * Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>. 6 * Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>. 7 */ 8 9 #ifndef IGUARD_vfs_public_h 10 #define IGUARD_vfs_public_h 11 12 #include "taisei.h" 13 14 #include <SDL.h> 15 16 #include "syspath_public.h" 17 #include "union_public.h" 18 #include "zipfile_public.h" 19 #include "readonly_wrapper_public.h" 20 #include "eventloop/eventloop.h" 21 22 typedef struct VFSInfo { 23 uchar error : 1; 24 uchar exists : 1; 25 uchar is_dir : 1; 26 uchar is_readonly : 1; 27 } VFSInfo; 28 29 #define VFSINFO_ERROR ((VFSInfo) { .error = true, 0 }) 30 31 typedef enum VFSOpenMode { 32 VFS_MODE_READ = 1, 33 VFS_MODE_WRITE = 2, 34 VFS_MODE_SEEKABLE = 4, 35 } VFSOpenMode; 36 37 typedef enum VFSSyncMode { 38 VFS_SYNC_LOAD = 1, 39 VFS_SYNC_STORE = 0, 40 } VFSSyncMode; 41 42 #define VFS_MODE_RWMASK (VFS_MODE_READ | VFS_MODE_WRITE) 43 44 typedef struct VFSDir VFSDir; 45 46 SDL_RWops* vfs_open(const char *path, VFSOpenMode mode); 47 VFSInfo vfs_query(const char *path); 48 49 bool vfs_mkdir(const char *path); 50 void vfs_mkdir_required(const char *path); 51 52 bool vfs_mount_alias(const char *dst, const char *src); 53 bool vfs_unmount(const char *path); 54 55 VFSDir* vfs_dir_open(const char *path) attr_nonnull(1) attr_nodiscard; 56 void vfs_dir_close(VFSDir *dir); 57 const char* vfs_dir_read(VFSDir *dir) attr_nonnull(1); 58 59 void* vfs_dir_walk(const char *path, void* (*visit)(const char *path, void *arg), void *arg); 60 61 char** vfs_dir_list_sorted(const char *path, size_t *out_size, int (*compare)(const void*, const void*), bool (*filter)(const char*)) 62 attr_nonnull(1, 2, 3) attr_nodiscard; 63 void vfs_dir_list_free(char **list, size_t size); 64 int vfs_dir_list_order_ascending(const void *a, const void *b); 65 int vfs_dir_list_order_descending(const void *a, const void *b); 66 67 char* vfs_repr(const char *path, bool try_syspath) attr_nonnull(1) attr_nodiscard; 68 bool vfs_print_tree(SDL_RWops *dest, const char *path) attr_nonnull(1, 2); 69 70 // these are defined in private.c, but need to be accessible from external code 71 void vfs_init(void); 72 void vfs_shutdown(void); 73 const char* vfs_get_error(void) attr_returns_nonnull; 74 75 void vfs_sync(VFSSyncMode mode, CallChain next); 76 77 #endif // IGUARD_vfs_public_h 78