src/fileio.h
branchnoai
changeset 9628 b5c2449616b5
parent 9627 6a7c8ead2328
child 9629 66dde6412125
equal deleted inserted replaced
9627:6a7c8ead2328 9628:b5c2449616b5
     3 /** @file fileio.h Declarations for Standard In/Out file operations */
     3 /** @file fileio.h Declarations for Standard In/Out file operations */
     4 
     4 
     5 #ifndef FILEIO_H
     5 #ifndef FILEIO_H
     6 #define FILEIO_H
     6 #define FILEIO_H
     7 
     7 
       
     8 #include "helpers.hpp"
       
     9 
     8 void FioSeekTo(uint32 pos, int mode);
    10 void FioSeekTo(uint32 pos, int mode);
     9 void FioSeekToFile(uint32 pos);
    11 void FioSeekToFile(uint32 pos);
    10 uint32 FioGetPos();
    12 uint32 FioGetPos();
       
    13 const char *FioGetFilename();
    11 byte FioReadByte();
    14 byte FioReadByte();
    12 uint16 FioReadWord();
    15 uint16 FioReadWord();
    13 uint32 FioReadDword();
    16 uint32 FioReadDword();
    14 void FioCloseAll();
    17 void FioCloseAll();
    15 void FioOpenFile(int slot, const char *filename);
    18 void FioOpenFile(int slot, const char *filename);
    16 void FioReadBlock(void *ptr, uint size);
    19 void FioReadBlock(void *ptr, uint size);
    17 void FioSkipBytes(int n);
    20 void FioSkipBytes(int n);
       
    21 void FioCreateDirectory(const char *filename);
    18 
    22 
    19 FILE *FioFOpenFile(const char *filename);
    23 /**
    20 bool FioCheckFileExists(const char *filename);
    24  * The different kinds of subdirectories OpenTTD uses
    21 void FioCreateDirectory(const char *filename);
    25  */
       
    26 enum Subdirectory {
       
    27 	BASE_DIR,      ///< Base directory for all subdirectories
       
    28 	SAVE_DIR,      ///< Base directory for all savegames
       
    29 	AUTOSAVE_DIR,  ///< Subdirectory of save for autosaves
       
    30 	SCENARIO_DIR,  ///< Base directory for all scenarios
       
    31 	HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps
       
    32 	GM_DIR,        ///< Subdirectory for all music
       
    33 	DATA_DIR,      ///< Subdirectory for all data (GRFs, sample.cat, intro game)
       
    34 	LANG_DIR,      ///< Subdirectory for all translation files
       
    35 	NUM_SUBDIRS,   ///< Number of subdirectories
       
    36 	NO_DIRECTORY,  ///< A path without any base directory
       
    37 };
       
    38 
       
    39 /**
       
    40  * Types of searchpaths OpenTTD might use
       
    41  */
       
    42 enum Searchpath {
       
    43 	SP_WORKING_DIR,            ///< Search in the working directory
       
    44 	SP_PERSONAL_DIR,           ///< Search in the personal directory
       
    45 	SP_SHARED_DIR,             ///< Search in the shared directory, like 'Shared Files' under Windows
       
    46 	SP_BINARY_DIR,             ///< Search in the directory where the binary resides
       
    47 	SP_INSTALLATION_DIR,       ///< Search in the installation directory
       
    48 	SP_APPLICATION_BUNDLE_DIR, ///< Search within the application bundle
       
    49 	NUM_SEARCHPATHS
       
    50 };
       
    51 
       
    52 DECLARE_POSTFIX_INCREMENT(Searchpath);
       
    53 
       
    54 /**
       
    55  * The searchpaths OpenTTD could search through.
       
    56  * At least one of the slots has to be filled with a path.
       
    57  * NULL paths tell that there is no such path for the
       
    58  * current operating system.
       
    59  */
       
    60 extern const char *_searchpaths[NUM_SEARCHPATHS];
       
    61 
       
    62 /**
       
    63  * Checks whether the given search path is a valid search path
       
    64  * @param sp the search path to check
       
    65  * @return true if the search path is valid
       
    66  */
       
    67 static inline bool IsValidSearchPath(Searchpath sp)
       
    68 {
       
    69 	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
       
    70 }
       
    71 
       
    72 /** Iterator for all the search paths */
       
    73 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_PERSONAL_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
       
    74 
       
    75 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR);
       
    76 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
       
    77 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
       
    78 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
       
    79 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
       
    80 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
       
    81 
       
    82 static inline const char *FioGetSubdirectory(Subdirectory subdir)
       
    83 {
       
    84 	extern const char *_subdirs[NUM_SUBDIRS];
       
    85 	assert(subdir < NUM_SUBDIRS);
       
    86 	return _subdirs[subdir];
       
    87 }
    22 
    88 
    23 void SanitizeFilename(char *filename);
    89 void SanitizeFilename(char *filename);
    24 void AppendPathSeparator(char *buf, size_t buflen);
    90 void AppendPathSeparator(char *buf, size_t buflen);
    25 void DeterminePaths(const char *exe);
    91 void DeterminePaths(const char *exe);
    26 
    92 
       
    93 extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.
       
    94 
    27 #endif /* FILEIO_H */
    95 #endif /* FILEIO_H */