fixed invalidating artwork info cache for non-existing artwork config file
[rocksndiamonds.git] / src / libgame / setup.c
index 2372886f92d3b02af60f605f6dc93a7c6c4b46b7..e1840b1d375e92491492ed31752ecaaf59c07b48 100644 (file)
@@ -96,6 +96,7 @@ static SetupFileHash *artworkinfo_cache_old = NULL;
 static SetupFileHash *artworkinfo_cache_new = NULL;
 static SetupFileHash *optional_tokens_hash = NULL;
 static boolean use_artworkinfo_cache = TRUE;
+static boolean update_artworkinfo_cache = FALSE;
 
 
 // ----------------------------------------------------------------------------
@@ -2882,7 +2883,7 @@ static TreeInfo *createParentTreeInfoNode(TreeInfo *node_parent)
   ti_new->parent_link = TRUE;
 
   setString(&ti_new->identifier, node_parent->identifier);
-  setString(&ti_new->name, ".. (parent directory)");
+  setString(&ti_new->name, BACKLINK_TEXT_PARENT);
   setString(&ti_new->name_sorting, ti_new->name);
 
   setString(&ti_new->subdir, STRING_PARENT_DIRECTORY);
@@ -2904,14 +2905,15 @@ static TreeInfo *createTopTreeInfoNode(TreeInfo *node_first)
     return NULL;
 
   TreeInfo *ti_new = newTreeInfo();
+  int type = node_first->type;
 
-  setTreeInfoToDefaults(ti_new, TREE_TYPE_LEVEL_DIR);
+  setTreeInfoToDefaults(ti_new, type);
 
   ti_new->node_parent = NULL;
   ti_new->parent_link = FALSE;
 
   setString(&ti_new->identifier, node_first->identifier);
-  setString(&ti_new->name, INFOTEXT_LEVEL_DIR);
+  setString(&ti_new->name, TREE_INFOTEXT(type));
   setString(&ti_new->name_sorting, ti_new->name);
 
   setString(&ti_new->subdir, STRING_TOP_DIRECTORY);
@@ -2920,19 +2922,32 @@ static TreeInfo *createTopTreeInfoNode(TreeInfo *node_first)
   ti_new->sort_priority = node_first->sort_priority;;
   ti_new->latest_engine = node_first->latest_engine;
 
-  setString(&ti_new->class_desc, INFOTEXT_LEVEL_DIR);
+  setString(&ti_new->class_desc, TREE_INFOTEXT(type));
 
   ti_new->node_group = node_first;
   ti_new->level_group = TRUE;
 
   TreeInfo *ti_new2 = createParentTreeInfoNode(ti_new);
 
-  setString(&ti_new2->name, ".. (main menu)");
+  setString(&ti_new2->name, TREE_BACKLINK_TEXT(type));
   setString(&ti_new2->name_sorting, ti_new2->name);
 
   return ti_new;
 }
 
+static void setTreeInfoParentNodes(TreeInfo *node, TreeInfo *node_parent)
+{
+  while (node)
+  {
+    if (node->node_group)
+      setTreeInfoParentNodes(node->node_group, node);
+
+    node->node_parent = node_parent;
+
+    node = node->next;
+  }
+}
+
 
 // ----------------------------------------------------------------------------
 // functions for handling level and custom artwork info cache
@@ -2958,10 +2973,15 @@ static void LoadArtworkInfoCache(void)
 
   if (artworkinfo_cache_new == NULL)
     artworkinfo_cache_new = newSetupFileHash();
+
+  update_artworkinfo_cache = FALSE;
 }
 
 static void SaveArtworkInfoCache(void)
 {
+  if (!update_artworkinfo_cache)
+    return;
+
   char *filename = getPath2(getCacheDir(), ARTWORKINFO_CACHE_FILE);
 
   InitCacheDirectory();
@@ -3006,6 +3026,9 @@ static boolean modifiedFileTimestamp(char *filename, char *timestamp_string)
   if (timestamp_string == NULL)
     return TRUE;
 
+  if (!fileExists(filename))                   // file does not exist
+    return (atoi(timestamp_string) != 0);
+
   if (stat(filename, &file_status) != 0)       // cannot stat file
     return TRUE;
 
@@ -3986,6 +4009,8 @@ static void LoadArtworkInfoFromLevelInfoExt(ArtworkDirTree **artwork_node,
 
          artwork_new->sort_priority = level_node->sort_priority;
          artwork_new->color = LEVELCOLOR(artwork_new);
+
+         update_artworkinfo_cache = TRUE;
        }
 
        free(path);
@@ -4047,10 +4072,18 @@ static void LoadArtworkInfoFromLevelInfoExt(ArtworkDirTree **artwork_node,
 
 static void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node)
 {
+  // move peviously loaded artwork tree into separate sub-tree
   MoveArtworkInfoIntoSubTree(artwork_node);
 
+  // load artwork from level sets into separate sub-trees
   LoadArtworkInfoFromLevelInfoExt(artwork_node, NULL, leveldir_first_all, TRUE);
   LoadArtworkInfoFromLevelInfoExt(artwork_node, NULL, leveldir_first_all, FALSE);
+
+  // add top tree node over all three separate sub-trees
+  *artwork_node = createTopTreeInfoNode(*artwork_node);
+
+  // set all parent links (back links) in complete artwork tree
+  setTreeInfoParentNodes(*artwork_node, NULL);
 }
 
 void LoadLevelArtworkInfo(void)