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
 
@@ -989,13 +989,17 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fiber.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio.h"
 
				RelativePath=".\..\src\fileio_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fios.h"
 
				>
 
			</File>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -986,13 +986,17 @@
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fiber.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio.h"
 
				RelativePath=".\..\src\fileio_func.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fileio_type.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\fios.h"
 
				>
 
			</File>
source.list
Show inline comments
 
@@ -172,13 +172,14 @@ effectvehicle_func.h
 
elrail_func.h
 
engine_base.h
 
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
 
gamelog.h
 
genworld.h
 
gfx_func.h
src/console_cmds.cpp
Show inline comments
 
@@ -12,13 +12,13 @@
 
#include "variables.h"
 
#include "network/network.h"
 
#include "network/network_func.h"
 
#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"
 
#include "viewport_func.h"
 
#include "window_func.h"
 
#include "functions.h"
src/fileio.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file fileio.cpp Standard In/Out file operations */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "variables.h"
 
#include "debug.h"
 
#include "fios.h"
 
#include "core/alloc_func.hpp"
 
#include "core/math_func.hpp"
 
#include "string_func.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
 
@@ -6,13 +6,13 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#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>
 
#include <sys/stat.h>
 

	
 
#ifdef WIN32
src/fios.h
Show inline comments
 
@@ -107,54 +107,7 @@ bool FiosDelete(const char *name);
 
void FiosMakeSavegameName(char *buf, const char *name, size_t size);
 
/* Determines type of savegame (or tells it is not a savegame) */
 
FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title);
 

	
 
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
 
@@ -4,13 +4,13 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#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"
 
#include "variables.h"
 
#include "fontcache.h"
 
#include "gfx_func.h"
src/ini.cpp
Show inline comments
 
@@ -5,13 +5,13 @@
 
#include "stdafx.h"
 
#include "core/alloc_func.hpp"
 
#include "core/math_func.hpp"
 
#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)
 
{
 
	if (len == 0) len = strlen(name);
 

	
 
	this->name = strndup(name, len);
src/misc_gui.cpp
Show inline comments
 
@@ -27,13 +27,13 @@
 
#include "cheat_func.h"
 
#include "train.h"
 
#include "tgp.h"
 
#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"
 
#include "functions.h"
 
#include "window_func.h"
 
#include "date_func.h"
src/music_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file music_gui.cpp GUI for the music playback. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "variables.h"
 
#include "music.h"
 
#include "music/music_driver.hpp"
 
#include "window_gui.h"
 
#include "strings_func.h"
 
#include "window_func.h"
src/network/network.cpp
Show inline comments
 
@@ -25,13 +25,12 @@
 
#include "core/core.h"
 
#include "core/host.h"
 
#include "network_gui.h"
 
#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"
 
#include "../string_func.h"
 
#include "../player_func.h"
 
#include "../settings_type.h"
src/network/network_client.cpp
Show inline comments
 
@@ -15,13 +15,13 @@
 
#include "../saveload.h"
 
#include "../command_func.h"
 
#include "../console_func.h"
 
#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"
 
#include "../string_func.h"
 
#include "../player_func.h"
 
#include "../player_base.h"
src/network/network_server.cpp
Show inline comments
 
@@ -19,13 +19,13 @@
 
#include "../command_func.h"
 
#include "../saveload.h"
 
#include "../station_base.h"
 
#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"
 
#include "../player_gui.h"
 
#include "../settings_type.h"
 

	
src/newgrf.cpp
Show inline comments
 
@@ -5,13 +5,13 @@
 
#include "stdafx.h"
 

	
 
#include <stdarg.h>
 

	
 
#include "openttd.h"
 
#include "debug.h"
 
#include "fileio.h"
 
#include "fileio_func.h"
 
#include "engine_func.h"
 
#include "engine_base.h"
 
#include "spritecache.h"
 
#include "sprite.h"
 
#include "newgrf.h"
 
#include "variables.h"
src/newgrf_config.cpp
Show inline comments
 
@@ -12,13 +12,13 @@
 
#include "newgrf_config.h"
 
#include "core/alloc_func.hpp"
 
#include "string_func.h"
 
#include "gamelog.h"
 
#include "network/network_type.h"
 

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

	
 

	
 
GRFConfig *_all_grfs;
 
GRFConfig *_grfconfig;
 
GRFConfig *_grfconfig_newgame;
src/openttd.cpp
Show inline comments
 
@@ -30,13 +30,13 @@
 
#include "player_func.h"
 
#include "player_base.h"
 
#include "command_func.h"
 
#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"
 
#include "console_func.h"
 
#include "screenshot.h"
 
#include "network/network.h"
src/saveload.cpp
Show inline comments
 
@@ -28,12 +28,13 @@
 
#include "core/alloc_func.hpp"
 
#include "functions.h"
 
#include "core/endian_func.hpp"
 
#include "vehicle_base.h"
 
#include "autoreplace_base.h"
 
#include "statusbar_gui.h"
 
#include "fileio_func.h"
 
#include <list>
 
#include "gamelog.h"
 

	
 
#include "table/strings.h"
 

	
 
extern const uint16 SAVEGAME_VERSION = 100;
src/saveload.h
Show inline comments
 
@@ -2,13 +2,13 @@
 

	
 
/** @file saveload.h Functions/types related to saving and loading games. */
 

	
 
#ifndef SAVELOAD_H
 
#define SAVELOAD_H
 

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

	
 
#ifdef SIZE_MAX
 
#undef SIZE_MAX
 
#endif
 

	
 
#define SIZE_MAX ((size_t)-1)
src/screenshot.cpp
Show inline comments
 
@@ -2,20 +2,19 @@
 

	
 
/** @file screenshot.cpp The creation of screenshots! */
 

	
 
#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"
 
#include "core/endian_func.hpp"
 
#include "map_func.h"
 
#include "date_func.h"
src/sound.cpp
Show inline comments
 
@@ -4,13 +4,13 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#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"
 
#include "core/alloc_func.hpp"
 
#include "map_func.h"
 
#include "vehicle_base.h"
src/spritecache.cpp
Show inline comments
 
@@ -4,13 +4,13 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#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"
 
#ifdef WITH_PNG
 
#include "spriteloader/png.hpp"
 
#endif /* WITH_PNG */
src/spriteloader/grf.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file grf.cpp Reading graphics data from (New)GRF files. */
 

	
 
#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"
 

	
 
bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos)
 
{
src/spriteloader/png.cpp
Show inline comments
 
@@ -3,13 +3,13 @@
 
/** @file png.cpp Reading sprites from png files. */
 

	
 
#ifdef WITH_PNG
 

	
 
#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"
 
#include <png.h>
 

	
 
#define PNG_SLOT 62
src/strings.cpp
Show inline comments
 
@@ -12,13 +12,13 @@
 
#include "waypoint.h"
 
#include "industry.h"
 
#include "variables.h"
 
#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"
 
#include "newgrf_townname.h"
 
#include "signs_base.h"
 
#include "newgrf_engine.h"
src/video/dedicated_v.cpp
Show inline comments
 
@@ -11,13 +11,13 @@
 
#include "../gfx_func.h"
 
#include "../network/network.h"
 
#include "../network/network_internal.h"
 
#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"
 
#include "../player_func.h"
 
#include "../core/random_func.hpp"
 
#include "dedicated_v.h"
0 comments (0 inline, 0 general)