From a20b833516d0a10edc7196b90cae30fe7d78a763 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 31 Aug 2008 10:50:05 +0000 Subject: [PATCH] (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. --- projects/openttd_vs80.vcproj | 6 ++- projects/openttd_vs90.vcproj | 6 ++- source.list | 3 +- src/console_cmds.cpp | 2 +- src/fileio.cpp | 2 +- src/{fileio.h => fileio_func.h} | 90 +++++++++++++++++++-------------- 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 +- 28 files changed, 128 insertions(+), 109 deletions(-) rename src/{fileio.h => fileio_func.h} (63%) create mode 100644 src/fileio_type.h diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index ec8132ffd7..65879058df 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -992,7 +992,11 @@ > + + + + +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 0000000000..baef9c70de --- /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 cdecb1b346..1161792282 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 40982bf4d9..d40292be1e 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 c6497bb0b1..f76e90968e 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 7c1786a741..defc913c9d 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 6c7221ac45..25f8e3baf0 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 aa2a8f97d4..002fb50709 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 dff8c220d5..e2b355c6f3 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 4814973a1d..0b07e7da08 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 56f8b724e5..d1e1614f63 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 1f8756d0a4..fadb9f57d4 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 6faeb8d773..98ba8d420a 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 61f466056d..73589937ca 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 a05302a1c9..180d80ecea 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 dfe07350cd..df2dc9f07b 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 6f5cc0105e..5a9ef0581b 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 ab5872b12e..81c22cbb44 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 d9c2498a8a..616eb59b14 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 0bd73f9274..871a9fa0a4 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 54d04a3a89..4ccc502aab 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 ac02b51783..f644eb7950 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 c54f3d8263..08fd87d280 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"