fixed some smaller issues with loading custom artwork
authorHolger Schemel <info@artsoft.org>
Mon, 27 Oct 2014 23:15:18 +0000 (00:15 +0100)
committerHolger Schemel <info@artsoft.org>
Mon, 27 Oct 2014 23:15:18 +0000 (00:15 +0100)
ChangeLog
src/conftime.h
src/files.c
src/libgame/misc.c
src/libgame/setup.c
src/libgame/sound.c

index d98af9f94270166ee6da03a3481fde7c6367b08f..5a7a6ee7f1aaf961e7c36a9649461fb4398e9079 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2014-10-27
+       * fixed some smaller issues with loading custom artwork
+
 2014-10-22
        * added warnings when using undefined element and graphic names in
          custom artwork definitions (like ".crumbled_like" or ".clone_from")
index 75c7e4d548931dd0643d582ea0d8e2ecdce2013f..545fff3a04a28ebd1ae288bf50cc5a8713b32802 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2014-10-23 00:22"
+#define COMPILE_DATE_STRING "2014-10-27 21:31"
index 343c6d9431342da4593034f924acb22d858f06be..793151ca109bd972eabbfb996811111871b4854a 100644 (file)
@@ -9257,7 +9257,7 @@ void LoadMusicInfo()
     if (music_already_used)
       continue;
 
-    if (!FileIsMusic(basename))
+    if (!FileIsMusic(dir_entry->filename))
       continue;
 
     if (!music_info_listed(music_file_info, basename))
index eb2f8f0c54476a281939448b3a9bdfe5aba8e984..c123892d60343c061caa9b7741b5a35c909c28a2 100644 (file)
@@ -2209,7 +2209,9 @@ boolean directoryExists(char *dir_name)
   if (dir_name == NULL)
     return FALSE;
 
-  boolean success = (access(dir_name, F_OK) == 0);
+  struct stat file_status;
+  boolean success = (stat(dir_name, &file_status) == 0 &&
+                    (file_status.st_mode & S_IFMT) == S_IFDIR);
 
 #if defined(PLATFORM_ANDROID)
   if (!success)
@@ -2297,40 +2299,37 @@ boolean fileHasSuffix(char *basename, char *suffix)
   return FALSE;
 }
 
-static boolean FileCouldBeArtwork(char *basename)
+static boolean FileCouldBeArtwork(char *filename)
 {
+  char *basename = getBaseNamePtr(filename);
+
   return (!strEqual(basename, ".") &&
          !strEqual(basename, "..") &&
          !fileHasSuffix(basename, "txt") &&
-         !fileHasSuffix(basename, "conf"));
+         !fileHasSuffix(basename, "conf") &&
+         !directoryExists(filename));
 }
 
 boolean FileIsGraphic(char *filename)
 {
-  char *basename = getBaseNamePtr(filename);
-
-  return FileCouldBeArtwork(basename);
+  return FileCouldBeArtwork(filename);
 }
 
 boolean FileIsSound(char *filename)
 {
-  char *basename = getBaseNamePtr(filename);
-
-  return FileCouldBeArtwork(basename);
+  return FileCouldBeArtwork(filename);
 }
 
 boolean FileIsMusic(char *filename)
 {
-  char *basename = getBaseNamePtr(filename);
-
-  return FileCouldBeArtwork(basename);
+  return FileCouldBeArtwork(filename);
 }
 
-boolean FileIsArtworkType(char *basename, int type)
+boolean FileIsArtworkType(char *filename, int type)
 {
-  if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) ||
-      (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) ||
-      (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename)))
+  if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(filename)) ||
+      (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(filename)) ||
+      (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(filename)))
     return TRUE;
 
   return FALSE;
index e60c8424f5409b67334bc5894912ae4390877212..b07f2fdf40dd551793167c95d765b2401037a312 100644 (file)
@@ -3026,9 +3026,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
     {
       while ((dir_entry = readDirectory(dir)) != NULL)
       {
-       char *entry_name = dir_entry->basename;
-
-       if (FileIsArtworkType(entry_name, type))
+       if (FileIsArtworkType(dir_entry->filename, type))
        {
          valid_file_found = TRUE;
 
index 591ea7d444ce3ecbe416fe96cbcc2b39c5a03ef6..5ace5922af201154ff5f96f9f0385a868365072a 100644 (file)
@@ -598,7 +598,6 @@ void LoadCustomMusic_NoConf(void)
   while ((dir_entry = readDirectory(dir)) != NULL)     /* loop all entries */
   {
     char *basename = dir_entry->basename;
-    char *filename = NULL;
     MusicInfo *mus_info = NULL;
     boolean music_already_used = FALSE;
     int i;
@@ -621,12 +620,8 @@ void LoadCustomMusic_NoConf(void)
     if (draw_init_text)
       DrawInitText(basename, 150, FC_YELLOW);
 
-    filename = getPath2(music_directory, basename);
-
-    if (FileIsMusic(basename))
-      mus_info = Load_WAV_or_MOD(filename);
-
-    free(filename);
+    if (FileIsMusic(dir_entry->filename))
+      mus_info = Load_WAV_or_MOD(dir_entry->filename);
 
     if (mus_info)
     {