scan for tarfiles in CACHE_DIR, remember what Subdirectory a tar was found in, set the GCF_FLAG on GRFs loaded from there, and hide those in the NewGRF GUI
--- a/src/fileio.cpp Tue Jul 22 18:29:06 2008 +0300
+++ b/src/fileio.cpp Tue Jul 22 21:51:14 2008 +0300
@@ -483,7 +483,7 @@
#endif
}
-static bool TarListAddFile(const char *filename)
+static bool TarListAddFile(const char *filename, Subdirectory subdir)
{
/* The TAR-header, repeated for every file */
typedef struct TarHeader {
@@ -516,6 +516,7 @@
TarListEntry *tar_entry = MallocT<TarListEntry>(1);
tar_entry->filename = strdup(filename);
+ tar_entry->subdir = subdir;
_tar_list.insert(TarList::value_type(filename, tar_entry));
TarLinkList links; ///< Temporary list to collect links
@@ -694,7 +695,7 @@
return true;
}
-static int ScanPathForTarFiles(const char *path, size_t basepath_length)
+static int ScanPathForTarFiles(const char *path, size_t basepath_length, Subdirectory subdir)
{
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
@@ -717,7 +718,7 @@
/* Directory */
if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
AppendPathSeparator(filename, lengthof(filename));
- num += ScanPathForTarFiles(filename, basepath_length);
+ num += ScanPathForTarFiles(filename, basepath_length, subdir);
} else if (sb.st_mode & S_IFREG) {
/* File */
char *ext = strrchr(filename, '.');
@@ -726,7 +727,7 @@
if (ext == NULL) continue;
if (strcasecmp(ext, ".tar") != 0) continue;
- if (TarListAddFile(filename)) num++;
+ if (TarListAddFile(filename, subdir)) num++;
}
}
@@ -743,7 +744,10 @@
DEBUG(misc, 1, "Scanning for tars");
FOR_ALL_SEARCHPATHS(sp) {
FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR);
- num += ScanPathForTarFiles(path, strlen(path));
+ num += ScanPathForTarFiles(path, strlen(path), DATA_DIR);
+
+ FioAppendDirectory(path, MAX_PATH, sp, CACHE_DIR);
+ num += ScanPathForTarFiles(path, strlen(path), CACHE_DIR);
}
DEBUG(misc, 1, "Scan complete, found %d files", num);
}
--- a/src/newgrf_config.cpp Tue Jul 22 18:29:06 2008 +0300
+++ b/src/newgrf_config.cpp Tue Jul 22 21:51:14 2008 +0300
@@ -267,10 +267,14 @@
return res;
}
-static bool ScanPathAddGrf(const char *filename)
+static bool ScanPathAddGrf(const char *filename, Subdirectory subdir)
{
GRFConfig *c = CallocT<GRFConfig>(1);
c->filename = strdup(filename);
+
+ // flag GRFs that are loaded from cache
+ if (subdir == CACHE_DIR)
+ SetBit(c->flags, GCF_CACHE);
bool added = true;
if (FillGRFDetails(c, false)) {
@@ -314,7 +318,7 @@
}
/* Scan a path for NewGRFs */
-static uint ScanPath(const char *path, size_t basepath_length)
+static uint ScanPath(const char *path, size_t basepath_length, Subdirectory subdir)
{
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
@@ -337,7 +341,7 @@
/* Directory */
if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
AppendPathSeparator(filename, lengthof(filename));
- num += ScanPath(filename, basepath_length);
+ num += ScanPath(filename, basepath_length, subdir);
} else if (sb.st_mode & S_IFREG) {
/* File */
char *ext = strrchr(filename, '.');
@@ -346,7 +350,7 @@
if (ext == NULL) continue;
if (strcasecmp(ext, ".grf") != 0) continue;
- if (ScanPathAddGrf(filename + basepath_length)) num++;
+ if (ScanPathAddGrf(filename + basepath_length, subdir)) num++;
}
}
@@ -365,7 +369,7 @@
if (ext == NULL) return false;
if (strcasecmp(ext, ".grf") != 0) return false;
- if (ScanPathAddGrf(filename)) num++;
+ if (ScanPathAddGrf(filename, (*tar).second.tar->subdir)) num++;
return num;
}
@@ -398,7 +402,7 @@
DEBUG(grf, 1, "Scanning for NewGRFs");
FOR_ALL_SEARCHPATHS(sp) {
FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR);
- num += ScanPath(path, strlen(path));
+ num += ScanPath(path, strlen(path), DATA_DIR);
}
FOR_ALL_TARS(tar) {
num += ScanTar(tar);
--- a/src/newgrf_config.h Tue Jul 22 18:29:06 2008 +0300
+++ b/src/newgrf_config.h Tue Jul 22 21:51:14 2008 +0300
@@ -16,7 +16,7 @@
GCF_COPY, ///< The data is copied from a grf in _all_grfs
GCF_INIT_ONLY, ///< GRF file is processed up to GLS_INIT
GCF_RESERVED, ///< GRF file passed GLS_RESERVE stage
-
+ GCF_CACHE, ///< GRF file was loaded from cache
};
/** Status of GRF */
--- a/src/newgrf_gui.cpp Tue Jul 22 18:29:06 2008 +0300
+++ b/src/newgrf_gui.cpp Tue Jul 22 21:51:14 2008 +0300
@@ -152,7 +152,9 @@
int n = 0;
/* Count the number of GRFs */
- for (c = _all_grfs; c != NULL; c = c->next) n++;
+ for (c = _all_grfs; c != NULL; c = c->next)
+ if (!HasBit(c->flags, GCF_CACHE))
+ n++;
this->vscroll.cap = (wl->bottom - wl->top) / 10;
SetVScrollCount(this, n);
@@ -164,7 +166,7 @@
uint y = wl->top + 1;
for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) {
- if (n >= this->vscroll.pos) {
+ if (!HasBit(c->flags, GCF_CACHE) && n >= this->vscroll.pos) {
bool h = c == this->sel;
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
--- a/src/tar_type.h Tue Jul 22 18:29:06 2008 +0300
+++ b/src/tar_type.h Tue Jul 22 21:51:14 2008 +0300
@@ -11,6 +11,7 @@
/** The define of a TarList. */
struct TarListEntry {
const char *filename;
+ Subdirectory subdir;
};
struct TarFileListEntry {