filesys.h

Go to the documentation of this file.
00001 
00006 /*
00007 All original material Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 Copyright (C) 1997-2001 Id Software, Inc.
00010 
00011 This program is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00019 
00020 See the GNU General Public License for more details.
00021 
00022 You should have received a copy of the GNU General Public License
00023 along with this program; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00025 
00026 */
00027 
00028 
00029 #ifndef _COMMON_FILESYS_H
00030 #define _COMMON_FILESYS_H
00031 
00032 #include <stdio.h>
00033 
00034 #define BASEDIRNAME "base"
00035 
00036 /* Maximum maps constant */
00037 #define MAX_MAPS 400
00038 
00039 /* max length of the ufo virtual filesystem */
00040 #define MAX_QPATH           64
00041 
00042 /* max length of a filesystem pathname
00043  * windows + linux 256, macosx 32 */
00044 #define MAX_OSPATH          256
00045 
00046 /* max files in a directory */
00047 #define MAX_FILES           512
00048 
00049 /*
00050 ==============================================================
00051 FILESYSTEM
00052 ==============================================================
00053 */
00054 typedef struct qFILE_s {
00055     void *z; 
00056     FILE *f; 
00057     char name[MAX_OSPATH];
00058     unsigned long filepos;
00059     unsigned long size;
00060 } qFILE;
00061 
00062 typedef enum {
00063     FS_READ,
00064     FS_WRITE,
00065     FS_APPEND,
00066     FS_APPEND_SYNC
00067 } fsMode_t;
00068 
00069 typedef enum {
00070     FS_SEEK_CUR,
00071     FS_SEEK_END,
00072     FS_SEEK_SET
00073 } fsOrigin_t;
00074 
00076 typedef struct filelink_s {
00077     struct filelink_s *next;
00078     char *from;
00079     int fromlength;
00080     char *to;
00081 } filelink_t;
00082 
00083 typedef struct {
00084     char name[MAX_QPATH];
00085     unsigned long filepos;
00086     unsigned long filelen;
00087 } packfile_t;
00088 
00089 typedef struct pack_s {
00090     char filename[MAX_OSPATH];
00091     qFILE handle;
00092     int numfiles;
00093     packfile_t *files;
00094 } pack_t;
00095 
00096 typedef struct searchpath_s {
00097     char filename[MAX_OSPATH];
00098     pack_t *pack;               /* only one of filename / pack will be used */
00099     struct searchpath_s *next;
00100 } searchpath_t;
00101 
00103 typedef enum {
00104     FILE_READ, FILE_WRITE, FILE_APPEND
00105 } filemode_t;
00106 
00107 /*
00108 ==============================================================
00109 FILESYSTEM
00110 ==============================================================
00111 */
00112 extern char *fs_maps[MAX_MAPS];
00113 extern int fs_numInstalledMaps;
00114 
00115 /* directory searching */
00116 #define SFF_ARCH    0x01
00117 #define SFF_HIDDEN  0x02
00118 #define SFF_RDONLY  0x04
00119 #define SFF_SUBDIR  0x08
00120 #define SFF_SYSTEM  0x10
00121 
00122 int FS_FileLength(qFILE * f);
00123 int FS_Seek(qFILE * f, long offset, int origin);
00124 int FS_WriteFile(const void *buffer, size_t len, const char *filename);
00125 int FS_Write(const void *buffer, int len, qFILE * f);
00126 int FS_Printf(qFILE *f, const char *msg, ...) __attribute__((format(__printf__, 2, 3)));
00127 void FS_InitFilesystem(qboolean writeToHomeDir);
00128 void FS_RestartFilesystem(void);
00129 const char *FS_Gamedir(void);
00130 const char *FS_NextPath(const char *prevpath);
00131 void FS_ExecAutoexec(void);
00132 const char *FS_GetCwd(void);
00133 void FS_NormPath(char *path);
00134 qboolean FS_FileExists(const char *filename);
00135 void FS_SkipBlock(const char **text);
00136 
00137 void FS_GetMaps(qboolean reset);
00138 
00139 int FS_OpenFile(const char *filename, qFILE * file, filemode_t mode);
00140 void FS_CloseFile(qFILE * f);
00141 
00142 qboolean FS_RenameFile(const char *from, const char *to, qboolean relative);
00143 void FS_RemoveFile(const char *osPath);
00144 void FS_CopyFile(const char *fromOSPath, const char *toOSPath);
00145 
00146 /* note: this can't be called from another DLL, due to MS libc issues */
00147 
00148 int FS_LoadFile(const char *path, byte **buffer);
00149 
00150 /* a null buffer will just return the file length without loading */
00151 /* a -1 length is not present */
00152 
00153 int FS_Read(void *buffer, int len, qFILE * f);
00154 /* properly handles partial reads */
00155 
00156 void FS_FreeFile(void *buffer);
00157 
00158 int FS_CheckFile(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
00159 
00160 int FS_BuildFileList(const char *files);
00161 const char* FS_NextFileFromFileList(const char *files);
00162 char *FS_NextScriptHeader(const char *files, const char **name, const char **text);
00163 void FS_CreatePath(const char *path);
00164 
00165 /* Make sure we have this available */
00166 char **FS_ListFiles(const char *findname, int *numfiles, unsigned musthave, unsigned canthave);
00167 
00168 const char *FS_GetFileData(const char *files);
00169 
00173 void FS_Shutdown(void);
00174 
00175 #endif

Generated by  doxygen 1.6.2