Mercurial > hg > openttd
changeset 18083:7de5da015146 draft
(svn r22904) -Codechange: add tar filename to file scanning
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 08 Sep 2011 09:48:52 +0000 |
parents | 3a3875cd2f37 |
children | 475be2c93383 |
files | src/ai/ai_scanner.cpp src/base_media_base.h src/base_media_func.h src/fileio.cpp src/fileio_func.h src/fios.cpp src/newgrf_config.cpp src/script/script_scanner.cpp src/script/script_scanner.hpp |
diffstat | 9 files changed, 27 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -378,7 +378,7 @@ } /* Add the file and calculate the md5 sum. */ - virtual bool AddFile(const char *filename, size_t basepath_length) + virtual bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { Md5 checksum; uint8 buffer[1024]; @@ -446,7 +446,7 @@ /* Create the full path name, */ seprintf(path, lastof(path), "%s%c%s", tar->second.tar_filename, PATHSEPCHAR, tar->first.c_str()); - checksum.AddFile(path, 0); + checksum.AddFile(path, 0, NULL); } } else { /* Add the path sep char back when searching a directory, so we are
--- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -142,7 +142,7 @@ static Tbase_set *duplicate_sets; ///< All sets that aren't available, but needed for not downloading base sets when a newer version than the one on BaNaNaS is loaded. static const Tbase_set *used_set; ///< The currently used set - /* virtual */ bool AddFile(const char *filename, size_t basepath_length); + /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename); /** * Get the extension that is used to identify this set.
--- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -148,7 +148,7 @@ } template <class Tbase_set> -bool BaseMedia<Tbase_set>::AddFile(const char *filename, size_t basepath_length) +bool BaseMedia<Tbase_set>::AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { bool ret = false; DEBUG(grf, 1, "Checking %s for base " SET_TYPE " set", filename); @@ -382,7 +382,7 @@ #define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \ template const char *repl_type::ini_set; \ template const char *repl_type::GetExtension(); \ - template bool repl_type::AddFile(const char *filename, size_t pathlength); \ + template bool repl_type::AddFile(const char *filename, size_t pathlength, const char *tar_filename); \ template bool repl_type::HasSet(const struct ContentInfo *ci, bool md5sum); \ template bool repl_type::SetSet(const char *name); \ template char *repl_type::GetSetsList(char *p, const char *last); \
--- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -647,8 +647,11 @@ return num; } -bool TarScanner::AddFile(const char *filename, size_t basepath_length) +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 @@ -1281,7 +1284,7 @@ num += ScanPath(fs, extension, filename, basepath_length, recursive); } else if (S_ISREG(sb.st_mode)) { /* File */ - if (MatchesExtension(extension, filename) && fs->AddFile(filename, basepath_length)) num++; + if (MatchesExtension(extension, filename) && fs->AddFile(filename, basepath_length, NULL)) num++; } } @@ -1301,7 +1304,7 @@ uint num = 0; const char *filename = (*tar).first.c_str(); - if (MatchesExtension(extension, filename) && fs->AddFile(filename, 0)) num++; + if (MatchesExtension(extension, filename) && fs->AddFile(filename, 0, (*tar).second.tar_filename)) num++; return num; }
--- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -82,15 +82,16 @@ * @param filename the full path to the file to read * @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) = 0; + 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 { public: - /* virtual */ bool AddFile(const char *filename, size_t basepath_length); + /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL); /** Do the scan for Tars. */ static uint DoScan();
--- a/src/fios.cpp +++ b/src/fios.cpp @@ -232,7 +232,7 @@ callback_proc(callback_proc) {} - /* virtual */ bool AddFile(const char *filename, size_t basepath_length); + /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename); }; /** @@ -241,7 +241,7 @@ * @param basepath_length amount of characters to chop of before to get a relative filename * @return true if the file is added. */ -bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length) +bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { const char *ext = strrchr(filename, '.'); if (ext == NULL) return false; @@ -597,7 +597,7 @@ this->scanned = true; } - /* virtual */ bool AddFile(const char *filename, size_t basepath_length) + /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { FILE *f = FioFOpenFile(filename, "r", SCENARIO_DIR); if (f == NULL) return false;
--- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -539,7 +539,7 @@ { } - /* virtual */ bool AddFile(const char *filename, size_t basepath_length); + /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename); /** Do the scan for GRFs. */ static uint DoScan() @@ -553,7 +553,7 @@ } }; -bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length) +bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { GRFConfig *c = new GRFConfig(filename + basepath_length);
--- a/src/script/script_scanner.cpp +++ b/src/script/script_scanner.cpp @@ -17,7 +17,7 @@ #include "../script/squirrel.hpp" #include "script_scanner.hpp" -bool ScriptScanner::AddFile(const char *filename, size_t basepath_length) +bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { free(this->main_script); this->main_script = strdup(filename);
--- a/src/script/script_scanner.hpp +++ b/src/script/script_scanner.hpp @@ -30,11 +30,17 @@ */ const char *GetMainScript() { return this->main_script; } - /* virtual */ bool AddFile(const char *filename, size_t basepath_length); + /** + * Get the current tar file the ScanDir is currently tracking. + */ + const char *GetTarFile() { return this->tar_file; } + + /* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename); protected: class Squirrel *engine; ///< The engine we're scanning with. char *main_script; ///< The name of the current main script. + char *tar_file; ///< The filename of the tar for the main script. }; #endif /* SCRIPT_SCANNER_HPP */