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
 
@@ -1242,39 +1242,39 @@ DEF_CONSOLE_CMD(ConStopAI)
 
DEF_CONSOLE_CMD(ConRescanAI)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Rescan the AI dir for scripts. Usage: 'rescan_ai'");
 
		return true;
 
	}
 

	
 
	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 */
 

	
 
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)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Returns the seed used to create this game. Usage: 'getseed'");
 
		IConsoleHelp("The seed can be used to reproduce the exact same map as the game started with.");
 
		return true;
 
	}
src/fileio.cpp
Show inline comments
 
@@ -636,32 +636,39 @@ static void SimplifyFileName(char *name)
 
/**
 
 * Perform the scanning of a particular subdirectory.
 
 * @param subdir The subdirectory to scan.
 
 * @return The number of found tar files.
 
 */
 
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)
 
{
 
	/* No tar within tar. */
 
	assert(tar_filename == NULL);
 

	
 
	/* The TAR-header, repeated for every file */
 
	typedef struct TarHeader {
 
		char name[100];      ///< Name of the file
 
@@ -1181,26 +1188,24 @@ void DeterminePaths(const char *exe)
 
	}
 

	
 
	extern char *_log_file;
 
	_log_file = str_fmt("%sopenttd.log",  _personal_dir);
 
#else /* ENABLE_NETWORK */
 
	/* If we don't have networking, we don't need to make the directory. But
 
	 * 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
 
 */
 
void SanitizeFilename(char *filename)
 
{
 
	for (; *filename != '\0'; filename++) {
 
		switch (*filename) {
 
			/* The following characters are not allowed in filenames
 
			 * on at least one of the supported operating systems: */
src/fileio_func.h
Show inline comments
 
@@ -3,24 +3,25 @@
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @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);
 
byte FioReadByte();
 
uint16 FioReadWord();
 
uint32 FioReadDword();
 
void FioCloseAll();
 
void FioOpenFile(int slot, const char *filename, Subdirectory subdir);
 
void FioReadBlock(void *ptr, size_t size);
 
@@ -83,30 +84,42 @@ public:
 
	 * @param basepath_length amount of characters to chop of before to get a
 
	 *                        filename relative to the search path.
 
	 * @param tar_filename    the name of the tar file the file is read from.
 
	 * @return true if the file is added.
 
	 */
 
	virtual bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) = 0;
 
};
 

	
 
/** 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
 
	TCHAR *d_name; // name of found file
 
	/* little hack which will point to parent DIR struct which will
 
	 * save us a call to GetFileAttributes if we want information
 
	 * about the file (for example in function fio_bla) */
 
	DIR *dir;
 
};
src/network/network_content_gui.cpp
Show inline comments
 
@@ -77,25 +77,53 @@ public:
 
	{
 
		this->parent = FindWindowById(WC_NETWORK_WINDOW, 1);
 

	
 
		_network_content_client.AddCallback(this);
 
		_network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes);
 

	
 
		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:
 
					AI::Rescan();
 
					break;
 

	
 
				case CONTENT_TYPE_BASE_GRAPHICS:
 
					BaseGraphics::FindSets();
 
					SetWindowDirty(WC_GAME_OPTIONS, 0);
src/newgrf_config.cpp
Show inline comments
 
@@ -627,26 +627,24 @@ static int CDECL GRFSorter(GRFConfig * c
 
}
 

	
 
/**
 
 * Really perform the scan for all NewGRFs.
 
 * @param callback The callback to call after the scanning is complete.
 
 */
 
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.
 
		* For that we first have to make an array, then sort and
 
		* then remake the linked list. */
 
		GRFConfig **to_sort = MallocT<GRFConfig*>(num);
 

	
 
		uint i = 0;
 
		for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) {
src/newgrf_gui.cpp
Show inline comments
 
@@ -1163,25 +1163,25 @@ struct NewGRFWindow : public QueryString
 
						ttd_strlcpy(ci->name, c->GetName(), lengthof(ci->name));
 
						ci->unique_id = BSWAP32(c->ident.grfid);
 
						memcpy(ci->md5sum, HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum, sizeof(ci->md5sum));
 
						*cv.Append() = ci;
 
					}
 
					ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF);
 
#endif
 
				}
 
				break;
 

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

	
 
	virtual void OnNewGRFsScanned()
 
	{
 
		this->avail_sel = NULL;
 
		this->avail_pos = -1;
 
		this->avails.ForceRebuild();
 
		this->DeleteChildWindows(WC_QUERY_STRING);  // Remove the parameter query window
 
		this->DeleteChildWindows(WC_NEWGRF_README); // Remove the view readme window
src/openttd.cpp
Show inline comments
 
@@ -191,25 +191,24 @@ static void ShowHelp()
 
	p = BaseSounds::GetSetsList(p, lastof(buf));
 

	
 
	/* List the music packs */
 
	p = BaseMusic::GetSetsList(p, lastof(buf));
 

	
 
	/* List the drivers */
 
	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 */
 
#if !defined(WIN32) && !defined(WIN64)
 
	printf("%s\n", buf);
 
#else
 
	ShowInfo(buf);
 
#endif
 
}
 
@@ -613,53 +612,54 @@ int ttd_main(int argc, char *argv[])
 
			break;
 
		}
 
		if (i == -2) break;
 
	}
 

	
 
	if (i == -2 || mgo.numleft > 0) {
 
		/* 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;
 
	}
 

	
 
#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);
 
	if (_dedicated_forks && !dedicated) _dedicated_forks = false;
 

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

	
 
	/*
 
	 * The width and height must be at least 1 pixel and width times
 
	 * height times bytes per pixel must still fit within a 32 bits
 
	 * integer, even for 32 bpp video modes. This way all internal
 
	 * drawing routines work correctly.
 
	 */
0 comments (0 inline, 0 general)