Changeset - r10039:727fb45b0424
[Not reviewed]
master
1 26 2
rubidium - 16 years ago 2008-08-31 10:50:05
rubidium@openttd.org
(svn r14199) -Codechange: split fileio.h into fileio_type.h and fileio_func.h so not everything that includes saveload.h needs to include everything else too.
29 files changed with 206 insertions and 187 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -992,7 +992,11 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio.h"
 
				RelativePath=".\..\src\fileio_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio_type.h"
 
				>
 
			</File>
 
			<File
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -989,7 +989,11 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio.h"
 
				RelativePath=".\..\src\fileio_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio_type.h"
 
				>
 
			</File>
 
			<File
source.list
Show inline comments
 
@@ -175,7 +175,8 @@ engine_func.h
 
engine_gui.h
 
engine_type.h
 
fiber.hpp
 
fileio.h
 
fileio_func.h
 
fileio_type.h
 
fios.h
 
fontcache.h
 
functions.h
src/console_cmds.cpp
Show inline comments
 
@@ -15,7 +15,7 @@
 
#include "command_func.h"
 
#include "settings_func.h"
 
#include "fios.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "screenshot.h"
 
#include "genworld.h"
 
#include "strings_func.h"
src/fileio.cpp
Show inline comments
 
@@ -4,7 +4,7 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "variables.h"
 
#include "debug.h"
 
#include "fios.h"
src/fileio.h
Show inline comments
 
deleted file
src/fileio_func.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file fileio_func.h Functions for Standard In/Out file operations */
 

	
 
#ifndef FILEIO_FUNC_H
 
#define FILEIO_FUNC_H
 

	
 
#include "fileio_type.h"
 

	
 
void FioSeekTo(size_t pos, int mode);
 
void FioSeekToFile(uint8 slot, size_t pos);
 
size_t FioGetPos();
 
const char *FioGetFilename(uint8 slot);
 
byte FioReadByte();
 
uint16 FioReadWord();
 
uint32 FioReadDword();
 
void FioCloseAll();
 
void FioOpenFile(int slot, const char *filename);
 
void FioReadBlock(void *ptr, size_t size);
 
void FioSkipBytes(int n);
 
void FioCreateDirectory(const char *filename);
 

	
 
/**
 
 * 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];
 

	
 
/**
 
 * 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 */
 
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
 

	
 
void FioFCloseFile(FILE *f);
 
FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
 
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];
 
}
 

	
 
void SanitizeFilename(char *filename);
 
void AppendPathSeparator(char *buf, size_t buflen);
 
void DeterminePaths(const char *exe);
 
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
 
bool FileExists(const char *filename);
 

	
 
extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.
 

	
 
/** Helper for scanning for files with a given name */
 
class FileScanner
 
{
 
public:
 
	uint Scan(const char *extension, Subdirectory sd, bool tars = true);
 

	
 
	/**
 
	 * Add a file with the given filename.
 
	 * @param filename        the full path to the file to read
 
	 * @param basepath_length amount of characters to chop of before to get a
 
	 *                        filename relative to the search path.
 
	 * @return true if the file is added.
 
	 */
 
	virtual bool AddFile(const char *filename, size_t basepath_length) = 0;
 
};
 

	
 

	
 
/* Implementation of opendir/readdir/closedir for Windows */
 
#if defined(WIN32)
 
#include <windows.h>
 
struct DIR;
 

	
 
struct dirent { // XXX - only d_name implemented
 
	TCHAR *d_name; // name of found file
 
	/* little hack which will point to parent DIR struct which will
 
	 * save us a call to GetFileAttributes if we want information
 
	 * about the file (for example in function fio_bla) */
 
	DIR *dir;
 
};
 

	
 
struct DIR {
 
	HANDLE hFind;
 
	/* the dirent returned by readdir.
 
	 * note: having only one global instance is not possible because
 
	 * multiple independent opendir/readdir sequences must be supported. */
 
	dirent ent;
 
	WIN32_FIND_DATA fd;
 
	/* since opendir calls FindFirstFile, we need a means of telling the
 
	 * first call to readdir that we already have a file.
 
	 * that's the case iff this is true */
 
	bool at_first_entry;
 
};
 

	
 
DIR *opendir(const TCHAR *path);
 
struct dirent *readdir(DIR *d);
 
int closedir(DIR *d);
 
#else
 
/* Use system-supplied opendir/readdir/closedir functions */
 
# include <sys/types.h>
 
# include <dirent.h>
 
#endif /* defined(WIN32) */
 

	
 
