author | rubidium |
Fri, 25 Apr 2008 15:22:32 +0000 | |
changeset 9055 | 4dc6a0c0ef47 |
parent 8374 | 7a1b6c89cb89 |
child 9146 | dbe2317185eb |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6179
diff
changeset
|
3 |
/** @file fileio.h Declarations for Standard In/Out file operations */ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
5475
diff
changeset
|
4 |
|
0 | 5 |
#ifndef FILEIO_H |
6 |
#define FILEIO_H |
|
7 |
||
7592
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
8 |
#include <map> |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
9 |
#include <string> |
8263
2b3e64c5e680
(svn r11827) -Codechange: do not include enum_type.hpp unnecessary.
rubidium
parents:
8131
diff
changeset
|
10 |
#include "core/enum_type.hpp" |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
11 |
|
0 | 12 |
void FioSeekTo(uint32 pos, int mode); |
7570
5d5d9b6af0ef
(svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents:
6944
diff
changeset
|
13 |
void FioSeekToFile(uint8 slot, uint32 pos); |
6247 | 14 |
uint32 FioGetPos(); |
8374
7a1b6c89cb89
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
peter1138
parents:
8263
diff
changeset
|
15 |
const char *FioGetFilename(uint8 slot); |
6247 | 16 |
byte FioReadByte(); |
17 |
uint16 FioReadWord(); |
|
18 |
uint32 FioReadDword(); |
|
19 |
void FioCloseAll(); |
|
0 | 20 |
void FioOpenFile(int slot, const char *filename); |
21 |
void FioReadBlock(void *ptr, uint size); |
|
22 |
void FioSkipBytes(int n); |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
23 |
void FioCreateDirectory(const char *filename); |
6298
01c80746f308
(svn r9129) -Codechange: unify parts of DeterminePaths.
rubidium
parents:
6247
diff
changeset
|
24 |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
25 |
/** |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
26 |
* The different kinds of subdirectories OpenTTD uses |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
27 |
*/ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
28 |
enum Subdirectory { |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
29 |
BASE_DIR, ///< Base directory for all subdirectories |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
30 |
SAVE_DIR, ///< Base directory for all savegames |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
31 |
AUTOSAVE_DIR, ///< Subdirectory of save for autosaves |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
32 |
SCENARIO_DIR, ///< Base directory for all scenarios |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
33 |
HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
34 |
GM_DIR, ///< Subdirectory for all music |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
35 |
DATA_DIR, ///< Subdirectory for all data (GRFs, sample.cat, intro game) |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
36 |
LANG_DIR, ///< Subdirectory for all translation files |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
37 |
NUM_SUBDIRS, ///< Number of subdirectories |
6935
0a2a174d3f6a
(svn r10188) -Codechange: make it a little easier to load a savegame from the console:
rubidium
parents:
6929
diff
changeset
|
38 |
NO_DIRECTORY, ///< A path without any base directory |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
39 |
}; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
40 |
|
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
41 |
/** |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
42 |
* Types of searchpaths OpenTTD might use |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
43 |
*/ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
44 |
enum Searchpath { |
6944
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
45 |
SP_FIRST_DIR, |
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
46 |
SP_WORKING_DIR = SP_FIRST_DIR, ///< Search in the working directory |
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
47 |
SP_PERSONAL_DIR, ///< Search in the personal directory |
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
48 |
SP_SHARED_DIR, ///< Search in the shared directory, like 'Shared Files' under Windows |
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
49 |
SP_BINARY_DIR, ///< Search in the directory where the binary resides |
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
50 |
SP_INSTALLATION_DIR, ///< Search in the installation directory |
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
51 |
SP_APPLICATION_BUNDLE_DIR, ///< Search within the application bundle |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
52 |
NUM_SEARCHPATHS |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
53 |
}; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
54 |
|
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
55 |
DECLARE_POSTFIX_INCREMENT(Searchpath); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
56 |
|
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
57 |
/** |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
58 |
* The searchpaths OpenTTD could search through. |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
59 |
* At least one of the slots has to be filled with a path. |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
60 |
* NULL paths tell that there is no such path for the |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
61 |
* current operating system. |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
62 |
*/ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
63 |
extern const char *_searchpaths[NUM_SEARCHPATHS]; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
64 |
|
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
65 |
/** |
7592
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
66 |
* The define of a TarList. |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
67 |
*/ |
7592
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
68 |
struct TarListEntry { |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
69 |
const char *filename; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
70 |
}; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
71 |
struct TarFileListEntry { |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
72 |
TarListEntry *tar; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
73 |
int size; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
74 |
int position; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
75 |
}; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
76 |
typedef std::map<std::string, TarListEntry *> TarList; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
77 |
typedef std::map<std::string, TarFileListEntry> TarFileList; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
78 |
extern TarList _tar_list; |
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
79 |
extern TarFileList _tar_filelist; |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
80 |
|
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
81 |
/** |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
82 |
* Checks whether the given search path is a valid search path |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
83 |
* @param sp the search path to check |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
84 |
* @return true if the search path is valid |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
85 |
*/ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
86 |
static inline bool IsValidSearchPath(Searchpath sp) |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
87 |
{ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
88 |
return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
89 |
} |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
90 |
|
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
91 |
/** Iterator for all the search paths */ |
6944
53e2a7e57071
(svn r10198) -Fix (r10194): did not search all search paths.
rubidium
parents:
6941
diff
changeset
|
92 |
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp)) |
7592
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
93 |
#define FOR_ALL_TARS(tar) for (tar = _tar_filelist.begin(); tar != _tar_filelist.end(); tar++) |
7581
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
94 |
|
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
95 |
typedef bool FioTarFileListCallback(const char *filename, int size, void *userdata); |
24dab79dca15
(svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents:
7574
diff
changeset
|
96 |
FILE *FioTarFileList(const char *tar, const char *mode, size_t *filesize, FioTarFileListCallback *callback, void *userdata); |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
97 |
|
7592
792daecf7c77
(svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents:
7584
diff
changeset
|
98 |
void FioFCloseFile(FILE *f); |
7574
40e7c5575a2a
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents:
7570
diff
changeset
|
99 |
FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL); |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
100 |
bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
101 |
char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
102 |
char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
103 |
char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
104 |
char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
105 |
|
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
106 |
static inline const char *FioGetSubdirectory(Subdirectory subdir) |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
107 |
{ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
108 |
extern const char *_subdirs[NUM_SUBDIRS]; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
109 |
assert(subdir < NUM_SUBDIRS); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
110 |
return _subdirs[subdir]; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
111 |
} |
6298
01c80746f308
(svn r9129) -Codechange: unify parts of DeterminePaths.
rubidium
parents:
6247
diff
changeset
|
112 |
|
6875
e517a59b78e5
(svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents:
6317
diff
changeset
|
113 |
void SanitizeFilename(char *filename); |
6298
01c80746f308
(svn r9129) -Codechange: unify parts of DeterminePaths.
rubidium
parents:
6247
diff
changeset
|
114 |
void AppendPathSeparator(char *buf, size_t buflen); |
6317
70f4e9e52eb1
(svn r9266) -Codechange: unify the retrieval of the base paths a little more.
rubidium
parents:
6298
diff
changeset
|
115 |
void DeterminePaths(const char *exe); |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8130
diff
changeset
|
116 |
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize); |
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8130
diff
changeset
|
117 |
bool FileExists(const char *filename); |
0 | 118 |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
119 |
extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc. |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6896
diff
changeset
|
120 |
|
0 | 121 |
#endif /* FILEIO_H */ |