fileio_func.h
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 void FioCreateDirectory(const char *filename);
00029
00036 extern const char *_searchpaths[NUM_SEARCHPATHS];
00037
00043 static inline bool IsValidSearchPath(Searchpath sp)
00044 {
00045 return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
00046 }
00047
00049 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
00050
00051 void FioFCloseFile(FILE *f);
00052 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
00053 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
00054 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
00055 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
00056 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
00057 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
00058
00059 void SanitizeFilename(char *filename);
00060 bool 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 const char *FioTarFirstDir(const char *tarname);
00065 void FioTarAddLink(const char *src, const char *dest);
00066 bool ExtractTar(const char *tar_filename);
00067
00068 extern char *_personal_dir;
00069
00071 class FileScanner
00072 {
00073 public:
00075 virtual ~FileScanner() {}
00076
00077 uint Scan(const char *extension, Subdirectory sd, bool tars = true, bool recursive = true);
00078 uint Scan(const char *extension, const char *directory, bool recursive = true);
00079
00087 virtual bool AddFile(const char *filename, size_t basepath_length) = 0;
00088 };
00089
00091 class TarScanner : FileScanner {
00092 public:
00093 bool AddFile(const char *filename, size_t basepath_length);
00094
00096 static uint DoScan();
00097 };
00098
00099
00100 #if defined(WIN32)
00101 #include <windows.h>
00102 struct DIR;
00103
00104 struct dirent {
00105 TCHAR *d_name;
00106
00107
00108
00109 DIR *dir;
00110 };
00111
00112 struct DIR {
00113 HANDLE hFind;
00114
00115
00116
00117 dirent ent;
00118 WIN32_FIND_DATA fd;
00119
00120
00121
00122 bool at_first_entry;
00123 };
00124
00125 DIR *opendir(const TCHAR *path);
00126 struct dirent *readdir(DIR *d);
00127 int closedir(DIR *d);
00128 #else
00129
00130 # include <sys/types.h>
00131 # include <dirent.h>
00132 #endif
00133
00141 static inline DIR *ttd_opendir(const char *path)
00142 {
00143 return opendir(OTTD2FS(path));
00144 }
00145
00146 #endif