fileio_func.h

Go to the documentation of this file.
00001 /* $Id: fileio_func.h 14207 2008-08-31 19:56:52Z rubidium $ */
00002 
00005 #ifndef FILEIO_FUNC_H
00006 #define FILEIO_FUNC_H
00007 
00008 #include "fileio_type.h"
00009 
00010 void FioSeekTo(size_t pos, int mode);
00011 void FioSeekToFile(uint8 slot, size_t pos);
00012 size_t FioGetPos();
00013 const char *FioGetFilename(uint8 slot);
00014 byte FioReadByte();
00015 uint16 FioReadWord();
00016 uint32 FioReadDword();
00017 void FioCloseAll();
00018 void FioOpenFile(int slot, const char *filename);
00019 void FioReadBlock(void *ptr, size_t size);
00020 void FioSkipBytes(int n);
00021 void FioCreateDirectory(const char *filename);
00022 
00029 extern const char *_searchpaths[NUM_SEARCHPATHS];
00030 
00036 static inline bool IsValidSearchPath(Searchpath sp)
00037 {
00038   return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
00039 }
00040 
00042 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
00043 
00044 void FioFCloseFile(FILE *f);
00045 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
00046 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
00047 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
00048 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
00049 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
00050 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
00051 
00052 static inline const char *FioGetSubdirectory(Subdirectory subdir)
00053 {
00054   extern const char *_subdirs[NUM_SUBDIRS];
00055   assert(subdir < NUM_SUBDIRS);
00056   return _subdirs[subdir];
00057 }
00058 
00059 void SanitizeFilename(char *filename);
00060 void AppendPathSeparator(char *buf, size_t buflen);
00061 void DeterminePaths(const char *exe);
00062 void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
00063 bool FileExists(const char *filename);
00064 
00065 extern char *_personal_dir; 
00066 
00068 class FileScanner
00069 {
00070 public:
00072   virtual ~FileScanner() {}
00073 
00074   uint Scan(const char *extension, Subdirectory sd, bool tars = true);
00075 
00083   virtual bool AddFile(const char *filename, size_t basepath_length) = 0;
00084 };
00085 
00086 
00087 /* Implementation of opendir/readdir/closedir for Windows */
00088 #if defined(WIN32)
00089 #include <windows.h>
00090 struct DIR;
00091 
00092 struct dirent { // XXX - only d_name implemented
00093   TCHAR *d_name; // name of found file
00094   /* little hack which will point to parent DIR struct which will
00095    * save us a call to GetFileAttributes if we want information
00096    * about the file (for example in function fio_bla) */
00097   DIR *dir;
00098 };
00099 
00100 struct DIR {
00101   HANDLE hFind;
00102   /* the dirent returned by readdir.
00103    * note: having only one global instance is not possible because
00104    * multiple independent opendir/readdir sequences must be supported. */
00105   dirent ent;
00106   WIN32_FIND_DATA fd;
00107   /* since opendir calls FindFirstFile, we need a means of telling the
00108    * first call to readdir that we already have a file.
00109    * that's the case iff this is true */
00110   bool at_first_entry;
00111 };
00112 
00113 DIR *opendir(const TCHAR *path);
00114 struct dirent *readdir(DIR *d);
00115 int closedir(DIR *d);
00116 #else
00117 /* Use system-supplied opendir/readdir/closedir functions */
00118 # include <sys/types.h>
00119 # include <dirent.h>
00120 #endif /* defined(WIN32) */
00121 
00129 static inline DIR *ttd_opendir(const char *path)
00130 {
00131   return opendir(OTTD2FS(path));
00132 }
00133 
00134 #endif /* FILEIO_FUNC_H */

Generated on Mon Jan 5 19:01:36 2009 for openttd by  doxygen 1.5.6