rnd-20131216-1-src
authorHolger Schemel <info@artsoft.org>
Mon, 16 Dec 2013 21:19:53 +0000 (22:19 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 09:00:19 +0000 (11:00 +0200)
src/conftime.h
src/events.c
src/files.c
src/libgame/misc.c
src/libgame/misc.h
src/libgame/sdl.h
src/libgame/setup.c
src/libgame/sound.c
src/tools.c

index 7c5c7076f178706045a6c41acd0b12896636b60a..e6c5ef71cad658892eb12dfc21583f1d24b0a3c7 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2013-12-12 17:46"
+#define COMPILE_DATE_STRING "2013-12-16 21:45"
index d1880faee1297faa523d874dd3fda6c4b9ed28f4..d017a6343f9dc205540bd37ec277bbfb28a12542 100644 (file)
@@ -24,7 +24,7 @@
 #include "network.h"
 
 
-#define        DEBUG_EVENTS            0
+#define        DEBUG_EVENTS            1
 
 
 static boolean cursor_inside_playfield = FALSE;
@@ -358,8 +358,10 @@ void HandleExposeEvent(ExposeEvent *event)
 void HandleButtonEvent(ButtonEvent *event)
 {
 #if DEBUG_EVENTS
-  printf("::: BUTTON EVENT: button %d %s\n", event->button,
-        event->type == EVENT_BUTTONPRESS ? "pressed" : "released");
+  Error(ERR_DEBUG, "BUTTON EVENT: button %d %s, x/y %d/%d\n",
+       event->button,
+       event->type == EVENT_BUTTONPRESS ? "pressed" : "released",
+       event->x, event->y);
 #endif
 
   motion_status = FALSE;
@@ -382,25 +384,30 @@ void HandleMotionEvent(MotionEvent *event)
 
   motion_status = TRUE;
 
+  Error(ERR_DEBUG, "MOTION EVENT: button %d moved, x/y %d/%d\n",
+       button_status, event->x, event->y);
+
   HandleButton(event->x, event->y, button_status, button_status);
 }
 
 #if defined(TARGET_SDL2)
 void HandleFingerEvent(FingerEvent *event)
 {
+#if 0
   static int num_events = 0;
   int max_events = 10;
+#endif
 
-  // #if DEBUG_EVENTS
+#if DEBUG_EVENTS
   Error(ERR_DEBUG, "FINGER EVENT: finger was %s, touch ID %lld, finger ID %lld, x/y %f/%f, dx/dy %f/%f, pressure %f",
-       (event->type == EVENT_FINGERPRESS ? "pressed" :
-        event->type == EVENT_FINGERRELEASE ? "released" : "moved"),
+       event->type == EVENT_FINGERPRESS ? "pressed" :
+       event->type == EVENT_FINGERRELEASE ? "released" : "moved",
        event->touchId,
        event->fingerId,
        event->x, event->y,
        event->dx, event->dy,
        event->pressure);
-  // #endif
+#endif
 
   int x = (int)(event->x * video.width);
   int y = (int)(event->y * video.height);
@@ -414,7 +421,8 @@ void HandleFingerEvent(FingerEvent *event)
 #endif
 
 #if 1
-  if (event->type == EVENT_FINGERPRESS)
+  if (event->type == EVENT_FINGERPRESS ||
+      event->type == EVENT_FINGERMOTION)
     button_status = button;
   else
     button_status = MB_RELEASED;
@@ -439,7 +447,14 @@ void HandleFingerEvent(FingerEvent *event)
   }
   else
   {
+#if 1
+    Error(ERR_DEBUG, "::: button_status == %d, button == %d\n",
+         button_status, button);
+#endif
+
+#if 1
     HandleButton(x, y, button_status, button);
+#endif
   }
 #endif
 }
