summaryrefslogtreecommitdiff
path: root/src/gfxinit.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-06-02 12:56:38 +0000
committerrubidium <rubidium@openttd.org>2009-06-02 12:56:38 +0000
commitbe04b7e29c57290c44f2712c27e83296b7bdc163 (patch)
tree98d84f50ba79978d4a60a75f5a0502221535f91d /src/gfxinit.cpp
parent4ea3e511bd71559ab475f49292c8b50f1eace647 (diff)
downloadopenttd-be04b7e29c57290c44f2712c27e83296b7bdc163.tar.xz
(svn r16503) -Fix: base graphics names must be unique, so don't add duplicates (even if the versions differ).
Diffstat (limited to 'src/gfxinit.cpp')
-rw-r--r--src/gfxinit.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp
index 0554eee9b..9ef205895 100644
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -444,7 +444,7 @@ public:
bool OBGFileScanner::AddFile(const char *filename, size_t basepath_length)
{
bool ret = false;
- DEBUG(grf, 1, "Found %s as base graphics set", filename);
+ DEBUG(grf, 1, "Checking %s for base graphics set", filename);
GraphicsSet *graphics = new GraphicsSet();;
IniFile *ini = new IniFile();
@@ -459,12 +459,28 @@ bool OBGFileScanner::AddFile(const char *filename, size_t basepath_length)
}
if (FillGraphicsSetDetails(graphics, ini, path)) {
- bool duplicate = false;
- for (const GraphicsSet *c = _available_graphics_sets; !duplicate && c != NULL; c = c->next) {
- duplicate = (strcmp(c->name, graphics->name) == 0 || c->shortname == graphics->shortname) && c->version == graphics->version;
+ const GraphicsSet *duplicate = NULL;
+ for (const GraphicsSet *c = _available_graphics_sets; c != NULL; c = c->next) {
+ if (strcmp(c->name, graphics->name) == 0 || c->shortname == graphics->shortname) {
+ duplicate = c;
+ break;
+ }
}
- if (duplicate) {
- delete graphics;
+ if (duplicate != NULL) {
+ if (duplicate->version >= graphics->version) {
+ DEBUG(grf, 1, "Not adding %s (%i) as base graphics set (duplicate)", graphics->name, graphics->version);
+ delete graphics;
+ } else {
+ GraphicsSet **prev = &_available_graphics_sets;
+ while (*prev != duplicate) prev = &(*prev)->next;
+
+ *prev = graphics;
+ graphics->next = duplicate->next;
+
+ DEBUG(grf, 1, "Removing %s (%i) as base graphics set (duplicate)", duplicate->name, duplicate->version);
+ delete duplicate;
+ ret = true;
+ }
} else {
GraphicsSet **last = &_available_graphics_sets;
while (*last != NULL) last = &(*last)->next;
@@ -472,6 +488,9 @@ bool OBGFileScanner::AddFile(const char *filename, size_t basepath_length)
*last = graphics;
ret = true;
}
+ if (ret) {
+ DEBUG(grf, 1, "Adding %s (%i) as base graphics set", graphics->name, graphics->version);
+ }
} else {
delete graphics;
}