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

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 13 years ago
parent 92244f1663
commit 414c397000

@ -378,7 +378,7 @@ struct AIFileChecksumCreator : FileScanner {
}
/* 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 @@ static bool IsSameAI(const ContentInfo *ci, bool md5sum, AIFileInfo *info)
/* 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

@ -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 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.

@ -148,7 +148,7 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
}
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 @@ template <class Tbase_set>
#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); \

@ -647,8 +647,11 @@ static void SimplifyFileName(char *name)
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 @@ static uint ScanPath(FileScanner *fs, const char *extension, const char *path, s
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 @@ static uint ScanTar(FileScanner *fs, const char *extension, TarFileList::iterato
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;
}

@ -82,15 +82,16 @@ public:
* @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();

@ -232,7 +232,7 @@ public:
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
* @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 @@ public:
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;

@ -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. */
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);

@ -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);

@ -30,11 +30,17 @@ public:
*/
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 */

Loading…
Cancel
Save