From ea1f180a55f66ae02f95e63d387fa445061daa25 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 31 Aug 2008 10:50:05 +0000 Subject: (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. --- src/console_cmds.cpp | 2 +- src/fileio.cpp | 2 +- src/fileio.h | 115 ------------------------------------ src/fileio_func.h | 131 +++++++++++++++++++++++++++++++++++++++++ src/fileio_type.h | 42 +++++++++++++ src/fios.cpp | 2 +- src/fios.h | 47 --------------- src/gfxinit.cpp | 2 +- src/ini.cpp | 2 +- src/misc_gui.cpp | 2 +- src/music_gui.cpp | 2 +- src/network/network.cpp | 1 - src/network/network_client.cpp | 2 +- src/network/network_server.cpp | 2 +- src/newgrf.cpp | 2 +- src/newgrf_config.cpp | 2 +- src/openttd.cpp | 2 +- src/saveload.cpp | 1 + src/saveload.h | 2 +- src/screenshot.cpp | 3 +- src/sound.cpp | 2 +- src/spritecache.cpp | 2 +- src/spriteloader/grf.cpp | 2 +- src/spriteloader/png.cpp | 2 +- src/strings.cpp | 2 +- src/video/dedicated_v.cpp | 2 +- 26 files changed, 194 insertions(+), 184 deletions(-) delete mode 100644 src/fileio.h create mode 100644 src/fileio_func.h create mode 100644 src/fileio_type.h (limited to 'src') diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 2286f865f..c0a7b1c7d 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -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" diff --git a/src/fileio.cpp b/src/fileio.cpp index 9e141c6e5..381d51c57 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -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" diff --git a/src/fileio.h b/src/fileio.h deleted file mode 100644 index 7c8a80221..000000000 --- a/src/fileio.h +++ /dev/null @@ -1,115 +0,0 @@ -/* $Id$ */ - -/** @file fileio.h Declarations for Standard In/Out file operations */ - -#ifndef FILEIO_H -#define FILEIO_H - -#include "core/enum_type.hpp" - -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 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); - -/** - * 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; -}; - -#endif /* FILEIO_H */ diff --git a/src/fileio_func.h b/src/fileio_func.h new file mode 100644 index 000000000..476e1afff --- /dev/null +++ b/src/fileio_func.h @@ -0,0 +1,131 @@ +/* $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 +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 +# include +#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 */ diff --git a/src/fileio_type.h b/src/fileio_type.h new file mode 100644 index 000000000..baef9c70d --- /dev/null +++ b/src/fileio_type.h @@ -0,0 +1,42 @@ +/* $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 */ diff --git a/src/fios.cpp b/src/fios.cpp index cdecb1b34..116179228 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -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 diff --git a/src/fios.h b/src/fios.h index 40982bf4d..d40292be1 100644 --- a/src/fios.h +++ b/src/fios.h @@ -110,51 +110,4 @@ FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, int CDECL compare_FiosItems(const void *a, const void *b); -/* Implementation of opendir/readdir/closedir for Windows */ -#if defined(WIN32) -#include -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 -# include -#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 */ diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index c6497bb0b..f76e90968 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -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" diff --git a/src/ini.cpp b/src/ini.cpp index 7c1786a74..defc913c9 100644 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -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) { diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 6c7221ac4..25f8e3baf 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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" diff --git a/src/music_gui.cpp b/src/music_gui.cpp index aa2a8f97d..002fb5070 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -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" diff --git a/src/network/network.cpp b/src/network/network.cpp index dff8c220d..e2b355c6f 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -28,7 +28,6 @@ #include "../console_func.h" #include /* va_list */ #include "../md5.h" -#include "../fileio.h" #include "../texteff.hpp" #include "../core/random_func.hpp" #include "../window_func.h" diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 4814973a1..0b07e7da0 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -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" diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 56f8b724e..d1e1614f6 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -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" diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 1f8756d0a..fadb9f57d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -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" diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 6faeb8d77..98ba8d420 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -15,7 +15,7 @@ #include "gamelog.h" #include "network/network_type.h" -#include "fileio.h" +#include "fileio_func.h" #include "fios.h" diff --git a/src/openttd.cpp b/src/openttd.cpp index 61f466056..73589937c 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -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" diff --git a/src/saveload.cpp b/src/saveload.cpp index a05302a1c..180d80ece 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -31,6 +31,7 @@ #include "vehicle_base.h" #include "autoreplace_base.h" #include "statusbar_gui.h" +#include "fileio_func.h" #include #include "gamelog.h" diff --git a/src/saveload.h b/src/saveload.h index dfe07350c..df2dc9f07 100644 --- a/src/saveload.h +++ b/src/saveload.h @@ -5,7 +5,7 @@ #ifndef SAVELOAD_H #define SAVELOAD_H -#include "fileio.h" +#include "fileio_type.h" #ifdef SIZE_MAX #undef SIZE_MAX diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 6f5cc0105..5a9ef0581 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -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" diff --git a/src/sound.cpp b/src/sound.cpp index ab5872b12..81c22cbb4 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -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" diff --git a/src/spritecache.cpp b/src/spritecache.cpp index d9c2498a8..616eb59b1 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -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" diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index 0bd73f927..871a9fa0a 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -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" diff --git a/src/spriteloader/png.cpp b/src/spriteloader/png.cpp index 54d04a3a8..4ccc502aa 100644 --- a/src/spriteloader/png.cpp +++ b/src/spriteloader/png.cpp @@ -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" diff --git a/src/strings.cpp b/src/strings.cpp index ac02b5178..f644eb795 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -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" diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index c54f3d826..08fd87d28 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -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" -- cgit v1.2.3-70-g09d2