1
0
Fork 0

(svn r23217) -Codechange: introduce the concept of scanning only in a limited set of sub directories

release/1.2
rubidium 2011-11-14 21:30:37 +00:00
parent 160294ff22
commit 6d991b3b10
7 changed files with 60 additions and 16 deletions

View File

@ -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;

View File

@ -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();
}
/**

View File

@ -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>

View File

@ -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++) {

View File

@ -636,8 +636,6 @@ void DoScanNewGRFFiles(void *callback)
ClearGRFConfigList(&_all_grfs);
TarScanner::DoScan();
DEBUG(grf, 1, "Scanning for NewGRFs");
uint num = GRFFileScanner::DoScan();

View File

@ -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;
}

View File

@ -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);