diff options
author | rubidium <rubidium@openttd.org> | 2010-05-10 09:37:17 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-05-10 09:37:17 +0000 |
commit | 948beec597f788bc661bf7869d4ab27945215e53 (patch) | |
tree | 3d49135c91d76b6c2dc3b7daeebfbfe4e4c9a7ab /src | |
parent | 8a2fecbff5532f5208c457d6f49742f4cc0ff754 (diff) | |
download | openttd-948beec597f788bc661bf7869d4ab27945215e53.tar.xz |
(svn r19777) -Change: use the file scanner to find the .tars
Diffstat (limited to 'src')
-rw-r--r-- | src/fileio.cpp | 75 | ||||
-rw-r--r-- | src/fileio_func.h | 8 | ||||
-rw-r--r-- | src/network/network_content.cpp | 4 |
3 files changed, 23 insertions, 64 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp index dfa3dca1d..9ffa10777 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -534,7 +534,18 @@ static void SimplifyFileName(char *name) #endif } -bool TarListAddFile(const char *filename) +/* static */ uint TarScanner::DoScan() { + DEBUG(misc, 1, "Scanning for tars"); + TarScanner fs; + uint num = fs.Scan(".tar", DATA_DIR, false); + num += fs.Scan(".tar", AI_DIR, false); + num += fs.Scan(".tar", AI_LIBRARY_DIR, false); + num += fs.Scan(".tar", SCENARIO_DIR, false); + DEBUG(misc, 1, "Scan complete, found %d files", num); + return num; +} + +bool TarScanner::AddFile(const char *filename, size_t basepath_length) { /* The TAR-header, repeated for every file */ typedef struct TarHeader { @@ -820,66 +831,6 @@ bool ExtractTar(const char *tar_filename) return true; } -static int ScanPathForTarFiles(const char *path, size_t basepath_length) -{ - extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); - - uint num = 0; - struct stat sb; - struct dirent *dirent; - DIR *dir; - - if (path == NULL || (dir = ttd_opendir(path)) == NULL) return 0; - - while ((dirent = readdir(dir)) != NULL) { - const char *d_name = FS2OTTD(dirent->d_name); - char filename[MAX_PATH]; - - if (!FiosIsValidFile(path, dirent, &sb)) continue; - - snprintf(filename, lengthof(filename), "%s%s", path, d_name); - - if (S_ISDIR(sb.st_mode)) { - /* Directory */ - if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; - AppendPathSeparator(filename, lengthof(filename)); - num += ScanPathForTarFiles(filename, basepath_length); - } else if (S_ISREG(sb.st_mode)) { - /* File */ - char *ext = strrchr(filename, '.'); - - /* If no extension or extension isn't .tar, skip the file */ - if (ext == NULL) continue; - if (strcasecmp(ext, ".tar") != 0) continue; - - if (TarListAddFile(filename)) num++; - } - } - - closedir(dir); - return num; -} - -void ScanForTarFiles() -{ - Searchpath sp; - char path[MAX_PATH]; - uint num = 0; - - DEBUG(misc, 1, "Scanning for tars"); - FOR_ALL_SEARCHPATHS(sp) { - FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR); - num += ScanPathForTarFiles(path, strlen(path)); - FioAppendDirectory(path, MAX_PATH, sp, AI_DIR); - num += ScanPathForTarFiles(path, strlen(path)); - FioAppendDirectory(path, MAX_PATH, sp, AI_LIBRARY_DIR); - num += ScanPathForTarFiles(path, strlen(path)); - FioAppendDirectory(path, MAX_PATH, sp, SCENARIO_DIR); - num += ScanPathForTarFiles(path, strlen(path)); - } - DEBUG(misc, 1, "Scan complete, found %d files", num); -} - #if defined(WIN32) || defined(WINCE) /** * Determine the base (personal dir and game data dir) paths @@ -1079,7 +1030,7 @@ void DeterminePaths(const char *exe) } #endif /* ENABLE_NETWORK */ - ScanForTarFiles(); + TarScanner::DoScan(); } /** diff --git a/src/fileio_func.h b/src/fileio_func.h index 53b3aa233..05253b432 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -87,6 +87,14 @@ public: virtual bool AddFile(const char *filename, size_t basepath_length) = 0; }; +/** Helper for scanning for files with tar as extension */ +class TarScanner : FileScanner { +public: + /* virtual */ bool AddFile(const char *filename, size_t basepath_length); + + /** Do the scan for Tars. */ + static uint DoScan(); +}; /* Implementation of opendir/readdir/closedir for Windows */ #if defined(WIN32) diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index c722fd585..062586593 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -27,7 +27,6 @@ #include <zlib.h> #endif -extern bool TarListAddFile(const char *filename); extern bool HasScenario(const ContentInfo *ci, bool md5sum); ClientNetworkContentSocketHandler _network_content_client; @@ -498,7 +497,8 @@ void ClientNetworkContentSocketHandler::AfterDownload() if (GunzipFile(this->curInfo)) { unlink(GetFullFilename(this->curInfo, true)); - TarListAddFile(GetFullFilename(this->curInfo, false)); + TarScanner ts; + ts.AddFile(GetFullFilename(this->curInfo, false), 0); if (this->curInfo->type == CONTENT_TYPE_BASE_MUSIC) { /* Music can't be in a tar. So extract the tar! */ |