Пример #1
0
        private static CPlaylistFile _ConvertUSDXPlaylist(string file)
        {
            var pl = new CPlaylistFile();
            ReadOnlyCollection <CSong> allSongs = CSongs.AllSongs;

            if (!File.Exists(file))
            {
                return(null);
            }
            try
            {
                StreamReader sr;
                using (sr = new StreamReader(file, Encoding.Default, true))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        int pos = line.IndexOf(":", StringComparison.Ordinal);
                        if (pos <= 0)
                        {
                            continue;
                        }
                        if (line[0] == '#')
                        {
                            //Name or comment
                            string identifier = line.Substring(1, pos - 1).Trim();
                            string value      = line.Substring(pos + 1, line.Length - pos - 1).Trim();
                            if (identifier.ToUpper() == "NAME")
                            {
                                pl.Name = value;
                            }
                        }
                        else
                        {
                            //Song
                            string artist = line.Substring(0, pos - 1).Trim();
                            string title  = line.Substring(pos + 1, line.Length - pos - 1).Trim();
                            CSong  plSong = allSongs.FirstOrDefault(song => song.Artist == artist && song.Title == title);
                            if (plSong != null)
                            {
                                pl.AddSong(plSong.ID);
                            }
                            else
                            {
                                CLog.Error("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + file);
                            }
                        }
                    }
                }
                File.Delete(file);
            }
            catch
            {
                return(null);
            }

            return(pl);
        }
Пример #2
0
        public static void AddSong(int playlistID, int songID, EGameMode gameMode)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.AddSong(songID, gameMode);
            }
        }