Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef FILEIO_FUNC_H
00013 #define FILEIO_FUNC_H
00014
00015 #include "fileio_type.h"
00016
00017 void FioSeekTo(size_t pos, int mode);
00018 void FioSeekToFile(uint8 slot, size_t pos);
00019 size_t FioGetPos();
00020 const char *FioGetFilename(uint8 slot);
00021 byte FioReadByte();
00022 uint16 FioReadWord();
00023 uint32 FioReadDword();
00024 void FioCloseAll();
00025 void FioOpenFile(int slot, const char *filename);
00026 void FioReadBlock(void *ptr, size_t size);
00027 void FioSkipBytes(int n);
00028
00035 extern const char *_searchpaths[NUM_SEARCHPATHS];
00036
00042 static inline bool IsValidSearchPath(Searchpath sp)
00043 {
00044 return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
00045 }
00046
00048 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
00049
00050 void FioFCloseFile(FILE *f);
00051 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
00052 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
00053 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
00054 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
00055 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
00056 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
00057
00058 void SanitizeFilename(char *filename);
00059 bool AppendPathSeparator(char *buf, size_t buflen);
00060 void DeterminePaths(const char *exe);
00061 void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
00062 bool FileExists(const char *filename);
00063 const char *FioTarFirstDir(const char *tarname);
00064 void FioTarAddLink(const char *src, const char *dest);
00065 bool ExtractTar(const char *tar_filename);
00066
00067 extern char *_personal_dir;
00068
00070 class FileScanner
00071 {
00072 public:
00074 virtual ~FileScanner() {}
00075
00076 uint Scan(const char *extension, Subdirectory sd, bool tars = true, bool recursive = true);
00077 uint Scan(const char *extension, const char *directory, bool recursive = true);
00078
00086 virtual bool AddFile(const char *filename, size_t basepath_length) = 0;
00087 };
00088
00090 class TarScanner : FileScanner {
00091 public:
00092 bool AddFile(const char *filename, size_t basepath_length);
00093
00095 static uint DoScan();
00096 };
00097
00098
00099 #if defined(WIN32)
00100 #include <windows.h>
00101 struct DIR;
00102
00103 struct dirent {
00104 TCHAR *d_name;
00105
00106
00107
00108 DIR *dir;
00109 };
00110
00111 struct DIR {
00112 HANDLE hFind;
00113
00114
00115
00116 dirent ent;
00117 WIN32_FIND_DATA fd;
00118
00119
00120
00121 bool at_first_entry;
00122 };
00123
00124 DIR *opendir(const TCHAR *path);
00125 struct dirent *readdir(DIR *d);
00126 int closedir(DIR *d);
00127 #else
00128
00129 # include <sys/types.h>
00130 # include <dirent.h>
00131 #endif
00132
00140 static inline DIR *ttd_opendir(const char *path)
00141 {
00142 return opendir(OTTD2FS(path));
00143 }
00144
00145 #endif