changeset 18015:7f4c6ab61bcc draft

(svn r22824) -Codechange: pass sub directory to ini loading
author rubidium <rubidium@openttd.org>
date Wed, 24 Aug 2011 13:38:26 +0000
parents 0c0d50f3519a
children 09780d1c580a
files src/base_media_func.h src/hotkeys.cpp src/ini.cpp src/ini_load.cpp src/ini_type.h src/settings.cpp src/settingsgen/settingsgen.cpp
diffstat 7 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/base_media_func.h
+++ b/src/base_media_func.h
@@ -155,7 +155,7 @@
 
 	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);
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -253,7 +253,7 @@
 static void SaveLoadHotkeys(bool save)
 {
 	IniFile *ini = new IniFile();
-	ini->LoadFromDisk(_hotkeys_file);
+	ini->LoadFromDisk(_hotkeys_file, BASE_DIR);
 
 	IniGroup *group;
 
--- a/src/ini.cpp
+++ b/src/ini.cpp
@@ -111,11 +111,11 @@
 	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)
--- a/src/ini_load.cpp
+++ b/src/ini_load.cpp
@@ -204,9 +204,10 @@
 /**
  * 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 @@
 	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);
--- 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 @@
 	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 @@
 
 	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);
 };
 
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1503,7 +1503,7 @@
 static IniFile *IniLoadConfig()
 {
 	IniFile *ini = new IniFile(_list_group_names);
-	ini->LoadFromDisk(_config_file);
+	ini->LoadFromDisk(_config_file, BASE_DIR);
 	return ini;
 }
 
--- a/src/settingsgen/settingsgen.cpp
+++ b/src/settingsgen/settingsgen.cpp
@@ -173,7 +173,7 @@
 	{
 	}
 
-	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 @@
 /**
  * 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 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;
 }