Esempio n. 1
0
        private List<Music> GetMusic(string mapName)
        {
            List<Music> result = new List<Music>();

            string path = this.RootMusicFolder + "\\" + mapName;

            if (File.Exists(path + ".m3u")) // Check if a playlist exists for the map
            {
                Playlist playlist = new Playlist(path + ".m3u");
                result.AddRange(playlist.GetMusic());
            }

            if (Directory.Exists(path))
            {
                result.AddRange(this.GetMusicFromFolder(path));
            }

            if (this.SpecialFolders.Keys.Contains(mapName))
            {
                result.AddRange(this.GetMusicFromFolder(this.RootMusicFolder + "\\" + this.SpecialFolders[mapName]));
            }
            else if (result.Count == 0 && !string.IsNullOrEmpty(this.FallbackFolder))
            {
                result.AddRange(this.GetMusicFromFolder(this.RootMusicFolder + "\\" + this.FallbackFolder));
            }

            return result;
        }
Esempio n. 2
0
        private List<Music> GetMusicFromFolder(string folder)
        {
            List<Music> result = new List<Music>();
            if (Directory.Exists(folder)) // Else check if a folder of files exists for the map
            {
                string[] files = Directory.GetFiles(Path.GetFullPath(folder));
                foreach (string f in files)
                {
                    foreach (string format in SupportedFormats)
                    {
                        if (f.ToLower().EndsWith("." + format))
                        {
                            if (format == "m3u")
                            {
                                Playlist playlist = new Playlist(f);
                                result.AddRange(playlist.GetMusic());
                            }
                            else {
                                Music m = new Music(f);

                                // Remove file extension from name
                                if(m.Name.EndsWith("." + format))
                                {
                                    m.Name = m.Name.Substring(0, m.Name.Length - ("." + format).Length);
                                }

                                result.Add(m);
                            }

                            break;
                        }
                    }
                }
            }
            return result;
        }