summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/ai_scanner.cpp4
-rw-r--r--src/base_media_base.h2
-rw-r--r--src/base_media_func.h4
-rw-r--r--src/fileio.cpp9
-rw-r--r--src/fileio_func.h5
-rw-r--r--src/fios.cpp6
-rw-r--r--src/newgrf_config.cpp4
-rw-r--r--src/script/script_scanner.cpp2
-rw-r--r--src/script/script_scanner.hpp8
9 files changed, 27 insertions, 17 deletions
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index aa4e5190a..100147f5a 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -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
diff --git a/src/base_media_base.h b/src/base_media_base.h
index f83d644ca..2a990ad0d 100644
--- a/src/base_media_base.h
+++ b/src/base_media_base.h
@@ -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.
diff --git a/src/base_media_func.h b/src/base_media_func.h
index c9f4e21bb..8834c6d4f 100644
--- a/src/base_media_func.h
+++ b/src/base_media_func.h
@@ -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); \
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 86714d108..dbf0bc01b 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -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;
}
diff --git a/src/fileio_func.h b/src/fileio_func.h
index 30aa997ae..42132aba8 100644
--- a/src/fileio_func.h
+++ b/src/fileio_func.h
@@ -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();
diff --git a/src/fios.cpp b/src/fios.cpp
index 627fdf291..731a12ecd 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -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;
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 6683f7b4f..932e7227e 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -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);
diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp
index 72f1c3b2a..75f4ba074 100644
--- 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);
diff --git a/src/script/script_scanner.hpp b/src/script/script_scanner.hpp
index 2fba6ef5a..f50d05747 100644
--- a/src/script/script_scanner.hpp
+++ b/src/script/script_scanner.hpp
@@ -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 */