1 #pragma once 2 3 //******************************************************************************************** 4 //* 5 //* This file is part of Egoboo. 6 //* 7 //* Egoboo is free software: you can redistribute it and/or modify it 8 //* under the terms of the GNU General Public License as published by 9 //* the Free Software Foundation, either version 3 of the License, or 10 //* (at your option) any later version. 11 //* 12 //* Egoboo is distributed in the hope that it will be useful, but 13 //* WITHOUT ANY WARRANTY; without even the implied warranty of 14 //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 //* General Public License for more details. 16 //* 17 //* You should have received a copy of the GNU General Public License 18 //* along with Egoboo. If not, see <http://www.gnu.org/licenses/>. 19 //* 20 //******************************************************************************************** 21 22 /// @file egoboo_vfs.h 23 /// @brief A virtual filesystem for Egoboo. 24 /// 25 /// @details Almost all filesystem reads and writes should be handled through this interface. The only possible 26 /// exceptions would be the log file (?) or something similar. 27 /// Currently, this basically just wraps PhysicsFS functions 28 29 #include "file_common.h" 30 #include <SDL_types.h> 31 32 #if defined(__cplusplus) 33 extern "C" 34 { 35 #endif 36 37 //-------------------------------------------------------------------------------------------- 38 // MACROS 39 //-------------------------------------------------------------------------------------------- 40 41 # define VFS_TRUE (1==1) 42 # define VFS_FALSE (!VFS_TRUE) 43 44 //-------------------------------------------------------------------------------------------- 45 // TYPEDEFS 46 //-------------------------------------------------------------------------------------------- 47 48 struct s_vfs_search_context; 49 typedef struct s_vfs_search_context vfs_search_context_t; 50 51 // use this ugly thing, since there is no other way to hide the actual structure of the vfs_FILE... 52 struct vfs_FILE; 53 typedef struct vfs_FILE vfs_FILE; 54 55 //-------------------------------------------------------------------------------------------- 56 // CONSTANTS 57 //-------------------------------------------------------------------------------------------- 58 59 /// What type of things are we searching for? 60 enum e_vfs_serach_bits 61 { 62 // file types 63 VFS_SEARCH_NONE = 0, ///< NONE == ALL 64 VFS_SEARCH_DIR = ( 1 << 0 ), 65 VFS_SEARCH_FILE = ( 1 << 1 ), 66 67 // search options 68 VFS_SEARCH_BARE = ( 1 << 2 ), ///< return only the bare filename, not the whole relative path 69 70 VFS_SEARCH_ALL = VFS_SEARCH_DIR | VFS_SEARCH_FILE 71 }; 72 73 /// physfs does not distinguish between these functions 74 /// but if we change the package we are using, it might care... 75 #define vfs_delete_directory vfs_delete_file 76 77 //-------------------------------------------------------------------------------------------- 78 // FUNCTION PROTOYPES 79 //-------------------------------------------------------------------------------------------- 80 81 /// the initlization routing. there is no need to call the de-initialization. That 82 /// will be called automatically at program termination 83 void vfs_init(); 84 85 /// these functions open in "binary mode" this means that they are reading using 86 /// physfs and not using the c stdio routines 87 vfs_FILE * vfs_openReadB( const char * filename ); 88 vfs_FILE * vfs_openWriteB( const char * filename ); 89 vfs_FILE * vfs_openAppendB( const char * filename ); 90 91 // these functions open in "text mode" this means that they are reading using 92 // the c stdio routines. we use physfs to resolve the actual filename 93 vfs_FILE * vfs_openRead( const char * filename ); 94 vfs_FILE * vfs_openWrite( const char * filename ); 95 vfs_FILE * vfs_openAppend( const char * filename ); 96 97 int vfs_close( vfs_FILE * pfile ); 98 int vfs_flush( vfs_FILE * pfile ); 99 100 int vfs_eof( vfs_FILE * pfile ); 101 int vfs_error( vfs_FILE * pfile ); 102 long vfs_tell( vfs_FILE * pfile ); 103 int vfs_seek( vfs_FILE * pfile , long offset ); 104 105 int vfs_mkdir( const char *dirName ); 106 int vfs_delete_file( const char *filename ); 107 108 int vfs_exists( const char *fname ); 109 int vfs_isDirectory( const char *fname ); 110 111 // binary reading and writing 112 size_t vfs_read( void * buffer, size_t size, size_t count, vfs_FILE * pfile ); 113 size_t vfs_write( void * buffer, size_t size, size_t count, vfs_FILE * pfile ); 114 int vfs_read_Sint16( vfs_FILE * pfile, Sint16 * val ); 115 int vfs_read_Uint16( vfs_FILE * pfile, Uint16 * val ); 116 int vfs_read_Sint32( vfs_FILE * pfile, Sint32 * val ); 117 int vfs_read_Uint32( vfs_FILE * pfile, Uint32 * val ); 118 int vfs_read_Sint64( vfs_FILE * pfile, Sint64 * val ); 119 int vfs_read_Uint64( vfs_FILE * pfile, Uint64 * val ); 120 121 /// the file searching routines 122 char ** vfs_enumerateFiles( const char * dir_name ); 123 void vfs_freeList( void * listVar ); 124 125 const char * vfs_search_context_get_current( struct s_vfs_search_context * ctxt ); 126 127 vfs_search_context_t * vfs_findFirst( const char * search_path, const char * search_extension, Uint32 search_bits ); 128 vfs_search_context_t * vfs_findNext( vfs_search_context_t ** pctxt ); 129 void vfs_findClose( vfs_search_context_t ** pctxt ); 130 131 long vfs_fileLength( vfs_FILE * pfile ); 132 133 int vfs_scanf( vfs_FILE * pfile, const char *format, ... ); 134 int vfs_printf( vfs_FILE * pfile, const char *format, ... ); 135 136 int vfs_putc( int c, vfs_FILE * pfile ); 137 int vfs_getc( vfs_FILE * pfile ); 138 int vfs_ungetc( int c, vfs_FILE * pfile ); 139 140 void vfs_empty_temp_directories(); 141 142 int vfs_copyFile( const char *source, const char *dest ); 143 int vfs_copyDirectory( const char *sourceDir, const char *destDir ); 144 145 int vfs_ungetc( int, vfs_FILE * ); 146 int vfs_getc( vfs_FILE * ); 147 int vfs_removeDirectoryAndContents( const char * dirname, int recursive ); 148 int vfs_putc( int , vfs_FILE * ); 149 int vfs_puts( const char * , vfs_FILE * ); 150 char * vfs_gets( char *, int, vfs_FILE * ); 151 152 const char * vfs_resolveReadFilename( const char * src_filename ); 153 const char * vfs_resolveWriteFilename( const char * src_filename ); 154 155 const char* vfs_getError(); 156 const char* vfs_getVersion(); 157 158 int vfs_add_mount_point( const char * dirname, const char * relative_path, const char * mount_point, int append ); 159 int vfs_remove_mount_point( const char * mount_point ); 160 161 const char * vfs_convert_fname( const char * fname ); 162 const char * vfs_convert_fname_sys( const char * fname ); 163 164 void vfs_set_base_search_paths(); 165 const char * vfs_mount_info_strip_path( const char * some_path ); 166 167 //-------------------------------------------------------------------------------------------- 168 //-------------------------------------------------------------------------------------------- 169 170 #if defined(__cplusplus) 171 } 172 #endif 173 174 //-------------------------------------------------------------------------------------------- 175 //-------------------------------------------------------------------------------------------- 176 177 #define _egoboo_vfs_h 178