1
0
Fork 0

(svn r22904) -Codechange: add tar filename to file scanning

release/1.2
rubidium 2011-09-08 09:48:52 +00:00
parent 92244f1663
commit 414c397000
9 changed files with 27 additions and 17 deletions

View File

@ -378,7 +378,7 @@ struct AIFileChecksumCreator : FileScanner {
} }
/* Add the file and calculate the md5 sum. */ /* 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; Md5 checksum;
uint8 buffer[1024]; uint8 buffer[1024];
@ -446,7 +446,7 @@ static bool IsSameAI(const ContentInfo *ci, bool md5sum, AIFileInfo *info)
/* Create the full path name, */ /* Create the full path name, */
seprintf(path, lastof(path), "%s%c%s", tar->second.tar_filename, PATHSEPCHAR, tar->first.c_str()); 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 { } else {
/* Add the path sep char back when searching a directory, so we are /* Add the path sep char back when searching a directory, so we are

View File

@ -142,7 +142,7 @@ protected:
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 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 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. * Get the extension that is used to identify this set.

View File

@ -148,7 +148,7 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
} }
template <class Tbase_set> 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; bool ret = false;
DEBUG(grf, 1, "Checking %s for base " SET_TYPE " set", filename); DEBUG(grf, 1, "Checking %s for base " SET_TYPE " set", filename);
@ -382,7 +382,7 @@ template <class Tbase_set>
#define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \ #define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \
template const char *repl_type::ini_set; \ template const char *repl_type::ini_set; \
template const char *repl_type::GetExtension(); \ 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::HasSet(const struct ContentInfo *ci, bool md5sum); \
template bool repl_type::SetSet(const char *name); \ template bool repl_type::SetSet(const char *name); \
template char *repl_type::GetSetsList(char *p, const char *last); \ template char *repl_type::GetSetsList(char *p, const char *last); \

View File

@ -647,8 +647,11 @@ static void SimplifyFileName(char *name)
return num; 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 */ /* The TAR-header, repeated for every file */
typedef struct TarHeader { typedef struct TarHeader {
char name[100]; ///< Name of the file char name[100]; ///< Name of the file
@ -1281,7 +1284,7 @@ static uint ScanPath(FileScanner *fs, const char *extension, const char *path, s
num += ScanPath(fs, extension, filename, basepath_length, recursive); num += ScanPath(fs, extension, filename, basepath_length, recursive);
} else if (S_ISREG(sb.st_mode)) { } else if (S_ISREG(sb.st_mode)) {
/* File */ /* 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 @@ static uint ScanTar(FileScanner *fs, const char *extension, TarFileList::iterato
uint num = 0; uint num = 0;
const char *filename = (*tar).first.c_str(); 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; return num;
} }

View File

@ -82,15 +82,16 @@ public:
* @param filename the full path to the file to read * @param filename the full path to the file to read
* @param basepath_length amount of characters to chop of before to get a * @param basepath_length amount of characters to chop of before to get a
* filename relative to the search path. * 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. * @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 */ /** Helper for scanning for files with tar as extension */
class TarScanner : FileScanner { class TarScanner : FileScanner {
public: 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. */ /** Do the scan for Tars. */
static uint DoScan(); static uint DoScan();

View File

@ -232,7 +232,7 @@ public:
callback_proc(callback_proc) 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 @@ public:
* @param basepath_length amount of characters to chop of before to get a relative filename * @param basepath_length amount of characters to chop of before to get a relative filename
* @return true if the file is added. * @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, '.'); const char *ext = strrchr(filename, '.');
if (ext == NULL) return false; if (ext == NULL) return false;
@ -597,7 +597,7 @@ public:
this->scanned = true; 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); FILE *f = FioFOpenFile(filename, "r", SCENARIO_DIR);
if (f == NULL) return false; if (f == NULL) return false;

View File

@ -539,7 +539,7 @@ 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);
/** Do the scan for GRFs. */ /** Do the scan for GRFs. */
static uint DoScan() static uint DoScan()
@ -553,7 +553,7 @@ public:
} }
}; };
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); GRFConfig *c = new GRFConfig(filename + basepath_length);

View File

@ -17,7 +17,7 @@
#include "../script/squirrel.hpp" #include "../script/squirrel.hpp"
#include "script_scanner.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); free(this->main_script);
this->main_script = strdup(filename); this->main_script = strdup(filename);

View File

@ -30,11 +30,17 @@ public:
*/ */
const char *GetMainScript() { return this->main_script; } 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: protected:
class Squirrel *engine; ///< The engine we're scanning with. class Squirrel *engine; ///< The engine we're scanning with.
char *main_script; ///< The name of the current main script. 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 */ #endif /* SCRIPT_SCANNER_HPP */