mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r22824) -Codechange: pass sub directory to ini loading
This commit is contained in:
parent
5f06d5067f
commit
05300a00b1
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue