src/fileio.h
branchnoai
changeset 9703 d2a6acdbd665
parent 9629 66dde6412125
child 9723 eee46cb39750
equal deleted inserted replaced
9702:e782b59f1f6a 9703:d2a6acdbd665
     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 <map>
       
    10 #include <string>
     9 
    11 
    10 void FioSeekTo(uint32 pos, int mode);
    12 void FioSeekTo(uint32 pos, int mode);
    11 void FioSeekToFile(uint32 pos);
    13 void FioSeekToFile(uint8 slot, uint32 pos);
    12 uint32 FioGetPos();
    14 uint32 FioGetPos();
    13 const char *FioGetFilename();
    15 const char *FioGetFilename();
    14 byte FioReadByte();
    16 byte FioReadByte();
    15 uint16 FioReadWord();
    17 uint16 FioReadWord();
    16 uint32 FioReadDword();
    18 uint32 FioReadDword();
    59  * current operating system.
    61  * current operating system.
    60  */
    62  */
    61 extern const char *_searchpaths[NUM_SEARCHPATHS];
    63 extern const char *_searchpaths[NUM_SEARCHPATHS];
    62 
    64 
    63 /**
    65 /**
       
    66  * The define of a TarList.
       
    67  */
       
    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;
       
    80 
       
    81 /**
    64  * Checks whether the given search path is a valid search path
    82  * Checks whether the given search path is a valid search path
    65  * @param sp the search path to check
    83  * @param sp the search path to check
    66  * @return true if the search path is valid
    84  * @return true if the search path is valid
    67  */
    85  */
    68 static inline bool IsValidSearchPath(Searchpath sp)
    86 static inline bool IsValidSearchPath(Searchpath sp)
    70 	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
    88 	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
    71 }
    89 }
    72 
    90 
    73 /** Iterator for all the search paths */
    91 /** Iterator for all the search paths */
    74 #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))
       
    93 #define FOR_ALL_TARS(tar) for (tar = _tar_filelist.begin(); tar != _tar_filelist.end(); tar++)
    75 
    94 
    76 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR);
    95 typedef bool FioTarFileListCallback(const char *filename, int size, void *userdata);
       
    96 FILE *FioTarFileList(const char *tar, const char *mode, size_t *filesize, FioTarFileListCallback *callback, void *userdata);
       
    97 
       
    98 void FioFCloseFile(FILE *f);
       
    99 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
    77 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
   100 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
    78 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);
    79 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);
    80 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
   103 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
    81 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
   104 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);