diff options
author | rubidium <rubidium@openttd.org> | 2011-08-24 13:38:26 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-08-24 13:38:26 +0000 |
commit | 05300a00b1c82b1c411b38fb024a6decfefce4f8 (patch) | |
tree | f13b4b5eb198dac31d5de390bd0041f0fa8e4746 | |
parent | 5f06d5067f861031dedd8de0ce0d21cd6f70a9a7 (diff) | |
download | openttd-05300a00b1c82b1c411b38fb024a6decfefce4f8.tar.xz |
(svn r22824) -Codechange: pass sub directory to ini loading
-rw-r--r-- | src/base_media_func.h | 2 | ||||
-rw-r--r-- | src/hotkeys.cpp | 2 | ||||
-rw-r--r-- | src/ini.cpp | 4 | ||||
-rw-r--r-- | src/ini_load.cpp | 5 | ||||
-rw-r--r-- | src/ini_type.h | 9 | ||||
-rw-r--r-- | src/settings.cpp | 2 | ||||
-rw-r--r-- | src/settingsgen/settingsgen.cpp | 5 |
7 files changed, 17 insertions, 12 deletions
diff --git a/src/base_media_func.h b/src/base_media_func.h index 6adf397c4..c9f4e21bb 100644 --- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -155,7 +155,7 @@ bool BaseMedia<Tbase_set>::AddFile(const char *filename, size_t basepath_length) Tbase_set *set = new Tbase_set(); IniFile *ini = new IniFile(); - ini->LoadFromDisk(filename); + ini->LoadFromDisk(filename, Tbase_set::SUBDIR); char *path = strdup(filename + basepath_length); char *psep = strrchr(path, PATHSEPCHAR); diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index 2434686cc..674c10c73 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -253,7 +253,7 @@ struct SignListWindow; static void SaveLoadHotkeys(bool save) { IniFile *ini = new IniFile(); - ini->LoadFromDisk(_hotkeys_file); + ini->LoadFromDisk(_hotkeys_file, BASE_DIR); IniGroup *group; diff --git a/src/ini.cpp b/src/ini.cpp index 016e382c9..fe49f5fe7 100644 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -111,11 +111,11 @@ bool IniFile::SaveToDisk(const char *filename) return true; } -/* virtual */ FILE *IniFile::OpenFile(const char *filename, size_t *size) +/* virtual */ FILE *IniFile::OpenFile(const char *filename, Subdirectory subdir, size_t *size) { /* Open the text file in binary mode to prevent end-of-line translations * done by ftell() and friends, as defined by K&R. */ - return FioFOpenFile(filename, "rb", BASESET_DIR, size); + return FioFOpenFile(filename, "rb", subdir, size); } /* virtual */ void IniFile::ReportFileError(const char * const pre, const char * const buffer, const char * const post) diff --git a/src/ini_load.cpp b/src/ini_load.cpp index ae59f6c83..6a2087303 100644 --- a/src/ini_load.cpp +++ b/src/ini_load.cpp @@ -204,9 +204,10 @@ void IniLoadFile::RemoveGroup(const char *name) /** * Load the Ini file's data from the disk. * @param filename the file to load. + * @param subdir the sub directory to load the file from. * @pre nothing has been loaded yet. */ -void IniLoadFile::LoadFromDisk(const char *filename) +void IniLoadFile::LoadFromDisk(const char *filename, Subdirectory subdir) { assert(this->last_group == &this->group); @@ -218,7 +219,7 @@ void IniLoadFile::LoadFromDisk(const char *filename) uint comment_alloc = 0; size_t end; - FILE *in = this->OpenFile(filename, &end); + FILE *in = this->OpenFile(filename, subdir, &end); if (in == NULL) return; end += ftell(in); diff --git a/src/ini_type.h b/src/ini_type.h index a011a798d..05133c77f 100644 --- a/src/ini_type.h +++ b/src/ini_type.h @@ -12,6 +12,8 @@ #ifndef INI_TYPE_H #define INI_TYPE_H +#include "fileio_type.h" + /** Types of groups */ enum IniGroupType { IGT_VARIABLES = 0, ///< Values of the form "landscape = hilly". @@ -62,15 +64,16 @@ struct IniLoadFile { IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true); void RemoveGroup(const char *name); - void LoadFromDisk(const char *filename); + void LoadFromDisk(const char *filename, Subdirectory subdir); /** * Open the INI file. * @param filename Name of the INI file. + * @param subdir The subdir to load the file from. * @param size [out] Size of the opened file. * @return File handle of the opened file, or \c NULL. */ - virtual FILE *OpenFile(const char *filename, size_t *size) = 0; + virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size) = 0; /** * Report an error about the file contents. @@ -87,7 +90,7 @@ struct IniFile : IniLoadFile { bool SaveToDisk(const char *filename); - virtual FILE *OpenFile(const char *filename, size_t *size); + virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size); virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post); }; diff --git a/src/settings.cpp b/src/settings.cpp index b0c5494f7..a688fc5aa 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1503,7 +1503,7 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP static IniFile *IniLoadConfig() { IniFile *ini = new IniFile(_list_group_names); - ini->LoadFromDisk(_config_file); + ini->LoadFromDisk(_config_file, BASE_DIR); return ini; } diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index ad602e360..7dd8aef43 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -173,7 +173,7 @@ struct SettingsIniFile : IniLoadFile { { } - virtual FILE *OpenFile(const char *filename, size_t *size) + virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size) { /* Open the text file in binary mode to prevent end-of-line translations * done by ftell() and friends, as defined by K&R. */ @@ -203,6 +203,7 @@ static const char *DEFAULTS_GROUP_NAME = "defaults"; ///< Name of the group c /** * Load the INI file. * @param filename Name of the file to load. + * @param subdir The subdirectory to load from. * @return Loaded INI data. */ static IniLoadFile *LoadIniFile(const char *filename) @@ -210,7 +211,7 @@ static IniLoadFile *LoadIniFile(const char *filename) static const char * const seq_groups[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, NULL}; IniLoadFile *ini = new SettingsIniFile(NULL, seq_groups); - ini->LoadFromDisk(filename); + ini->LoadFromDisk(filename, NO_DIRECTORY); return ini; } |