+int LoadMusic(void)
+{
+ DIR *dir;
+ struct dirent *dir_entry;
+ char *music_directory = getPath2(options.ro_base_directory, MUSIC_DIRECTORY);
+
+ num_music = 0;
+
+ if ((dir = opendir(music_directory)) == NULL)
+ {
+ Error(ERR_WARN, "cannot read music directory '%s'", music_directory);
+ audio.music_available = FALSE;
+ free(music_directory);
+ return 0;
+ }
+
+ while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */
+ {
+ char *filename = dir_entry->d_name;
+
+ if (strlen(filename) > 4 &&
+ strcmp(&filename[strlen(filename) - 4], ".wav") == 0)
+ {
+ if (!LoadSoundExt(filename, TRUE))
+ {
+ audio.music_available = FALSE;
+ free(music_directory);
+ return num_music;
+ }
+
+ num_music++;
+ }
+ else if (strlen(filename) > 4 &&
+ (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 ||
+ strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 ||
+ strncmp(filename, "mod.", 4) == 0 ||
+ strncmp(filename, "MOD.", 4) == 0))
+ {
+ if (!LoadMod(filename))
+ {
+ audio.music_available = FALSE;
+ free(music_directory);
+ return num_music;
+ }
+
+ num_music++;
+ }
+ }
+
+ closedir(dir);
+
+ if (num_music == 0)
+ Error(ERR_WARN, "cannot find any valid music files in directory '%s'",
+ music_directory);
+
+ free(music_directory);
+
+ if (num_mods > 0)
+ num_music = num_mods;
+
+ return num_music;
+}
+