Changeset - r11252:706b96dca92b
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-03-04 00:17:51
rubidium@openttd.org
(svn r15606) -Codechange: make it possible to not recursively search with the file scanner (i.e. only search a single directory).
2 files changed with 9 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -1022,7 +1022,7 @@ void *ReadFileToMem(const char *filename
 
 * @param path            full path we're currently at
 
 * @param basepath_length from where in the path are we 'based' on the search path
 
 */
 
static uint ScanPath(FileScanner *fs, const char *extension, const char *path, size_t basepath_length)
 
static uint ScanPath(FileScanner *fs, const char *extension, const char *path, size_t basepath_length, bool recursive)
 
{
 
	extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
 

	
 
@@ -1043,9 +1043,10 @@ static uint ScanPath(FileScanner *fs, co
 

	
 
		if (S_ISDIR(sb.st_mode)) {
 
			/* Directory */
 
			if (!recursive) continue;
 
			if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
 
			AppendPathSeparator(filename, lengthof(filename));
 
			num += ScanPath(fs, extension, filename, basepath_length);
 
			num += ScanPath(fs, extension, filename, basepath_length, recursive);
 
		} else if (S_ISREG(sb.st_mode)) {
 
			/* File */
 
			char *ext = strrchr(filename, '.');
 
@@ -1091,7 +1092,7 @@ static uint ScanTar(FileScanner *fs, con
 
 * @return the number of found files, i.e. the number of times that
 
 *         AddFile returned true.
 
 */
 
uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars)
 
uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool recursive)
 
{
 
	Searchpath sp;
 
	char path[MAX_PATH];
 
@@ -1100,7 +1101,7 @@ uint FileScanner::Scan(const char *exten
 

	
 
	FOR_ALL_SEARCHPATHS(sp) {
 
		FioAppendDirectory(path, MAX_PATH, sp, sd);
 
		num += ScanPath(this, extension, path, strlen(path));
 
		num += ScanPath(this, extension, path, strlen(path), recursive);
 
	}
 

	
 
	if (tars) {
 
@@ -1119,10 +1120,10 @@ uint FileScanner::Scan(const char *exten
 
 * @return the number of found files, i.e. the number of times that
 
 *         AddFile returned true.
 
 */
 
uint FileScanner::Scan(const char *extension, const char *directory)
 
uint FileScanner::Scan(const char *extension, const char *directory, bool recursive)
 
{
 
	char path[MAX_PATH];
 
	strecpy(path, directory, lastof(path));
 
	AppendPathSeparator(path, lengthof(path));
 
	return ScanPath(this, extension, path, strlen(path));
 
	return ScanPath(this, extension, path, strlen(path), recursive);
 
}
src/fileio_func.h
Show inline comments
 
@@ -73,8 +73,8 @@ public:
 
	/** Destruct the proper one... */
 
	virtual ~FileScanner() {}
 

	
 
	uint Scan(const char *extension, Subdirectory sd, bool tars = true);
 
	uint Scan(const char *extension, const char *directory);
 
	uint Scan(const char *extension, Subdirectory sd, bool tars = true, bool recursive = true);
 
	uint Scan(const char *extension, const char *directory, bool recursive = true);
 

	
 
	/**
 
	 * Add a file with the given filename.
0 comments (0 inline, 0 general)