00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef FILEIO_FUNC_H
00013 #define FILEIO_FUNC_H
00014
00015 #include "core/enum_type.hpp"
00016 #include "fileio_type.h"
00017
00018 void FioSeekTo(size_t pos, int mode);
00019 void FioSeekToFile(uint8 slot, size_t pos);
00020 size_t FioGetPos();
00021 const char *FioGetFilename(uint8 slot);
00022 byte FioReadByte();
00023 uint16 FioReadWord();
00024 uint32 FioReadDword();
00025 void FioCloseAll();
00026 void FioOpenFile(int slot, const char *filename, Subdirectory subdir);
00027 void FioReadBlock(void *ptr, size_t size);
00028 void FioSkipBytes(int n);
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, Subdirectory subdir, size_t *filesize = NULL);
00053 bool FioCheckFileExists(const char *filename, Subdirectory subdir);
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 const char *FiosGetScreenshotDir();
00060
00061 void SanitizeFilename(char *filename);
00062 bool AppendPathSeparator(char *buf, size_t buflen);
00063 void DeterminePaths(const char *exe);
00064 void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
00065 bool FileExists(const char *filename);
00066 const char *FioTarFirstDir(const char *tarname, Subdirectory subdir);
00067 void FioTarAddLink(const char *src, const char *dest, Subdirectory subdir);
00068 bool ExtractTar(const char *tar_filename, Subdirectory subdir);
00069
00070 extern const char *_personal_dir;
00071
00073 class FileScanner {
00074 protected:
00075 Subdirectory subdir;
00076 public:
00078 virtual ~FileScanner() {}
00079
00080 uint Scan(const char *extension, Subdirectory sd, bool tars = true, bool recursive = true);
00081 uint Scan(const char *extension, const char *directory, bool recursive = true);
00082
00091 virtual bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) = 0;
00092 };
00093
00095 class TarScanner : FileScanner {
00096 uint DoScan(Subdirectory sd);
00097 public:
00099 enum Mode {
00100 NONE = 0,
00101 BASESET = 1 << 0,
00102 NEWGRF = 1 << 1,
00103 AI = 1 << 2,
00104 SCENARIO = 1 << 3,
00105 GAME = 1 << 4,
00106 ALL = BASESET | NEWGRF | AI | SCENARIO | GAME,
00107 };
00108
00109 bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL);
00110
00111 bool AddFile(Subdirectory sd, const char *filename);
00112
00114 static uint DoScan(TarScanner::Mode mode);
00115 };
00116
00117 DECLARE_ENUM_AS_BIT_SET(TarScanner::Mode)
00118
00119
00120 #if defined(WIN32)
00121 struct DIR;
00122
00123 struct dirent {
00124 TCHAR *d_name;
00125
00126
00127
00128 DIR *dir;
00129 };
00130
00131 DIR *opendir(const TCHAR *path);
00132 struct dirent *readdir(DIR *d);
00133 int closedir(DIR *d);
00134 #else
00135
00136 # include <sys/types.h>
00137 # include <dirent.h>
00138 #endif
00139
00147 static inline DIR *ttd_opendir(const char *path)
00148 {
00149 return opendir(OTTD2FS(path));
00150 }
00151
00152 #endif