/**
 
 * A wrapper around opendir() which will convert the string from
 
 * OPENTTD encoding to that of the filesystem. For all purposes this
 
 * function behaves the same as the original opendir function
 
 * @param path string to open directory of
 
 * @return DIR pointer
 
 */
 
static inline DIR *ttd_opendir(const char *path)
 
{
 
	return opendir(OTTD2FS(path));
 
}
 

	
 
#endif /* FILEIO_FUNC_H */
src/fileio_type.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file fileio_type.h Types for Standard In/Out file operations */
 

	
 
#ifndef FILEIO_TYPE_H
 
#define FILEIO_TYPE_H
 

	
 
#include "core/enum_type.hpp"
 

	
 
/**
 
 * 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
 
	NO_DIRECTORY,  ///< A path without any base directory
 
};
 

	
 
/**
 
 * Types of searchpaths OpenTTD might use
 
 */
 
enum Searchpath {
 
	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
 
	NUM_SEARCHPATHS
 
};
 

	
 
DECLARE_POSTFIX_INCREMENT(Searchpath);
 

	
 
#endif /* FILEIO_TYPE_H */
src/fios.cpp
Show inline comments
 
@@ -9,7 +9,7 @@
 
#include "variables.h"
 
#include "heightmap.h"
 
#include "fios.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "functions.h"
 
#include "string_func.h"
 
#include <sys/types.h>
src/fios.h
Show inline comments
 