@@ -447,14 +462,31 @@ void HandleFingerEvent(FingerEvent *event)
 
 void HandleKeyEvent(KeyEvent *event)
 {
-  int key_status = (event->type==EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED);
+  int key_status = (event->type == EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED);
   boolean with_modifiers = (game_status == GAME_MODE_PLAYING ? FALSE : TRUE);
   Key key = GetEventKey(event, with_modifiers);
   Key keymod = (with_modifiers ? GetEventKey(event, FALSE) : key);
 
 #if DEBUG_EVENTS
-  printf("::: KEY EVENT: %d %s\n", GetEventKey(event, TRUE),
-        event->type == EVENT_KEYPRESS ? "pressed" : "released");
+  Error(ERR_DEBUG, "KEY EVENT: key was %s, keysym.scancode == %d, keysym.sym == %d, resulting key == %d (%s)",
+       event->type == EVENT_KEYPRESS ? "pressed" : "released",
+       event->keysym.scancode,
+       event->keysym.sym,
+       GetEventKey(event, TRUE),
+       getKeyNameFromKey(key));
+#endif
+
+#if 0
+  if (key == KSYM_Menu)
+    Error(ERR_DEBUG, "menu key pressed");
+  else if (key == KSYM_Back)
+    Error(ERR_DEBUG, "back key pressed");
+#endif
+
+#if defined(PLATFORM_ANDROID)
+  // always map the "back" button to the "escape" key on Android devices
+  if (key == KSYM_Back)
+    key = KSYM_Escape;
 #endif
 
   HandleKeyModState(keymod, key_status);
@@ -541,6 +573,8 @@ void HandleButton(int mx, int my, int button, int button_nr)
   if (IS_WHEEL_BUTTON(button_nr))
     return;
 
+  Error(ERR_DEBUG, "::: game_status == %d", game_status);
+
   switch (game_status)
   {
     case GAME_MODE_TITLE:
@@ -626,7 +660,7 @@ static void HandleKeysSpecial(Key key)
   cheat_input[cheat_input_len] = '\0';
 
 #if DEBUG_EVENTS
-  printf("::: '%s' [%d]\n", cheat_input, cheat_input_len);
+  Error(ERR_DEBUG, "SPECIAL KEY '%s' [%d]\n", cheat_input, cheat_input_len);
 #endif
 
   if (game_status == GAME_MODE_MAIN)
index 0f74fc00a00e31f9ed5843ce4be57b0e40ccfa71..7237f57722a570efe9f36d227846ae8b24400abf 100644 (file)
@@ -2090,6 +2090,48 @@ static char *getSingleLevelBasename(int nr)
   return getSingleLevelBasenameExt(nr, LEVELFILE_EXTENSION);
 }
 
+#if 1
+
+static char *getPackedLevelBasename(int type)
+{
+  static char basename[MAX_FILENAME_LEN];
+  char *directory = getCurrentLevelDir();
+  Directory *dir;
+  DirectoryEntry *dir_entry;
+
+  strcpy(basename, UNDEFINED_FILENAME);                /* default: undefined file */
+
+  if ((dir = openDirectory(directory)) == NULL)
+  {
+    Error(ERR_WARN, "cannot read current level directory '%s'", directory);
+
+    return basename;
+  }
+
+  while ((dir_entry = readDirectory(dir)) != NULL)     /* loop all entries */
+  {
+    char *entry_basename = dir_entry->basename;
+    int entry_type = getFileTypeFromBasename(entry_basename);
+
+    if (entry_type != LEVEL_FILE_TYPE_UNKNOWN) /* found valid level package */
+    {
+      if (type == LEVEL_FILE_TYPE_UNKNOWN ||
+         type == entry_type)
+      {
+       strcpy(basename, entry_basename);
+
+       break;
+      }
+    }
+  }
+
+  closeDirectory(dir);
+
+  return basename;
+}
+
+#else
+
 static char *getPackedLevelBasename(int type)
 {
   static char basename[MAX_FILENAME_LEN];
@@ -2128,6 +2170,8 @@ static char *getPackedLevelBasename(int type)
   return basename;
 }
 
+#endif
+
 static char *getSingleLevelFilename(int nr)
 {
   return getLevelFilenameFromBasename(getSingleLevelBasename(nr));
@@ -10547,6 +10591,160 @@ static boolean sound_info_listed(struct MusicFileInfo *list, char *basename)
   return music_info_listed_ext(list, basename, TRUE);
 }
 
+#if 1
+
+void LoadMusicInfo()
+{
+  char *music_directory = getCustomMusicDirectory();
+  int num_music = getMusicListSize();
+  int num_music_noconf = 0;
+  int num_sounds = getSoundListSize();
+  Directory *dir;
+  DirectoryEntry *dir_entry;
+  struct FileInfo *music, *sound;
+  struct MusicFileInfo *next, **new;
+  int i;
+
+  while (music_file_info != NULL)
+  {
+    next = music_file_info->next;
+
+    checked_free(music_file_info->basename);
+
+    checked_free(music_file_info->title_header);
+    checked_free(music_file_info->artist_header);
+    checked_free(music_file_info->album_header);
+    checked_free(music_file_info->year_header);
+
+    checked_free(music_file_info->title);
+    checked_free(music_file_info->artist);
+    checked_free(music_file_info->album);
+    checked_free(music_file_info->year);
+
+    free(music_file_info);
+
+    music_file_info = next;
+  }
+
+  new = &music_file_info;
+
+  for (i = 0; i < num_music; i++)
+  {
+    music = getMusicListEntry(i);
+
+    if (music->filename == NULL)
+      continue;
+
+    if (strEqual(music->filename, UNDEFINED_FILENAME))
+      continue;
+
+    /* a configured file may be not recognized as music */
+    if (!FileIsMusic(music->filename))
+      continue;
+
+#if 0
+    printf("::: -> '%s' (configured)\n", music->filename);
+#endif
+
+    if (!music_info_listed(music_file_info, music->filename))
+    {
+      *new = get_music_file_info(music->filename, i);
+#if 0
+      if (*new != NULL)
+       printf(":1: adding '%s' ['%s'] ...\n", (*new)->title, music->filename);
+#endif
+      if (*new != NULL)
+       new = &(*new)->next;
+    }
+  }
+
+  if ((dir = openDirectory(music_directory)) == NULL)
+  {
+    Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+    return;
+  }
+
+  while ((dir_entry = readDirectory(dir)) != NULL)     /* loop all entries */
+  {
+    char *basename = dir_entry->basename;
+    boolean music_already_used = FALSE;
+    int i;
+
+    /* skip all music files that are configured in music config file */
+    for (i = 0; i < num_music; i++)
+    {
+      music = getMusicListEntry(i);
+
+      if (music->filename == NULL)
+       continue;
+
+      if (strEqual(basename, music->filename))
+      {
+       music_already_used = TRUE;
+       break;
+      }
+    }
+
+    if (music_already_used)
+      continue;
+
+    if (!FileIsMusic(basename))
+      continue;
+
+#if 0
+    printf("::: -> '%s' (found in directory)\n", basename);
+#endif
+
+    if (!music_info_listed(music_file_info, basename))
+    {
+      *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf));
+#if 0
+      if (*new != NULL)
+       printf(":2: adding '%s' ['%s'] ...\n", (*new)->title, basename);
+#endif
+      if (*new != NULL)
+       new = &(*new)->next;
+    }
+
+    num_music_noconf++;
+  }
+
+  closeDirectory(dir);
+
+  for (i = 0; i < num_sounds; i++)
+  {
+    sound = getSoundListEntry(i);
+
+    if (sound->filename == NULL)
+      continue;
+
+    if (strEqual(sound->filename, UNDEFINED_FILENAME))
+      continue;
+
+    /* a configured file may be not recognized as sound */
+    if (!FileIsSound(sound->filename))
+      continue;
+
+#if 0
+    printf("::: -> '%s' (configured)\n", sound->filename);
+#endif
+
+    if (!sound_info_listed(music_file_info, sound->filename))
+    {
+      *new = get_sound_file_info(sound->filename, i);
+      if (*new != NULL)
+       new = &(*new)->next;
+    }
+  }
+
+#if 0
+  for (next = music_file_info; next != NULL; next = next->next)
+    printf("::: title == '%s'\n", next->title);
+#endif
+}
+
+#else
+
 void LoadMusicInfo()
 {
   char *music_directory = getCustomMusicDirectory();
@@ -10697,6 +10895,8 @@ void LoadMusicInfo()
 #endif
 }
 
+#endif
+
 void add_helpanim_entry(int element, int action, int direction, int delay,
                        int *num_list_entries)
 {
index 81ec00e7a1cc2245f1dd573d100a3c6e38296f48..eda87185ec74990bc6ac9efbee0b648a93d82436 100644 (file)
@@ -441,7 +441,7 @@ unsigned int get_random_number(int nr, int max)
 /* system info functions                                                     */
 /* ------------------------------------------------------------------------- */
 
-#if !defined(PLATFORM_MSDOS)
+#if !defined(PLATFORM_MSDOS) && !defined(PLATFORM_ANDROID)
 static char *get_corrected_real_name(char *real_name)
 {
   char *real_name_new = checked_malloc(MAX_USERNAME_LEN + 1);
@@ -1453,7 +1453,9 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode)
     { KSYM_End,                "XK_End",               "end" },
     { KSYM_Page_Up,    "XK_Page_Up",           "page up" },
     { KSYM_Page_Down,  "XK_Page_Down",         "page down" },
-    { KSYM_Menu,       "XK_Menu",              "menu" },        /* Win-Menu */
+
+    { KSYM_Menu,       "XK_Menu",              "menu" },        /* menu key */
+    { KSYM_Back,       "XK_Back",              "back" },        /* back key */
 
     /* ASCII 0x20 to 0x40 keys (except numbers) */
     { KSYM_space,      "XK_space",             "space" },
@@ -2090,7 +2092,7 @@ DirectoryEntry *readDirectory(Directory *dir)
     dir->dir_entry = checked_calloc(sizeof(DirectoryEntry));
 
     dir->dir_entry->is_directory = FALSE;
-    if (line[strlen(line) - 1] = '/')
+    if (line[strlen(line) - 1] == '/')
     {
       dir->dir_entry->is_directory = TRUE;
 
@@ -2144,23 +2146,53 @@ void freeDirectoryEntry(DirectoryEntry *dir_entry)
 /* functions for checking files and filenames                                */
 /* ------------------------------------------------------------------------- */
 
+boolean directoryExists(char *dir_name)
+{
+  if (dir_name == NULL)
+    return FALSE;
+
+  boolean success = (access(dir_name, F_OK) == 0);
+
+#if defined(PLATFORM_ANDROID)
+  if (!success)
+  {
+    // this might be an asset directory; check by trying to open toc file
+    char *asset_toc_filename = getPath2(dir_name, ASSET_TOC_BASENAME);
+    SDL_RWops *file = SDL_RWFromFile(asset_toc_filename, MODE_READ);
+
+    checked_free(asset_toc_filename);
+
+    success = (file != NULL);
+
+    if (success)
+      SDL_RWclose(file);
+  }
+#endif
+
+  return success;
+}
+
 boolean fileExists(char *filename)
 {
   if (filename == NULL)
     return FALSE;
 
+  boolean success = (access(filename, F_OK) == 0);
+
 #if defined(PLATFORM_ANDROID)
-  // workaround: check if file exists by opening and closing it
-  SDL_RWops *file = SDL_RWFromFile(filename, MODE_READ);
-  boolean success = (file != NULL);
+  if (!success)
+  {
+    // this might be an asset file; check by trying to open it
+    SDL_RWops *file = SDL_RWFromFile(filename, MODE_READ);
 
-  if (success)
-    SDL_RWclose(file);
+    success = (file != NULL);
 
-  return success;
-#else
-  return (access(filename, F_OK) == 0);
+    if (success)
+      SDL_RWclose(file);
+  }
 #endif
+
+  return success;
 }
 
 boolean fileHasPrefix(char *basename, char *prefix)
@@ -2209,36 +2241,40 @@ boolean fileHasSuffix(char *basename, char *suffix)
 
 boolean FileIsGraphic(char *filename)
 {
-#if 1
-  return TRUE;
-#else
   char *basename = getBaseNamePtr(filename);
 
+#if defined(TARGET_SDL)
+  return (!fileHasSuffix(basename, "txt") &&
+         !fileHasSuffix(basename, "conf"));
+#else
   return fileHasSuffix(basename, "pcx");
 #endif
 }
 
 boolean FileIsSound(char *filename)
 {
-#if 1
-  return TRUE;
-#else
   char *basename = getBaseNamePtr(filename);
 
+#if defined(TARGET_SDL)
+  return (!fileHasSuffix(basename, "txt") &&
+         !fileHasSuffix(basename, "conf"));
+#else
   return fileHasSuffix(basename, "wav");
 #endif
 }
 
 boolean FileIsMusic(char *filename)
 {
-#if 1
-  return TRUE;
-#else
   char *basename = getBaseNamePtr(filename);
 
+#if defined(TARGET_SDL)
+  return (!fileHasSuffix(basename, "txt") &&
+         !fileHasSuffix(basename, "conf"));
+#else
   if (FileIsSound(basename))
     return TRUE;
 
+#if 0
 #if defined(TARGET_SDL)
   if ((fileHasPrefix(basename, "mod") && !fileHasSuffix(basename, "txt")) ||
       fileHasSuffix(basename, "mod") ||
@@ -2250,6 +2286,7 @@ boolean FileIsMusic(char *filename)
       fileHasSuffix(basename, "mp3") ||
       fileHasSuffix(basename, "ogg"))
     return TRUE;
+#endif
 #endif
 
   return FALSE;
index 582a6255f9ee4d2ad67a445e87f3956442409253..244a3992d2e02b725dd6cc0be3d17db758c865ce 100644 (file)
@@ -241,6 +241,7 @@ int closeDirectory(Directory *);
 DirectoryEntry *readDirectory(Directory *);
 void freeDirectoryEntry(DirectoryEntry *);
 
+boolean directoryExists(char *);
 boolean fileExists(char *);
 boolean FileIsGraphic(char *);
 boolean FileIsSound(char *);
index 5cc375c8e134aa3ca48ea6a434b43cf9818a8213..b228c00934820a81e4d300270aae8cb0ca764574 100644 (file)
@@ -185,7 +185,9 @@ struct MouseCursorInfo
 #define KSYM_End               SDLK_END
 #define KSYM_Page_Up           SDLK_PAGEUP
 #define KSYM_Page_Down         SDLK_PAGEDOWN
+
 #define KSYM_Menu              SDLK_MENU
+#define KSYM_Back              SDLK_AC_BACK
 
 #define KSYM_space             SDLK_SPACE
 #define KSYM_exclam            SDLK_EXCLAIM
index 610660765a4c8eefe6d3e996a5b7182c3926bb62..2f573e764af6adcb351b9616585101fc76411083 100644 (file)
@@ -357,7 +357,7 @@ char *setLevelArtworkDir(TreeInfo *ti)
 
     checked_free(*artwork_set_ptr);
 
-    if (fileExists(dir))
+    if (directoryExists(dir))
     {
       *artwork_path_ptr = getStringCopy(getClassicArtworkDir(ti->type));
       *artwork_set_ptr = getStringCopy(getClassicArtworkSet(ti->type));
@@ -880,7 +880,7 @@ char *getCustomMusicDirectory(void)
   {
     /* 1st try: look for special artwork in current level series directory */
     directory = getPath2(getCurrentLevelDir(), MUSIC_DIRECTORY);
-    if (fileExists(directory))
+    if (directoryExists(directory))
       return directory;
 
     free(directory);
@@ -890,7 +890,7 @@ char *getCustomMusicDirectory(void)
     {
       /* 2nd try: look for special artwork configured in level series config */
       directory = getStringCopy(getLevelArtworkDir(TREE_TYPE_MUSIC_DIR));
-      if (fileExists(directory))
+      if (directoryExists(directory))
        return directory;
 
       free(directory);
@@ -904,7 +904,7 @@ char *getCustomMusicDirectory(void)
   {
     /* 3rd try: look for special artwork in configured artwork directory */
     directory = getStringCopy(getSetupArtworkDir(artwork.mus_current));
-    if (fileExists(directory))
+    if (directoryExists(directory))
       return directory;
 
     free(directory);
@@ -912,14 +912,14 @@ char *getCustomMusicDirectory(void)
 
   /* 4th try: look for default artwork in new default artwork directory */
   directory = getStringCopy(getDefaultMusicDir(MUS_DEFAULT_SUBDIR));
-  if (fileExists(directory))
+  if (directoryExists(directory))
     return directory;
 
   free(directory);
 
   /* 5th try: look for default artwork in old default artwork directory */
   directory = getStringCopy(options.music_directory);
-  if (fileExists(directory))
+  if (directoryExists(directory))
     return directory;
 
   return NULL;         /* cannot find specified artwork file anywhere */
@@ -943,7 +943,7 @@ static void SaveUserLevelInfo();
 
 void InitUserLevelDirectory(char *level_subdir)
 {
-  if (!fileExists(getUserLevelDir(level_subdir)))
+  if (!directoryExists(getUserLevelDir(level_subdir)))
   {
     createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE);
     createDirectory(getUserLevelDir(NULL), "main user level", PERMS_PRIVATE);
@@ -1389,7 +1389,7 @@ void updateUserGameDataDir()
   char *userdata_dir_new = getUserGameDataDir();       /* do not free() this */
 
   /* convert old Unix style game data directory to Mac OS X style, if needed */
-  if (fileExists(userdata_dir_old) && !fileExists(userdata_dir_new))
+  if (directoryExists(userdata_dir_old) && !directoryExists(userdata_dir_new))
   {
     if (rename(userdata_dir_old, userdata_dir_new) != 0)
     {
@@ -1456,7 +1456,7 @@ void createDirectory(char *dir, char *text, int permission_class)
   else
     dir_mode |= MODE_W_ALL;
 
-  if (!fileExists(dir))
+  if (!directoryExists(dir))
     if (posix_mkdir(dir, dir_mode) != 0)
       Error(ERR_WARN, "cannot create %s directory '%s': %s",
            text, dir, strerror(errno));
@@ -3634,6 +3634,154 @@ void LoadLevelInfo()
 #endif
 }
 
+#if 1
+
+static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
+                                             TreeInfo *node_parent,
+                                             char *base_directory,
+                                             char *directory_name, int type)
+{
+  char *directory_path = getPath2(base_directory, directory_name);
+  char *filename = getPath2(directory_path, ARTWORKINFO_FILENAME(type));
+  SetupFileHash *setup_file_hash = NULL;
+  TreeInfo *artwork_new = NULL;
+  int i;
+
+  if (fileExists(filename))
+    setup_file_hash = loadSetupFileHash(filename);
+
+  if (setup_file_hash == NULL) /* no config file -- look for artwork files */
+  {
+    Directory *dir;
+    DirectoryEntry *dir_entry;
+    boolean valid_file_found = FALSE;
+
+    if ((dir = openDirectory(directory_path)) != NULL)
+    {
+      while ((dir_entry = readDirectory(dir)) != NULL)
+      {
+       char *entry_name = dir_entry->basename;
+
+       if (FileIsArtworkType(entry_name, type))
+       {
+         valid_file_found = TRUE;
+
+         break;
+       }
+      }
+
+      closeDirectory(dir);
+    }
+
+    if (!valid_file_found)
+    {
+      if (!strEqual(directory_name, "."))
+       Error(ERR_WARN, "ignoring artwork directory '%s'", directory_path);
+
+      free(directory_path);
+      free(filename);
+
+      return FALSE;
+    }
+  }
+
+  artwork_new = newTreeInfo();
+
+  if (node_parent)
+    setTreeInfoToDefaultsFromParent(artwork_new, node_parent);
+  else
+    setTreeInfoToDefaults(artwork_new, type);
+
+  artwork_new->subdir = getStringCopy(directory_name);
+
+  if (setup_file_hash) /* (before defining ".color" and ".class_desc") */
+  {
+#if 0
+    checkSetupFileHashIdentifier(setup_file_hash, filename, getCookie("..."));
+#endif
+
+    /* set all structure fields according to the token/value pairs */
+    ldi = *artwork_new;
+    for (i = 0; i < NUM_LEVELINFO_TOKENS; i++)
+      setSetupInfo(levelinfo_tokens, i,
+                  getHashEntry(setup_file_hash, levelinfo_tokens[i].text));
+    *artwork_new = ldi;
+
+    if (strEqual(artwork_new->name, ANONYMOUS_NAME))
+      setString(&artwork_new->name, artwork_new->subdir);
+
+    if (artwork_new->identifier == NULL)
+      artwork_new->identifier = getStringCopy(artwork_new->subdir);
+
+    if (artwork_new->name_sorting == NULL)
+      artwork_new->name_sorting = getStringCopy(artwork_new->name);
+  }
+
+  if (node_parent == NULL)             /* top level group */
+  {
+    artwork_new->basepath = getStringCopy(base_directory);
+    artwork_new->fullpath = getStringCopy(artwork_new->subdir);
+  }
+  else                                 /* sub level group */
+  {
+    artwork_new->basepath = getStringCopy(node_parent->basepath);
+    artwork_new->fullpath = getPath2(node_parent->fullpath, directory_name);
+  }
+
+  artwork_new->in_user_dir =
+    (!strEqual(artwork_new->basepath, OPTIONS_ARTWORK_DIRECTORY(type)));
+
+  /* (may use ".sort_priority" from "setup_file_hash" above) */
+  artwork_new->color = ARTWORKCOLOR(artwork_new);
+
+  setString(&artwork_new->class_desc, getLevelClassDescription(artwork_new));
+
+  if (setup_file_hash == NULL) /* (after determining ".user_defined") */
+  {
+    if (strEqual(artwork_new->subdir, "."))
+    {
+      if (artwork_new->user_defined)
+      {
+       setString(&artwork_new->identifier, "private");
+       artwork_new->sort_priority = ARTWORKCLASS_PRIVATE;
+      }
+      else
+      {
+       setString(&artwork_new->identifier, "classic");
+       artwork_new->sort_priority = ARTWORKCLASS_CLASSICS;
+      }
+
+      /* set to new values after changing ".sort_priority" */
+      artwork_new->color = ARTWORKCOLOR(artwork_new);
+
+      setString(&artwork_new->class_desc,
+               getLevelClassDescription(artwork_new));
+    }
+    else
+    {
+      setString(&artwork_new->identifier, artwork_new->subdir);
+    }
+
+    setString(&artwork_new->name, artwork_new->identifier);
+    setString(&artwork_new->name_sorting, artwork_new->name);
+  }
+
+#if 0
+  DrawInitText(artwork_new->name, 150, FC_YELLOW);
+#endif
+
+  pushTreeInfo(node_first, artwork_new);
+
+  freeSetupFileHash(setup_file_hash);
+
+  free(directory_path);
+  free(filename);
+
+  return TRUE;
+}
+
+#else
+
 static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
                                              TreeInfo *node_parent,
                                              char *base_directory,
@@ -3777,6 +3925,82 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first,
   return TRUE;
 }
 
+#endif
+
+#if 1
+
+static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
+                                         TreeInfo *node_parent,
+                                         char *base_directory, int type)
+{
+  Directory *dir;
+  DirectoryEntry *dir_entry;
+  boolean valid_entry_found = FALSE;
+
+  if ((dir = openDirectory(base_directory)) == NULL)
+  {
+    /* display error if directory is main "options.graphics_directory" etc. */
+    if (base_directory == OPTIONS_ARTWORK_DIRECTORY(type))
+      Error(ERR_WARN, "cannot read directory '%s'", base_directory);
+
+    return;
+  }
+
+  while ((dir_entry = readDirectory(dir)) != NULL)     /* loop all entries */
+  {
+    char *directory_name = dir_entry->basename;
+    char *directory_path = getPath2(base_directory, directory_name);
+
+    /* skip directory entries for current and parent directory */
+    if (strEqual(directory_name, ".") ||
+       strEqual(directory_name, ".."))
+    {
+      free(directory_path);
+
+      continue;
+    }
+
+#if 1
+    /* skip directory entries which are not a directory */
+    if (!dir_entry->is_directory)                      /* not a directory */
+    {
+      free(directory_path);
+
+      continue;
+    }
+#else
+    /* skip directory entries which are not a directory or are not accessible */
+    struct stat file_status;
+    if (stat(directory_path, &file_status) != 0 ||     /* cannot stat file */
+       (file_status.st_mode & S_IFMT) != S_IFDIR)      /* not a directory */
+    {
+      free(directory_path);
+
+      continue;
+    }
+#endif
+
+    free(directory_path);
+
+    /* check if this directory contains artwork with or without config file */
+    valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first, node_parent,
+                                                       base_directory,
+                                                       directory_name, type);
+  }
+
+  closeDirectory(dir);
+
+  /* check if this directory directly contains artwork itself */
+  valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first, node_parent,
+                                                     base_directory, ".",
+                                                     type);
+  if (!valid_entry_found)
+    Error(ERR_WARN, "cannot find any valid artwork in directory '%s'",
+         base_directory);
+}
+
+#else
+
 static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
                                          TreeInfo *node_parent,
                                          char *base_directory, int type)
@@ -3835,6 +4059,8 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first,
          base_directory);
 }
 
+#endif
+
 static TreeInfo *getDummyArtworkInfo(int type)
 {
   /* this is only needed when there is completely no artwork available */
index 2712fa4c92970aefb7a98a5da4cd7071c5b4fad3..83abf606718bc956f52f7002e7f86b998e9d0720 100644 (file)
@@ -1790,6 +1790,91 @@ static void *Load_WAV_or_MOD(char *filename)
 #endif
 }
 
+#if 1
+
+void LoadCustomMusic_NoConf(void)
+{
+  static boolean draw_init_text = TRUE;                /* only draw at startup */
+  static char *last_music_directory = NULL;
+  char *music_directory = getCustomMusicDirectory();
+  Directory *dir;
+  DirectoryEntry *dir_entry;
+  int num_music = getMusicListSize();
+
+  if (!audio.sound_available)
+    return;
+
+  if (last_music_directory != NULL &&
+      strEqual(last_music_directory, music_directory))
+    return;    /* old and new music directory are the same */
+
+  if (last_music_directory != NULL)
+    free(last_music_directory);
+  last_music_directory = getStringCopy(music_directory);
+
+  FreeAllMusic_NoConf();
+
+  if ((dir = openDirectory(music_directory)) == NULL)
+  {
+    Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+
+    audio.music_available = FALSE;
+
+    return;
+  }
+
+  if (draw_init_text)
+    DrawInitText("Loading music", 120, FC_GREEN);
+
+  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;
+
+    /* skip all music files that are configured in music config file */
+    for (i = 0; i < num_music; i++)
+    {
+      struct FileInfo *music = getMusicListEntry(i);
+
+      if (strEqual(basename, music->filename))
+      {
+       music_already_used = TRUE;
+       break;
+      }
+    }
+
+    if (music_already_used)
+      continue;
+
+    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 (mus_info)
+    {
+      num_music_noconf++;
+      Music_NoConf = checked_realloc(Music_NoConf,
+                                    num_music_noconf * sizeof(MusicInfo *));
+      Music_NoConf[num_music_noconf - 1] = mus_info;
+    }
+  }
+
+  closeDirectory(dir);
+
+  draw_init_text = FALSE;
+}
+
+#else
+
 void LoadCustomMusic_NoConf(void)
 {
   static boolean draw_init_text = TRUE;                /* only draw at startup */
@@ -1815,7 +1900,9 @@ void LoadCustomMusic_NoConf(void)
   if ((dir = opendir(music_directory)) == NULL)
   {
     Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+
     audio.music_available = FALSE;
+
     return;
   }
 
@@ -1869,6 +1956,8 @@ void LoadCustomMusic_NoConf(void)
   draw_init_text = FALSE;
 }
 
+#endif
+
 int getSoundListSize()
 {
   return (sound_info->num_file_list_entries +
index 6c8e96be5a74d37404300725dd923892b04bf775..abde1cc7b311b5bb60b7f1562f79c55b181de9ab 100644 (file)
@@ -4172,6 +4172,7 @@ boolean Request(char *text, unsigned int req_state)
              break;
 
            case KSYM_Escape:
+           case KSYM_Back:
              result = 0;
              break;