summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-11-14 21:30:37 +0000
committerrubidium <rubidium@openttd.org>2011-11-14 21:30:37 +0000
commit6d991b3b10bad798f7e2afce1bc806dbdc3ced4b (patch)
tree49c462606a07d3243d66abb82b7467204753b705
parent160294ff22a2b30fc75be1977117eac6910bdd82 (diff)
downloadopenttd-6d991b3b10bad798f7e2afce1bc806dbdc3ced4b.tar.xz
(svn r23217) -Codechange: introduce the concept of scanning only in a limited set of sub directories
-rw-r--r--src/console_cmds.cpp4
-rw-r--r--src/fileio.cpp19
-rw-r--r--src/fileio_func.h15
-rw-r--r--src/network/network_content_gui.cpp30
-rw-r--r--src/newgrf_config.cpp2
-rw-r--r--src/newgrf_gui.cpp2
-rw-r--r--src/openttd.cpp4
7 files changed, 60 insertions, 16 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 7775a4a31..043d43b0c 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1251,7 +1251,7 @@ DEF_CONSOLE_CMD(ConRescanAI)
return true;
}
- TarScanner::DoScan();
+ TarScanner::DoScan(TarScanner::AI);
AI::Rescan();
return true;
@@ -1265,7 +1265,7 @@ DEF_CONSOLE_CMD(ConRescanNewGRF)
return true;
}
- TarScanner::DoScan();
+ TarScanner::DoScan(TarScanner::NEWGRF);
ScanNewGRFFiles(NULL);
return true;
diff --git a/src/fileio.cpp b/src/fileio.cpp
index c12ede866..2722b651d 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -645,14 +645,21 @@ uint TarScanner::DoScan(Subdirectory sd)
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 @@ void DeterminePaths(const char *exe)
_searchpaths[SP_AUTODOWNLOAD_DIR] = NULL;
}
#endif /* ENABLE_NETWORK */
-
- TarScanner::DoScan();
}
/**
diff --git a/src/fileio_func.h b/src/fileio_func.h
index e4d8cff77..ddc86f692 100644
--- 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 @@ public:
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>
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index ed293f2cd..782f3d52c 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -86,7 +86,35 @@ public:
/** 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++) {
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index b25e669be..d62ab8b9b 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -636,8 +636,6 @@ void DoScanNewGRFFiles(void *callback)
ClearGRFConfigList(&_all_grfs);
- TarScanner::DoScan();
-
DEBUG(grf, 1, "Scanning for NewGRFs");
uint num = GRFFileScanner::DoScan();
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 1aa86a481..f0a430d73 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -1172,7 +1172,7 @@ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback {
case SNGRFS_RESCAN_FILES:
case SNGRFS_RESCAN_FILES2:
- TarScanner::DoScan();
+ TarScanner::DoScan(TarScanner::NEWGRF);
ScanNewGRFFiles(this);
break;
}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 4a248e7fc..c82d7d823 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -200,7 +200,6 @@ static void ShowHelp()
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 @@ int ttd_main(int argc, char *argv[])
* 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 @@ int ttd_main(int argc, char *argv[])
#endif
DeterminePaths(argv[0]);
+ TarScanner::DoScan(TarScanner::ALL);
BaseGraphics::FindSets();
BaseSounds::FindSets();
BaseMusic::FindSets();
@@ -650,7 +651,6 @@ int ttd_main(int argc, char *argv[])
#endif
#endif
- TarScanner::DoScan();
AI::Initialize();
LoadFromConfig();
AI::Uninitialize(true);