changeset 18013:7a582ee01092 draft

(svn r22822) -Codechange: make a distinction between base sets and newgrfs for their directory
author rubidium <rubidium@openttd.org>
date Wed, 24 Aug 2011 13:33:49 +0000
parents ab5d1e04c521
children 0c0d50f3519a
files src/ai/ai_scanner.cpp src/base_media_base.h src/fileio.cpp src/fileio_func.h src/fileio_type.h src/gfxinit.cpp src/ini.cpp src/network/network_content.cpp src/newgrf_config.cpp src/openttd.cpp
diffstat 10 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -384,7 +384,7 @@
 		byte tmp_md5sum[16];
 
 		/* Open the file ... */
-		FILE *f = FioFOpenFile(filename, "rb", DATA_DIR, &size);
+		FILE *f = FioFOpenFile(filename, "rb", AI_DIR, &size);
 		if (f == NULL) return false;
 
 		/* ... calculate md5sum... */
--- a/src/base_media_base.h
+++ b/src/base_media_base.h
@@ -198,7 +198,7 @@
 };
 
 /** All data of a graphics set. */
-struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, DATA_DIR> {
+struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, BASESET_DIR> {
 	PaletteType palette;       ///< Palette of this graphics set
 
 	bool FillSetDetails(struct IniFile *ini, const char *path, const char *full_filename);
@@ -210,7 +210,7 @@
 };
 
 /** All data of a sounds set. */
-struct SoundsSet : BaseSet<SoundsSet, 1, DATA_DIR> {
+struct SoundsSet : BaseSet<SoundsSet, 1, BASESET_DIR> {
 };
 
 /** All data/functions related with replacing the base sounds */
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -267,7 +267,7 @@
 	FioSeekToFile(slot, pos);
 }
 
-static const char * const _subdirs[NUM_SUBDIRS] = {
+static const char * const _subdirs[] = {
 	"",
 	"save" PATHSEP,
 	"save" PATHSEP "autosave" PATHSEP,
@@ -275,10 +275,12 @@
 	"scenario" PATHSEP "heightmap" PATHSEP,
 	"gm" PATHSEP,
 	"data" PATHSEP,
+	"data" PATHSEP,
 	"lang" PATHSEP,
 	"ai" PATHSEP,
 	"ai" PATHSEP "library" PATHSEP,
 };
+assert_compile(lengthof(_subdirs) == NUM_SUBDIRS);
 
 const char *_searchpaths[NUM_SEARCHPATHS];
 TarList _tar_list;
@@ -636,7 +638,7 @@
 
 	DEBUG(misc, 1, "Scanning for tars");
 	TarScanner fs;
-	uint num = fs.Scan(".tar", DATA_DIR, false);
+	uint num = fs.Scan(".tar", NEWGRF_DIR, false);
 	num += fs.Scan(".tar", AI_DIR, false);
 	num += fs.Scan(".tar", AI_LIBRARY_DIR, false);
 	num += fs.Scan(".tar", SCENARIO_DIR, false);
@@ -1156,7 +1158,7 @@
 	FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR]);
 
 	/* Create the directory for each of the types of content */
-	const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, DATA_DIR, AI_DIR, AI_LIBRARY_DIR, GM_DIR };
+	const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GM_DIR };
 	for (uint i = 0; i < lengthof(dirs); i++) {
 		char *tmp = str_fmt("%s%s", _searchpaths[SP_AUTODOWNLOAD_DIR], _subdirs[dirs[i]]);
 		FioCreateDirectory(tmp);
--- a/src/fileio_func.h
+++ b/src/fileio_func.h
@@ -48,8 +48,8 @@
 #define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
 
 void FioFCloseFile(FILE *f);
-FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
-bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
+FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = NEWGRF_DIR, size_t *filesize = NULL);
+bool FioCheckFileExists(const char *filename, Subdirectory subdir = NEWGRF_DIR);
 char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
 char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
--- a/src/fileio_type.h
+++ b/src/fileio_type.h
@@ -24,7 +24,8 @@
 	SCENARIO_DIR,  ///< Base directory for all scenarios
 	HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps
 	GM_DIR,        ///< Subdirectory for all music
