Changeset - r18371:8ec67d29c1db
[Not reviewed]
master
0 7 0
rubidium - 13 years ago 2011-11-14 21:30:37
rubidium@openttd.org
(svn r23217) -Codechange: introduce the concept of scanning only in a limited set of sub directories
7 files changed with 60 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -1248,13 +1248,13 @@ DEF_CONSOLE_CMD(ConRescanAI)
 

	
 
	if (_networking && !_network_server) {
 
		IConsoleWarning("Only the server can rescan the AI dir for scripts.");
 
		return true;
 
	}
 

	
 
	TarScanner::DoScan();
 
	TarScanner::DoScan(TarScanner::AI);
 
	AI::Rescan();
 

	
 
	return true;
 
}
 
#endif /* ENABLE_AI */
 

	
 
@@ -1262,13 +1262,13 @@ DEF_CONSOLE_CMD(ConRescanNewGRF)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Rescan the data dir for NewGRFs. Usage: 'rescan_newgrf'");
 
		return true;
 
	}
 

	
 
	TarScanner::DoScan();
 
	TarScanner::DoScan(TarScanner::NEWGRF);
 
	ScanNewGRFFiles(NULL);
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConGetSeed)
src/fileio.cpp
Show inline comments
 
@@ -642,20 +642,27 @@ uint TarScanner::DoScan(Subdirectory sd)
 
{
 
	_tar_filelist[sd].clear();
 
	_tar_list[sd].clear();
 
	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;
 
}
 

	
 
bool TarScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
 
{
 
@@ -1187,14 +1194,12 @@ void DeterminePaths(const char *exe)
 
	 * if it exists we keep it, otherwise remove it from the search paths. */
 
	if (!FileExists(_searchpaths[SP_AUTODOWNLOAD_DIR]))  {
 
		free(_searchpaths[SP_AUTODOWNLOAD_DIR]);
 
		_searchpaths[SP_AUTODOWNLOAD_DIR] = NULL;
 
	}
 
#endif /* ENABLE_NETWORK */
 

	
 
	TarScanner::DoScan();
 
}
 

	
 
/**
 
 * Sanitizes a filename, i.e. removes all illegal characters from it.
 
 * @param filename the "\0" terminated filename
 
 */
src/fileio_func.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
/** @file fileio_func.h Functions for Standard In/Out file operations */
 

	
 
#ifndef FILEIO_FUNC_H
 
#define FILEIO_FUNC_H
 

	
 
#include "core/enum_type.hpp"
 
#include "fileio_type.h"
 

	
 
void FioSeekTo(size_t pos, int mode);
 
void FioSeekToFile(uint8 slot, size_t pos);
 
size_t FioGetPos();
 
const char *FioGetFilename(uint8 slot);
 
@@ -89,18 +90,30 @@ public:
 
};
 

	
 
/** Helper for scanning for files with tar as extension */
 
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>
 
struct DIR;
 

	
 
struct dirent { // XXX - only d_name implemented
src/network/network_content_gui.cpp
Show inline comments
 
@@ -83,13 +83,41 @@ public:
 
		this->InitNested(&_network_content_download_status_window_desc, 0);
 
	}
 

	
 
	/** 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++) {
 
			switch (*iter) {
 
				case CONTENT_TYPE_AI:
 
				case CONTENT_TYPE_AI_LIBRARY:
src/newgrf_config.cpp
Show inline comments
 
@@ -633,14 +633,12 @@ static int CDECL GRFSorter(GRFConfig * c
 
void DoScanNewGRFFiles(void *callback)
 
{
 
	_modal_progress_work_mutex->BeginCritical();
 

	
 
	ClearGRFConfigList(&_all_grfs);
 

	
 
	TarScanner::DoScan();
 

	
 
	DEBUG(grf, 1, "Scanning for NewGRFs");
 
	uint num = GRFFileScanner::DoScan();
 

	
 
	DEBUG(grf, 1, "Scan complete, found %d files", num);
 
	if (num != 0 && _all_grfs != NULL) {
 
		/* Sort the linked list using quicksort.
src/newgrf_gui.cpp
Show inline comments
 
@@ -1169,13 +1169,13 @@ struct NewGRFWindow : public QueryString
 
#endif
 
				}
 
				break;
 

	
 
			case SNGRFS_RESCAN_FILES:
 
			case SNGRFS_RESCAN_FILES2:
 
				TarScanner::DoScan();
 
				TarScanner::DoScan(TarScanner::NEWGRF);
 
				ScanNewGRFFiles(this);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnNewGRFsScanned()
src/openttd.cpp
Show inline comments
 
@@ -197,13 +197,12 @@ static void ShowHelp()
 
	p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf));
 

	
 
	/* List the blitters */
 
	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);
 

	
 
	/* ShowInfo put output to stderr, but version information should go
 
	 * to stdout; this is the only exception */
 
@@ -619,12 +618,13 @@ int ttd_main(int argc, char *argv[])
 
		/* Either the user typed '-h', he made an error, or he added unrecognized command line arguments.
 
		 * In all cases, print the help, and exit.
 
		 *
 
		 * 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();
 
		ShowHelp();
 
		delete scanner;
 
		return 0;
 
@@ -633,12 +633,13 @@ int ttd_main(int argc, char *argv[])
 
#if defined(WINCE) && defined(_DEBUG)
 
	/* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
 
	SetDebugString("4");
 
#endif
 

	
 
	DeterminePaths(argv[0]);
 
	TarScanner::DoScan(TarScanner::ALL);
 
	BaseGraphics::FindSets();
 
	BaseSounds::FindSets();
 
	BaseMusic::FindSets();
 

	
 
#if defined(ENABLE_NETWORK)
 
	if (dedicated) DEBUG(net, 0, "Starting dedicated version %s", _openttd_revision);
 
@@ -647,13 +648,12 @@ int ttd_main(int argc, char *argv[])
 
#if defined(UNIX) && !defined(__MORPHOS__)
 
	/* We must fork here, or we'll end up without some resources we need (like sockets) */
 
	if (_dedicated_forks) DedicatedFork();
 
#endif
 
#endif
 

	
 
	TarScanner::DoScan();
 
	AI::Initialize();
 
	LoadFromConfig();
 
	AI::Uninitialize(true);
 

	
 
	if (resolution.width != 0) { _cur_resolution = resolution; }
 

	
0 comments (0 inline, 0 general)