src/fileio.h
changeset 7592 792daecf7c77
parent 7584 8f066de3f874
child 8130 d2eb7d04f6e1
equal deleted inserted replaced
7591:06202df3799e 7592:792daecf7c77
     4 
     4 
     5 #ifndef FILEIO_H
     5 #ifndef FILEIO_H
     6 #define FILEIO_H
     6 #define FILEIO_H
     7 
     7 
     8 #include "helpers.hpp"
     8 #include "helpers.hpp"
     9 #include <vector>
     9 #include <map>
       
    10 #include <string>
    10 
    11 
    11 void FioSeekTo(uint32 pos, int mode);
    12 void FioSeekTo(uint32 pos, int mode);
    12 void FioSeekToFile(uint8 slot, uint32 pos);
    13 void FioSeekToFile(uint8 slot, uint32 pos);
    13 uint32 FioGetPos();
    14 uint32 FioGetPos();
    14 const char *FioGetFilename();
    15 const char *FioGetFilename();
    60  * current operating system.
    61  * current operating system.
    61  */
    62  */
    62 extern const char *_searchpaths[NUM_SEARCHPATHS];
    63 extern const char *_searchpaths[NUM_SEARCHPATHS];
    63 
    64 
    64 /**
    65 /**
    65  * All the tar-files OpenTTD could search through.
    66  * The define of a TarList.
    66  */
    67  */
    67 extern std::vector<const char *>_tar_list;
    68 struct TarListEntry {
       
    69 	const char *filename;
       
    70 };
       
    71 struct TarFileListEntry {
       
    72 	TarListEntry *tar;
       
    73 	int size;
       
    74 	int position;
       
    75 };
       
    76 typedef std::map<std::string, TarListEntry *> TarList;
       
    77 typedef std::map<std::string, TarFileListEntry> TarFileList;
       
    78 extern TarList _tar_list;
       
    79 extern TarFileList _tar_filelist;
    68 
    80 
    69 /**
    81 /**
    70  * Checks whether the given search path is a valid search path
    82  * Checks whether the given search path is a valid search path
    71  * @param sp the search path to check
    83  * @param sp the search path to check
    72  * @return true if the search path is valid
    84  * @return true if the search path is valid
    76 	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
    88 	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
    77 }
    89 }
    78 
    90 
    79 /** Iterator for all the search paths */
    91 /** Iterator for all the search paths */
    80 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
    92 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
    81 #define FOR_ALL_TARS(tar) for (std::vector<const char *>::iterator it = _tar_list.begin(); it != _tar_list.end(); it++) if (tar = *it, true)
    93 #define FOR_ALL_TARS(tar) for (tar = _tar_filelist.begin(); tar != _tar_filelist.end(); tar++)
    82 
    94 
    83 typedef bool FioTarFileListCallback(const char *filename, int size, void *userdata);
    95 typedef bool FioTarFileListCallback(const char *filename, int size, void *userdata);
    84 FILE *FioTarFileList(const char *tar, const char *mode, size_t *filesize, FioTarFileListCallback *callback, void *userdata);
    96 FILE *FioTarFileList(const char *tar, const char *mode, size_t *filesize, FioTarFileListCallback *callback, void *userdata);
    85 
    97 
       
    98 void FioFCloseFile(FILE *f);
    86 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
    99 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
    87 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
   100 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
    88 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
   101 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
    89 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
   102 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
    90 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
   103 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);