-	DATA_DIR,      ///< Subdirectory for all data (GRFs, sample.cat, intro game)
+	BASESET_DIR,   ///< Subdirectory for all base data (base sets, intro game)
+	NEWGRF_DIR,    ///< Subdirectory for all NewGRFs
 	LANG_DIR,      ///< Subdirectory for all translation files
 	AI_DIR,        ///< Subdirectory for all AI files
 	AI_LIBRARY_DIR,///< Subdirectory for all AI libraries
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -108,7 +108,7 @@
 		/* Not all files were loaded successfully, see which ones */
 		add_pos += seprintf(add_pos, last, "Trying to load graphics set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of readme.txt.\n\nThe following files are corrupted or missing:\n", used_set->name);
 		for (uint i = 0; i < GraphicsSet::NUM_FILES; i++) {
-			MD5File::ChecksumResult res = used_set->files[i].CheckMD5(DATA_DIR);
+			MD5File::ChecksumResult res = used_set->files[i].CheckMD5(BASESET_DIR);
 			if (res != MD5File::CR_MATCH) add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", used_set->files[i].filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning);
 		}
 		add_pos += seprintf(add_pos, last, "\n");
@@ -121,7 +121,7 @@
 		assert_compile(SoundsSet::NUM_FILES == 1);
 		/* No need to loop each file, as long as there is only a single
 		 * sound file. */
-		add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename, sounds_set->files->CheckMD5(DATA_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
+		add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename, sounds_set->files->CheckMD5(BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
 	}
 
 	if (add_pos != error_msg) ShowInfoF("%s", error_msg);
@@ -208,7 +208,7 @@
 
 bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
 {
-	bool ret = this->BaseSet<GraphicsSet, MAX_GFT, DATA_DIR>::FillSetDetails(ini, path, full_filename, false);
+	bool ret = this->BaseSet<GraphicsSet, MAX_GFT, BASESET_DIR>::FillSetDetails(ini, path, full_filename, false);
 	if (ret) {
 		IniGroup *metadata = ini->GetGroup("metadata");
 		IniItem *item;
--- a/src/ini.cpp
+++ b/src/ini.cpp
@@ -115,7 +115,7 @@
 {
 	/* 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", DATA_DIR, size);
+	return FioFOpenFile(filename, "rb", BASESET_DIR, size);
 }
 
 /* virtual */ void IniFile::ReportFileError(const char * const pre, const char * const buffer, const char * const post)
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -375,10 +375,10 @@
 	Subdirectory dir;
 	switch (ci->type) {
 		default: return NULL;
-		case CONTENT_TYPE_BASE_GRAPHICS: dir = DATA_DIR;       break;
+		case CONTENT_TYPE_BASE_GRAPHICS: dir = BASESET_DIR;    break;
 		case CONTENT_TYPE_BASE_MUSIC:    dir = GM_DIR;         break;
-		case CONTENT_TYPE_BASE_SOUNDS:   dir = DATA_DIR;       break;
-		case CONTENT_TYPE_NEWGRF:        dir = DATA_DIR;       break;
+		case CONTENT_TYPE_BASE_SOUNDS:   dir = BASESET_DIR;    break;
+		case CONTENT_TYPE_NEWGRF:        dir = NEWGRF_DIR;     break;
 		case CONTENT_TYPE_AI:            dir = AI_DIR;         break;
 		case CONTENT_TYPE_AI_LIBRARY:    dir = AI_LIBRARY_DIR; break;
 		case CONTENT_TYPE_SCENARIO:      dir = SCENARIO_DIR;   break;
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -292,7 +292,7 @@
 	size_t len, size;
 
 	/* open the file */
-	f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size);
+	f = FioFOpenFile(config->filename, "rb", NEWGRF_DIR, &size);
 	if (f == NULL) return false;
 
 	/* calculate md5sum */
@@ -543,7 +543,7 @@
 	static uint DoScan()
 	{
 		GRFFileScanner fs;
-		int ret = fs.Scan(".grf", DATA_DIR);
+		int ret = fs.Scan(".grf", NEWGRF_DIR);
 		/* The number scanned and the number returned may not be the same;
 		 * duplicate NewGRFs and base sets are ignored in the return value. */
 		_settings_client.gui.last_newgrf_count = fs.num_scanned;
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -280,7 +280,7 @@
 	SetupColoursAndInitialWindow();
 
 	/* Load the default opening screen savegame */
-	if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
+	if (SaveOrLoad("opntitle.dat", SL_LOAD, BASESET_DIR) != SL_OK) {
 		GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
 		WaitTillGeneratedWorld();
 		SetLocalCompany(COMPANY_SPECTATOR);