From: Holger Schemel Date: Mon, 16 Dec 2013 21:19:53 +0000 (+0100) Subject: rnd-20131216-1-src X-Git-Tag: 4.0.0.0-rc1~426 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7ecf99096c7c23909ada034e05d971464f66552f;p=rocksndiamonds.git rnd-20131216-1-src --- diff --git a/src/conftime.h b/src/conftime.h index 7c5c7076..e6c5ef71 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2013-12-12 17:46" +#define COMPILE_DATE_STRING "2013-12-16 21:45" diff --git a/src/events.c b/src/events.c index d1880fae..d017a634 100644 --- a/src/events.c +++ b/src/events.c @@ -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) diff --git a/src/files.c b/src/files.c index 0f74fc00..7237f577 100644 --- a/src/files.c +++ b/src/files.c @@ -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) { diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 81ec00e7..eda87185 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -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; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 582a6255..244a3992 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -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 *); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 5cc375c8..b228c009 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -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 diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 61066076..2f573e76 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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 */ diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 2712fa4c..83abf606 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -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 + diff --git a/src/tools.c b/src/tools.c index 6c8e96be..abde1cc7 100644 --- a/src/tools.c +++ b/src/tools.c @@ -4172,6 +4172,7 @@ boolean Request(char *text, unsigned int req_state) break; case KSYM_Escape: + case KSYM_Back: result = 0; break;