Mercurial > hg > openttd
changeset 7572:6f7f69570938 draft
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
author | truelight <truelight@openttd.org> |
---|---|
date | Thu, 13 Sep 2007 18:28:56 +0000 |
parents | b20b488ca748 |
children | 85fa5b92adef |
files | src/newgrf_config.cpp |
diffstat | 1 files changed, 44 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -270,12 +270,54 @@ return res; } +static bool ScanPathAddGrf(const char *filename) +{ + GRFConfig *c = CallocT<GRFConfig>(1); + c->filename = strdup(filename); -extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); + bool added = true; + if (FillGRFDetails(c, false)) { + if (_all_grfs == NULL) { + _all_grfs = c; + } else { + /* Insert file into list at a position determined by its + * name, so the list is sorted as we go along */ + GRFConfig **pd, *d; + bool stop = false; + for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { + if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false; + /* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name, + * before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of + * just after the first with the same name. Avoids doubles in the list. */ + if (strcasecmp(c->name, d->name) <= 0) stop = true; + else if (stop) break; + } + if (added) { + c->next = d; + *pd = c; + } + } + } else { + added = false; + } + + if (!added) { + /* File couldn't be opened, or is either not a NewGRF or is a + * 'system' NewGRF or it's already known, so forget about it. */ + free(c->filename); + free(c->name); + free(c->info); + free(c); + } + + return added; +} /* Scan a path for NewGRFs */ static uint ScanPath(const char *path, int basepath_length) { + extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); + uint num = 0; struct stat sb; struct dirent *dirent; @@ -304,45 +346,7 @@ if (ext == NULL) continue; if (strcasecmp(ext, ".grf") != 0) continue; - GRFConfig *c = CallocT<GRFConfig>(1); - c->filename = strdup(filename + basepath_length); - - bool added = true; - if (FillGRFDetails(c, false)) { - if (_all_grfs == NULL) { - _all_grfs = c; - } else { - /* Insert file into list at a position determined by its - * name, so the list is sorted as we go along */ - GRFConfig **pd, *d; - bool stop = false; - for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { - if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false; - /* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name, - * before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of - * just after the first with the same name. Avoids doubles in the list. */ - if (strcasecmp(c->name, d->name) <= 0) stop = true; - else if (stop) break; - } - if (added) { - c->next = d; - *pd = c; - } - } - } else { - added = false; - } - - if (!added) { - /* File couldn't be opened, or is either not a NewGRF or is a - * 'system' NewGRF or it's already known, so forget about it. */ - free(c->filename); - free(c->name); - free(c->info); - free(c); - } else { - num++; - } + if (ScanPathAddGrf(filename + basepath_length)) num++; } }