diff options
author | rubidium <rubidium@openttd.org> | 2009-03-04 00:17:51 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-03-04 00:17:51 +0000 |
commit | fb978c04b18fef71a0caa9737ea16688dfb25d74 (patch) | |
tree | af8b4cbcec546f4be494ede2609e3cb1fb519f8a /src | |
parent | 9e3449ecc933f561eb85618aa0fb32a624cae7dd (diff) | |
download | openttd-fb978c04b18fef71a0caa9737ea16688dfb25d74.tar.xz |
(svn r15606) -Codechange: make it possible to not recursively search with the file scanner (i.e. only search a single directory).
Diffstat (limited to 'src')
-rw-r--r-- | src/fileio.cpp | 13 | ||||
-rw-r--r-- | src/fileio_func.h | 4 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp index 59620df5c..85c4e2d04 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -1022,7 +1022,7 @@ void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) * @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, const char *extension, const char *path, s 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, const char *extension, TarFileList::iterato * @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 *extension, Subdirectory sd, bool tars) 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 *extension, Subdirectory sd, bool tars) * @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); } diff --git a/src/fileio_func.h b/src/fileio_func.h index d86696358..19bf12550 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -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. |