2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/** @file fileio.h Declarations for Standard In/Out file operations */
|
2007-03-01 01:24:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef FILEIO_H
|
|
|
|
#define FILEIO_H
|
|
|
|
|
2007-09-16 18:10:52 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2007-06-17 15:48:57 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void FioSeekTo(uint32 pos, int mode);
|
2007-09-13 18:22:34 +00:00
|
|
|
void FioSeekToFile(uint8 slot, uint32 pos);
|
2007-03-07 11:47:46 +00:00
|
|
|
uint32 FioGetPos();
|
2007-06-13 16:21:11 +00:00
|
|
|
const char *FioGetFilename();
|
2007-03-07 11:47:46 +00:00
|
|
|
byte FioReadByte();
|
|
|
|
uint16 FioReadWord();
|
|
|
|
uint32 FioReadDword();
|
|
|
|
void FioCloseAll();
|
2004-08-09 17:04:08 +00:00
|
|
|
void FioOpenFile(int slot, const char *filename);
|
|
|
|
void FioReadBlock(void *ptr, uint size);
|
|
|
|
void FioSkipBytes(int n);
|
2007-03-12 15:25:33 +00:00
|
|
|
void FioCreateDirectory(const char *filename);
|
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
/**
|
|
|
|
* The different kinds of subdirectories OpenTTD uses
|
|
|
|
*/
|
|
|
|
enum Subdirectory {
|
|
|
|
BASE_DIR, ///< Base directory for all subdirectories
|
|
|
|
SAVE_DIR, ///< Base directory for all savegames
|
|
|
|
AUTOSAVE_DIR, ///< Subdirectory of save for autosaves
|
|
|
|
SCENARIO_DIR, ///< Base directory for all scenarios
|
|
|
|
HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps
|
|
|
|
GM_DIR, ///< Subdirectory for all music
|
|
|
|
DATA_DIR, ///< Subdirectory for all data (GRFs, sample.cat, intro game)
|
|
|
|
LANG_DIR, ///< Subdirectory for all translation files
|
|
|
|
NUM_SUBDIRS, ///< Number of subdirectories
|
2007-06-17 20:09:05 +00:00
|
|
|
NO_DIRECTORY, ///< A path without any base directory
|
2007-06-17 15:48:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Types of searchpaths OpenTTD might use
|
|
|
|
*/
|
|
|
|
enum Searchpath {
|
2007-06-18 11:04:12 +00:00
|
|
|
SP_FIRST_DIR,
|
|
|
|
SP_WORKING_DIR = SP_FIRST_DIR, ///< Search in the working directory
|
|
|
|
SP_PERSONAL_DIR, ///< Search in the personal directory
|
|
|
|
SP_SHARED_DIR, ///< Search in the shared directory, like 'Shared Files' under Windows
|
|
|
|
SP_BINARY_DIR, ///< Search in the directory where the binary resides
|
|
|
|
SP_INSTALLATION_DIR, ///< Search in the installation directory
|
|
|
|
SP_APPLICATION_BUNDLE_DIR, ///< Search within the application bundle
|
2007-06-17 15:48:57 +00:00
|
|
|
NUM_SEARCHPATHS
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_POSTFIX_INCREMENT(Searchpath);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The searchpaths OpenTTD could search through.
|
|
|
|
* At least one of the slots has to be filled with a path.
|
|
|
|
* NULL paths tell that there is no such path for the
|
|
|
|
* current operating system.
|
|
|
|
*/
|
|
|
|
extern const char *_searchpaths[NUM_SEARCHPATHS];
|
|
|
|
|
2007-09-14 22:25:00 +00:00
|
|
|
/**
|
2007-09-16 18:10:52 +00:00
|
|
|
* The define of a TarList.
|
2007-09-14 22:25:00 +00:00
|
|
|
*/
|
2007-09-16 18:10:52 +00:00
|
|
|
struct TarListEntry {
|
|
|
|
const char *filename;
|
|
|
|
};
|
|
|
|
struct TarFileListEntry {
|
|
|
|
TarListEntry *tar;
|
|
|
|
int size;
|
|
|
|
int position;
|
|
|
|
};
|
|
|
|
typedef std::map<std::string, TarListEntry *> TarList;
|
|
|
|
typedef std::map<std::string, TarFileListEntry> TarFileList;
|
|
|
|
extern TarList _tar_list;
|
|
|
|
extern TarFileList _tar_filelist;
|
2007-09-14 22:25:00 +00:00
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given search path is a valid search path
|
|
|
|
* @param sp the search path to check
|
|
|
|
* @return true if the search path is valid
|
|
|
|
*/
|
|
|
|
static inline bool IsValidSearchPath(Searchpath sp)
|
|
|
|
{
|
|
|
|
return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Iterator for all the search paths */
|
2007-06-18 11:04:12 +00:00
|
|
|
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
|
2007-09-16 18:10:52 +00:00
|
|
|
#define FOR_ALL_TARS(tar) for (tar = _tar_filelist.begin(); tar != _tar_filelist.end(); tar++)
|
2007-09-14 22:25:00 +00:00
|
|
|
|
|
|
|
typedef bool FioTarFileListCallback(const char *filename, int size, void *userdata);
|
|
|
|
FILE *FioTarFileList(const char *tar, const char *mode, size_t *filesize, FioTarFileListCallback *callback, void *userdata);
|
2007-06-17 15:48:57 +00:00
|
|
|
|
2007-09-16 18:10:52 +00:00
|
|
|
void FioFCloseFile(FILE *f);
|
2007-09-13 18:46:29 +00:00
|
|
|
FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
|
2007-06-17 15:48:57 +00:00
|
|
|
bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
|
|
|
|
char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
|
|
|
|
char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
|
|
|
|
char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
|
|
|
|
char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
|
|
|
|
|
|
|
|
static inline const char *FioGetSubdirectory(Subdirectory subdir)
|
|
|
|
{
|
|
|
|
extern const char *_subdirs[NUM_SUBDIRS];
|
|
|
|
assert(subdir < NUM_SUBDIRS);
|
|
|
|
return _subdirs[subdir];
|
|
|
|
}
|
|
|
|
|
2007-06-12 15:46:34 +00:00
|
|
|
void SanitizeFilename(char *filename);
|
2007-03-12 15:25:33 +00:00
|
|
|
void AppendPathSeparator(char *buf, size_t buflen);
|
2007-03-17 11:36:04 +00:00
|
|
|
void DeterminePaths(const char *exe);
|
2007-12-25 11:26:07 +00:00
|
|
|
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
|
|
|
|
bool FileExists(const char *filename);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* FILEIO_H */
|