@@ -110,51 +110,4 @@ FiosType FiosGetSavegameListCallback(Sav
 

	
 
int CDECL compare_FiosItems(const void *a, const void *b);
 

	
 
/* Implementation of opendir/readdir/closedir for Windows */
 
#if defined(WIN32)
 
#include <windows.h>
 
struct DIR;
 

	
 
struct dirent { // XXX - only d_name implemented
 
	TCHAR *d_name; // name of found file
 
	/* little hack which will point to parent DIR struct which will
 
	 * save us a call to GetFileAttributes if we want information
 
	 * about the file (for example in function fio_bla) */
 
	DIR *dir;
 
};
 

	
 
struct DIR {
 
	HANDLE hFind;
 
	/* the dirent returned by readdir.
 
	 * note: having only one global instance is not possible because
 
	 * multiple independent opendir/readdir sequences must be supported. */
 
	dirent ent;
 
	WIN32_FIND_DATA fd;
 
	/* since opendir calls FindFirstFile, we need a means of telling the
 
	 * first call to readdir that we already have a file.
 
	 * that's the case iff this is true */
 
	bool at_first_entry;
 
};
 

	
 
DIR *opendir(const TCHAR *path);
 
struct dirent *readdir(DIR *d);
 
int closedir(DIR *d);
 
#else
 
/* Use system-supplied opendir/readdir/closedir functions */
 
# include <sys/types.h>
 
# include <dirent.h>
 
#endif /* defined(WIN32) */
 

	
 
/**
 
 * A wrapper around opendir() which will convert the string from
 
 * OPENTTD encoding to that of the filesystem. For all purposes this
 
 * function behaves the same as the original opendir function
 
 * @param path string to open directory of
 
 * @return DIR pointer
 
 */
 
static inline DIR *ttd_opendir(const char *path)
 
{
 
	return opendir(OTTD2FS(path));
 
}
 

	
 
#endif /* FIOS_H */
src/gfxinit.cpp
Show inline comments
 
@@ -7,7 +7,7 @@
 
#include "debug.h"
 
#include "gfxinit.h"
 
#include "spritecache.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "fios.h"
 
#include "newgrf.h"
 
#include "md5.h"
src/ini.cpp
Show inline comments
 
@@ -8,7 +8,7 @@
 
#include "debug.h"
 
#include "ini_type.h"
 
#include "string_func.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 

	
 
IniItem::IniItem(IniGroup *parent, const char *name, size_t len) : next(NULL), value(NULL), comment(NULL)
 
{
src/misc_gui.cpp
Show inline comments
 
@@ -30,7 +30,7 @@
 
#include "cargotype.h"
 
#include "player_face.h"
 
#include "strings_func.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "fios.h"
 
#include "tile_cmd.h"
 
#include "zoom_func.h"
src/music_gui.cpp
Show inline comments
 
@@ -4,7 +4,7 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "variables.h"
 
#include "music.h"
 
#include "music/music_driver.hpp"
src/network/network.cpp
Show inline comments
 
@@ -28,7 +28,6 @@
 
#include "../console_func.h"
 
#include <stdarg.h> /* va_list */
 
#include "../md5.h"
 
#include "../fileio.h"
 
#include "../texteff.hpp"
 
#include "../core/random_func.hpp"
 
#include "../window_func.h"
src/network/network_client.cpp
Show inline comments
 
@@ -18,7 +18,7 @@
 
#include "../variables.h"
 
#include "../ai/ai.h"
 
#include "../core/alloc_func.hpp"
 
#include "../fileio.h"
 
#include "../fileio_func.h"
 
#include "../md5.h"
 
#include "../strings_func.h"
 
#include "../window_func.h"
src/network/network_server.cpp
Show inline comments
 
@@ -22,7 +22,7 @@
 
#include "../variables.h"
 
#include "../genworld.h"
 
#include "../core/alloc_func.hpp"
 
#include "../fileio.h"
 
#include "../fileio_func.h"
 
#include "../string_func.h"
 
#include "../player_base.h"
 
#include "../player_func.h"
src/newgrf.cpp
Show inline comments
 
@@ -8,7 +8,7 @@
 

	
 
#include "openttd.h"
 
#include "debug.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "engine_func.h"
 
#include "engine_base.h"
 
#include "spritecache.h"
src/newgrf_config.cpp
Show inline comments
 
@@ -15,7 +15,7 @@
 
#include "gamelog.h"
 
#include "network/network_type.h"
 

	
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "fios.h"
 

	
 

	
src/openttd.cpp
Show inline comments
 
@@ -33,7 +33,7 @@
 
#include "town.h"
 
#include "industry.h"
 
#include "news_func.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "fios.h"
 
#include "airport.h"
 
#include "aircraft.h"
src/saveload.cpp
Show inline comments
 
@@ -31,6 +31,7 @@
 
#include "vehicle_base.h"
 
#include "autoreplace_base.h"
 
#include "statusbar_gui.h"
 
#include "fileio_func.h"
 
#include <list>
 
#include "gamelog.h"
 

	
src/saveload.h
Show inline comments
 
@@ -5,7 +5,7 @@
 
#ifndef SAVELOAD_H
 
#define SAVELOAD_H
 

	
 
#include "fileio.h"
 
#include "fileio_type.h"
 

	
 
#ifdef SIZE_MAX
 
#undef SIZE_MAX
src/screenshot.cpp
Show inline comments
 
@@ -5,14 +5,13 @@
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "core/math_func.hpp"
 
#include "screenshot.h"
 
#include "variables.h"
 
#include "blitter/factory.hpp"
 
#include "fileio.h"
 
#include "strings_func.h"
 
#include "zoom_func.h"
 
#include "core/alloc_func.hpp"
src/sound.cpp
Show inline comments
 
@@ -7,7 +7,7 @@
 
#include "landscape.h"
 
#include "mixer.h"
 
#include "sound_func.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "newgrf_sound.h"
 
#include "fios.h"
 
#include "window_gui.h"
src/spritecache.cpp
Show inline comments
 
@@ -7,7 +7,7 @@
 
#include "variables.h"
 
#include "debug.h"
 
#include "spritecache.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "spriteloader/grf.hpp"
 
#include "core/alloc_func.hpp"
 
#include "core/math_func.hpp"
src/spriteloader/grf.cpp
Show inline comments
 
@@ -4,7 +4,7 @@
 

	
 
#include "../stdafx.h"
 
#include "../gfx_func.h"
 
#include "../fileio.h"
 
#include "../fileio_func.h"
 
#include "../debug.h"
 
#include "../core/alloc_func.hpp"
 
#include "grf.hpp"
src/spriteloader/png.cpp
Show inline comments
 
@@ -6,7 +6,7 @@
 

	
 
#include "../stdafx.h"
 
#include "../gfx_func.h"
 
#include "../fileio.h"
 
#include "../fileio_func.h"
 
#include "../debug.h"
 
#include "../core/alloc_func.hpp"
 
#include "png.hpp"
src/strings.cpp
Show inline comments
 
@@ -15,7 +15,7 @@
 
#include "newgrf_text.h"
 
#include "music.h"
 
#include "industry.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "cargotype.h"
 
#include "group.h"
 
#include "debug.h"
src/video/dedicated_v.cpp
Show inline comments
 
@@ -14,7 +14,7 @@
 
#include "../console_func.h"
 
#include "../variables.h"
 
#include "../genworld.h"
 
#include "../fileio.h"
 
#include "../fileio_type.h"
 
#include "../fios.h"
 
#include "../blitter/factory.hpp"
 
#include "../core/alloc_func.hpp"
0 comments (0 inline, 0 general)