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); |
18 |
|
19 FILE *FioFOpenFile(const char *filename); |
|
20 bool FioCheckFileExists(const char *filename); |
|
21 void FioCreateDirectory(const char *filename); |
21 void FioCreateDirectory(const char *filename); |
22 |
22 |
|
23 /** |
|
24 * The different kinds of subdirectories OpenTTD uses |
|
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_FIRST_DIR, |
|
44 SP_WORKING_DIR = SP_FIRST_DIR, ///< Search in the working directory |
|
45 SP_PERSONAL_DIR, ///< Search in the personal directory |
|
46 SP_SHARED_DIR, ///< Search in the shared directory, like 'Shared Files' under Windows |
|
47 SP_BINARY_DIR, ///< Search in the directory where the binary resides |
|
48 SP_INSTALLATION_DIR, ///< Search in the installation directory |
|
49 SP_APPLICATION_BUNDLE_DIR, ///< Search within the application bundle |
|
50 NUM_SEARCHPATHS |
|
51 }; |
|
52 |
|
53 DECLARE_POSTFIX_INCREMENT(Searchpath); |
|
54 |
|
55 /** |
|
56 * The searchpaths OpenTTD could search through. |
|
57 * At least one of the slots has to be filled with a path. |
|
58 * NULL paths tell that there is no such path for the |
|
59 * current operating system. |
|
60 */ |
|
61 extern const char *_searchpaths[NUM_SEARCHPATHS]; |
|
62 |
|
63 /** |
|
64 * Checks whether the given search path is a valid search path |
|
65 * @param sp the search path to check |
|
66 * @return true if the search path is valid |
|
67 */ |
|
68 static inline bool IsValidSearchPath(Searchpath sp) |
|
69 { |
|
70 return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL; |
|
71 } |
|
72 |
|
73 /** Iterator for all the search paths */ |
|
74 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp)) |
|
75 |
|
76 FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR); |
|
77 bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR); |
|
78 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); |
|
80 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir); |
|
81 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir); |
|
82 |
|
83 static inline const char *FioGetSubdirectory(Subdirectory subdir) |
|
84 { |
|
85 extern const char *_subdirs[NUM_SUBDIRS]; |
|
86 assert(subdir < NUM_SUBDIRS); |
|
87 return _subdirs[subdir]; |
|
88 } |
|
89 |
|
90 void SanitizeFilename(char *filename); |
23 void AppendPathSeparator(char *buf, size_t buflen); |
91 void AppendPathSeparator(char *buf, size_t buflen); |
24 void DeterminePaths(const char *exe); |
92 void DeterminePaths(const char *exe); |
25 |
93 |
|
94 extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc. |
|
95 |
26 #endif /* FILEIO_H */ |
96 #endif /* FILEIO_H */ |