changeset 18381:6f9fad8837de draft

(svn r23217) -Codechange: introduce the concept of scanning only in a limited set of sub directories
author rubidium <rubidium@openttd.org>
date Mon, 14 Nov 2011 21:30:37 +0000
parents fec80cdeaab7
children ee500e57ab78
files src/console_cmds.cpp src/fileio.cpp src/fileio_func.h src/network/network_content_gui.cpp src/newgrf_config.cpp src/newgrf_gui.cpp src/openttd.cpp
diffstat 7 files changed, 60 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1251,7 +1251,7 @@
 		return true;
 	}
 
-	TarScanner::DoScan();
+	TarScanner::DoScan(TarScanner::AI);
 	AI::Rescan();
 
 	return true;
@@ -1265,7 +1265,7 @@
 		return true;
 	}
 
-	TarScanner::DoScan();
+	TarScanner::DoScan(TarScanner::NEWGRF);
 	ScanNewGRFFiles(NULL);
 
 	return true;
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -645,14 +645,21 @@
 	return this->Scan(".tar", sd, false);
 }
 
-/* static */ uint TarScanner::DoScan()
+/* static */ uint TarScanner::DoScan(TarScanner::Mode mode)
 {
 	DEBUG(misc, 1, "Scanning for tars");
 	TarScanner fs;
-	uint num = fs.DoScan(NEWGRF_DIR);
-	num += fs.DoScan(AI_DIR);
-	num += fs.DoScan(AI_LIBRARY_DIR);
-	num += fs.DoScan(SCENARIO_DIR);
+	uint num = 0;
+	if (mode & (TarScanner::BASESET | TarScanner::NEWGRF)) {
+		num += fs.DoScan(NEWGRF_DIR);
+	}
+	if (mode & TarScanner::AI) {
+		num += fs.DoScan(AI_DIR);
+		num += fs.DoScan(AI_LIBRARY_DIR);
+	}
+	if (mode & TarScanner::SCENARIO) {
+		num += fs.DoScan(SCENARIO_DIR);
+	}
 	DEBUG(misc, 1, "Scan complete, found %d files", num);
 	return num;
 }
@@ -1190,8 +1197,6 @@
 		_searchpaths[SP_AUTODOWNLOAD_DIR] = NULL;
 	}
 #endif /* ENABLE_NETWORK */
-
-	TarScanner::DoScan();
 }
 
 /**
--- a/src/fileio_func.h
+++ b/src/fileio_func.h
@@ -12,6 +12,7 @@
 #ifndef FILEIO_FUNC_H
 #define FILEIO_FUNC_H
 
+#include "core/enum_type.hpp"
 #include "fileio_type.h"
 
 void FioSeekTo(size_t pos, int mode);
@@ -92,12 +93,24 @@
 class TarScanner : FileScanner {
 	uint DoScan(Subdirectory sd);
 public:
+	/** The mode of tar scanning. */
+	enum Mode {
+		NONE     = 0,      ///< Scan nothing.
+		BASESET  = 1 << 0, ///< Scan for base sets.
+		NEWGRF   = 1 << 1, ///< Scan for non-base sets.
+		AI       = 1 << 2, ///< Scan for AIs and its libraries.
+		SCENARIO = 1 << 3, ///< Scan for scenarios and heightmaps.
+		ALL      = BASESET | NEWGRF | AI | SCENARIO ///< Scan for everything.
+	};
+
 	/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL);
 
 	/** Do the scan for Tars. */
-	static uint DoScan();
+	static uint DoScan(TarScanner::Mode mode);
 };
 
+DECLARE_ENUM_AS_BIT_SET(TarScanner::Mode)
+
 /* Implementation of opendir/readdir/closedir for Windows */
 #if defined(WIN32)
 #include <windows.h>
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -86,7 +86,35 @@
 	/** Free whatever we've allocated */
 	~NetworkContentDownloadStatusWindow()
 	{
-		TarScanner::DoScan();
+		TarScanner::Mode mode = TarScanner::NONE;
+		for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
+			switch (*iter) {
+				case CONTENT_TYPE_AI:
+				case CONTENT_TYPE_AI_LIBRARY:
+					mode |= TarScanner::AI;
+					break;
+
+				case CONTENT_TYPE_BASE_GRAPHICS:
+				case CONTENT_TYPE_BASE_SOUNDS:
+				case CONTENT_TYPE_BASE_MUSIC:
+					mode |= TarScanner::BASESET;
+					break;
+
+				case CONTENT_TYPE_NEWGRF:
+					mode |= TarScanner::NEWGRF;
+					break;
+
+				case CONTENT_TYPE_SCENARIO:
+				case CONTENT_TYPE_HEIGHTMAP:
+					mode |= TarScanner::SCENARIO;
+					break;
+
+				default:
+					break;
+			}
+		}
+
+		TarScanner::DoScan(mode);
 
 		/* Tell all the backends about what we've downloaded */
 		for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -636,8 +636,6 @@
 
 	ClearGRFConfigList(&_all_grfs);
 
-	TarScanner::DoScan();
-
 	DEBUG(grf, 1, "Scanning for NewGRFs");
 	uint num = GRFFileScanner::DoScan();
 
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -1172,7 +1172,7 @@
 
 			case SNGRFS_RESCAN_FILES:
 			case SNGRFS_RESCAN_FILES2:
-				TarScanner::DoScan();
+				TarScanner::DoScan(TarScanner::NEWGRF);
 				ScanNewGRFFiles(this);
 				break;
 		}
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -200,7 +200,6 @@
 	p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
 
 	/* We need to initialize the AI, so it finds the AIs */
-	TarScanner::DoScan();
 	AI::Initialize();
 	p = AI::GetConsoleList(p, lastof(buf), true);
 	AI::Uninitialize(true);
@@ -622,6 +621,7 @@
 		 * The next two functions are needed to list the graphics sets. We can't do them earlier
 		 * because then we cannot show it on the debug console as that hasn't been configured yet. */
 		DeterminePaths(argv[0]);
+		TarScanner::DoScan(TarScanner::AI | TarScanner::BASESET);
 		BaseGraphics::FindSets();
 		BaseSounds::FindSets();
 		BaseMusic::FindSets();
@@ -636,6 +636,7 @@
 #endif
 
 	DeterminePaths(argv[0]);
+	TarScanner::DoScan(TarScanner::ALL);
 	BaseGraphics::FindSets();
 	BaseSounds::FindSets();
 	BaseMusic::FindSets();
@@ -650,7 +651,6 @@
 #endif
 #endif
 
-	TarScanner::DoScan();
 	AI::Initialize();
 	LoadFromConfig();
 	AI::Uninitialize(true);