Changeset - r18005:27851770b57d
[Not reviewed]
master
0 7 0
rubidium - 13 years ago 2011-08-24 13:38:26
rubidium@openttd.org
(svn r22824) -Codechange: pass sub directory to ini loading
7 files changed with 17 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/base_media_func.h
Show inline comments
 
@@ -155,7 +155,7 @@ bool BaseMedia<Tbase_set>::AddFile(const
 

	
 
	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);
src/hotkeys.cpp
Show inline comments
 
@@ -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;
 

	
src/ini.cpp
Show inline comments
 
@@ -111,11 +111,11 @@ bool IniFile::SaveToDisk(const char *fil
 
	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)
src/ini_load.cpp
Show inline comments
 
@@ -204,9 +204,10 @@ void IniLoadFile::RemoveGroup(const char
 
/**
 
 * 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 cha
 
	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);
src/ini_type.h
Show inline comments
 
@@ -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);
 
};
 

	
src/settings.cpp
Show inline comments
 
@@ -1503,7 +1503,7 @@ static void HandleSettingDescs(IniFile *
 
static IniFile *IniLoadConfig()
 
{
 
	IniFile *ini = new IniFile(_list_group_names);
 
	ini->LoadFromDisk(_config_file);
 
	ini->LoadFromDisk(_config_file, BASE_DIR);
 
	return ini;
 
}
 

	
src/settingsgen/settingsgen.cpp
Show inline comments
 
@@ -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  
 
/**
 
 * 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 ch
 
	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;
 
}
 

	
0 comments (0 inline, 0 general)