mirror of https://github.com/OpenTTD/OpenTTD
(svn r22824) -Codechange: pass sub directory to ini loading
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();
|
Tbase_set *set = new Tbase_set();
|
||||||
IniFile *ini = new IniFile();
|
IniFile *ini = new IniFile();
|
||||||
ini->LoadFromDisk(filename);
|
ini->LoadFromDisk(filename, Tbase_set::SUBDIR);
|
||||||
|
|
||||||
char *path = strdup(filename + basepath_length);
|
char *path = strdup(filename + basepath_length);
|
||||||
char *psep = strrchr(path, PATHSEPCHAR);
|
char *psep = strrchr(path, PATHSEPCHAR);
|
||||||
|
|
|
@ -253,7 +253,7 @@ struct SignListWindow;
|
||||||
static void SaveLoadHotkeys(bool save)
|
static void SaveLoadHotkeys(bool save)
|
||||||
{
|
{
|
||||||
IniFile *ini = new IniFile();
|
IniFile *ini = new IniFile();
|
||||||
ini->LoadFromDisk(_hotkeys_file);
|
ini->LoadFromDisk(_hotkeys_file, BASE_DIR);
|
||||||
|
|
||||||
IniGroup *group;
|
IniGroup *group;
|
||||||
|
|
||||||
|
|
|
@ -111,11 +111,11 @@ bool IniFile::SaveToDisk(const char *filename)
|
||||||
return true;
|
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
|
/* Open the text file in binary mode to prevent end-of-line translations
|
||||||
* done by ftell() and friends, as defined by K&R. */
|
* 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)
|
/* 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.
|
* Load the Ini file's data from the disk.
|
||||||
* @param filename the file to load.
|
* @param filename the file to load.
|
||||||
|
* @param subdir the sub directory to load the file from.
|
||||||
* @pre nothing has been loaded yet.
|
* @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);
|
assert(this->last_group == &this->group);
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ void IniLoadFile::LoadFromDisk(const char *filename)
|
||||||
uint comment_alloc = 0;
|
uint comment_alloc = 0;
|
||||||
|
|
||||||
size_t end;
|
size_t end;
|
||||||
FILE *in = this->OpenFile(filename, &end);
|
FILE *in = this->OpenFile(filename, subdir, &end);
|
||||||
if (in == NULL) return;
|
if (in == NULL) return;
|
||||||
|
|
||||||
end += ftell(in);
|
end += ftell(in);
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#ifndef INI_TYPE_H
|
#ifndef INI_TYPE_H
|
||||||
#define INI_TYPE_H
|
#define INI_TYPE_H
|
||||||
|
|
||||||
|
#include "fileio_type.h"
|
||||||
|
|
||||||
/** Types of groups */
|
/** Types of groups */
|
||||||
enum IniGroupType {
|
enum IniGroupType {
|
||||||
IGT_VARIABLES = 0, ///< Values of the form "landscape = hilly".
|
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);
|
IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
|
||||||
void RemoveGroup(const char *name);
|
void RemoveGroup(const char *name);
|
||||||
|
|
||||||
void LoadFromDisk(const char *filename);
|
void LoadFromDisk(const char *filename, Subdirectory subdir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the INI file.
|
* Open the INI file.
|
||||||
* @param filename Name of 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.
|
* @param size [out] Size of the opened file.
|
||||||
* @return File handle of the opened file, or \c NULL.
|
* @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.
|
* Report an error about the file contents.
|
||||||
|
@ -87,7 +90,7 @@ struct IniFile : IniLoadFile {
|
||||||
|
|
||||||
bool SaveToDisk(const char *filename);
|
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);
|
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()
|
static IniFile *IniLoadConfig()
|
||||||
{
|
{
|
||||||
IniFile *ini = new IniFile(_list_group_names);
|
IniFile *ini = new IniFile(_list_group_names);
|
||||||
ini->LoadFromDisk(_config_file);
|
ini->LoadFromDisk(_config_file, BASE_DIR);
|
||||||
return ini;
|
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
|
/* Open the text file in binary mode to prevent end-of-line translations
|
||||||
* done by ftell() and friends, as defined by K&R. */
|
* 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.
|
* Load the INI file.
|
||||||
* @param filename Name of the file to load.
|
* @param filename Name of the file to load.
|
||||||
|
* @param subdir The subdirectory to load from.
|
||||||
* @return Loaded INI data.
|
* @return Loaded INI data.
|
||||||
*/
|
*/
|
||||||
static IniLoadFile *LoadIniFile(const char *filename)
|
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};
|
static const char * const seq_groups[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, NULL};
|
||||||
|
|
||||||
IniLoadFile *ini = new SettingsIniFile(NULL, seq_groups);
|
IniLoadFile *ini = new SettingsIniFile(NULL, seq_groups);
|
||||||
ini->LoadFromDisk(filename);
|
ini->LoadFromDisk(filename, NO_DIRECTORY);
|
||||||
return ini;
|
return ini;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue