-#define COMPILE_DATE_STRING "2013-12-12 17:46"
+#define COMPILE_DATE_STRING "2013-12-16 21:45"
#include "network.h"
-#define DEBUG_EVENTS 0
+#define DEBUG_EVENTS 1
static boolean cursor_inside_playfield = FALSE;
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;
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);
#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;
}
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
}
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);
if (IS_WHEEL_BUTTON(button_nr))
return;
+ Error(ERR_DEBUG, "::: game_status == %d", game_status);
+
switch (game_status)
{
case GAME_MODE_TITLE:
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)
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];
return basename;
}
+#endif
+
static char *getSingleLevelFilename(int nr)
{
return getLevelFilenameFromBasename(getSingleLevelBasename(nr));
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();
#endif
}
+#endif
+
void add_helpanim_entry(int element, int action, int direction, int delay,
int *num_list_entries)
{
/* 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);
{ 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" },
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;
/* 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)
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") ||
fileHasSuffix(basename, "mp3") ||
fileHasSuffix(basename, "ogg"))
return TRUE;
+#endif
#endif
return FALSE;
DirectoryEntry *readDirectory(Directory *);
void freeDirectoryEntry(DirectoryEntry *);
+boolean directoryExists(char *);
boolean fileExists(char *);
boolean FileIsGraphic(char *);
boolean FileIsSound(char *);
#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
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));
{
/* 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);
{
/* 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);
{
/* 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);
/* 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 */
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);
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)
{
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));
#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,
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)
base_directory);
}
+#endif
+
static TreeInfo *getDummyArtworkInfo(int type)
{
/* this is only needed when there is completely no artwork available */
#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 */
if ((dir = opendir(music_directory)) == NULL)
{
Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+
audio.music_available = FALSE;
+
return;
}
draw_init_text = FALSE;
}
+#endif
+
int getSoundListSize()
{
return (sound_info->num_file_list_entries +
break;
case KSYM_Escape:
+ case KSYM_Back:
result = 0;
break;