Example #1
0
        public static int NewPlaylist()
        {
            CPlaylistFile pl = new CPlaylistFile();

            pl.PlaylistName = "New Playlist";
            _Playlists.Add(pl);
            return(_Playlists.Count - 1);
        }
Example #2
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);
        }
Example #3
0
        public static int NewPlaylist(string name = "New Playlist")
        {
            CPlaylistFile pl = new CPlaylistFile {
                Name = name
            };

            _Playlists.Add(pl);
            return(pl.Id);
        }
Example #4
0
        public static void MoveSong(int playlistID, int sourceIndex, int destIndex)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.MoveSong(sourceIndex, destIndex);
            }
        }
Example #5
0
        public static void DeleteSong(int playlistID, int songIndex)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.DeleteSong(songIndex);
            }
        }
Example #6
0
        public static void InsertSong(int playlistID, int positionIndex, int songID, EGameMode gameMode)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.InsertSong(positionIndex, songID, gameMode);
            }
        }
Example #7
0
        public static void Save(int playlistID)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.Save();
            }
        }
Example #8
0
        public static void SetName(int playlistID, string name)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.Name = name;
            }
        }
Example #9
0
 private static SPlaylistSongInfo[] _GetPlaylistSongInfos(CPlaylistFile playlist)
 {
     SPlaylistSongInfo[] result = new SPlaylistSongInfo[playlist.Songs.Count];
     for (int i = 0; i < playlist.Songs.Count; i++)
     {
         result[i] = _GetPlaylistSongInfo(playlist.Songs[i], playlist.Id, i);
     }
     return(result);
 }
Example #10
0
        public static void MoveSongUp(int playlistID, int songIndex)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.MoveSongUp(songIndex);
            }
        }
Example #11
0
        public static void AddSong(int playlistID, int songID, EGameMode gameMode)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl != null)
            {
                pl.AddSong(songID, gameMode);
            }
        }
Example #12
0
 private static SPlaylistData _GetPlaylistInfo(CPlaylistFile playlist)
 {
     return(new SPlaylistData
     {
         PlaylistId = playlist.Id,
         PlaylistName = playlist.Name,
         SongCount = playlist.Songs.Count,
         LastChanged = DateTime.Now.ToLongDateString()
     });
 }
Example #13
0
        public static bool PlaylistContainsSong(int songId, int playlistId)
        {
            CPlaylistFile pl = CPlaylists.Get(playlistId);

            if (pl == null)
            {
                throw new ArgumentException("invalid playlistId");
            }
            return(pl.Songs.Any(s => s.SongID == songId));
        }
Example #14
0
        public static CPlaylistSong GetSong(int playlistID, int songIndex)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl == null || songIndex >= pl.Songs.Count)
            {
                return(null);
            }

            return(pl.Songs[songIndex]);
        }
Example #15
0
        public static SPlaylistSongInfo[] GetPlaylistSongs(int playlistId)
        {
            CPlaylistFile pl = CPlaylists.Get(playlistId);

            if (pl == null)
            {
                throw new ArgumentException("invalid playlistId");
            }

            return(_GetPlaylistSongInfos(pl));
        }
Example #16
0
        private static void _ConvertUSDXPlaylists()
        {
            var files = new List <string>();

            files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.DataFolder, CConfig.FolderPlaylists), "*.upl", true, true));

            foreach (string file in files)
            {
                CPlaylistFile playlist = _ConvertUSDXPlaylist(file);
                playlist.Save();
                _Playlists.Add(playlist);
            }
        }
Example #17
0
        public static void LoadPlaylists()
        {
            _Playlists = new List <CPlaylistFile>();
            List <string> files = new List <string>();

            files.AddRange(Helper.ListFiles(CSettings.sFolderPlaylists, "*.xml", true, true));

            foreach (string file in files)
            {
                CPlaylistFile playlist = new CPlaylistFile(file);
                _Playlists.Add(playlist);
            }

            SortPlaylistsByName();
        }
Example #18
0
        public static void Load()
        {
            _Playlists = new List <CPlaylistFile>();

            var files = new List <string>();

            files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.DataFolder, CConfig.FolderPlaylists), "*.xml", true, true));

            foreach (string file in files)
            {
                CPlaylistFile playlist = new CPlaylistFile();
                if (playlist._Load(file))
                {
                    _Playlists.Add(playlist);
                }
            }
        }
Example #19
0
        public static void RemoveSongFromPlaylist(int position, int playlistId, int songId)
        {
            CPlaylistFile pl = CPlaylists.Get(playlistId);

            if (pl == null)
            {
                throw new ArgumentException("invalid playlistId");
            }
            if (!PlaylistContainsSong(songId, playlistId))
            {
                throw new ArgumentException("invalid songId");
            }
            if (position < 0 || pl.Songs.Count <= position ||
                pl.Songs[position].SongID != songId)
            {
                throw new ArgumentException("invalid position");
            }
            pl.DeleteSong(position);
            pl.Save();
        }
Example #20
0
        public static void Delete(int playlistID)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl == null)
            {
                return;
            }
            if (pl.File != "" && File.Exists(pl.File))
            {
                try
                {
                    File.Delete(pl.File);
                }
                catch (Exception)
                {
                    CLog.Error("Can't delete Playlist File " + _Playlists[playlistID].File + ".xml");
                }
            }
            _Playlists.Remove(pl);
        }
Example #21
0
        public static void MoveSongInPlaylist(int newPosition, int playlistId, int songId)
        {
            CPlaylistFile pl = CPlaylists.Get(playlistId);

            if (pl == null)
            {
                throw new ArgumentException("invalid playlistId");
            }
            if (!PlaylistContainsSong(songId, playlistId))
            {
                throw new ArgumentException("invalid songId");
            }

            if (pl.Songs.Count < newPosition)
            {
                throw new ArgumentException("invalid newPosition");
            }

            int oldPosition = pl.Songs.FindIndex(s => s.SongID == songId);

            pl.MoveSong(oldPosition, newPosition);
            pl.Save();
        }
Example #22
0
        public static string GetName(int playlistID)
        {
            CPlaylistFile pl = Get(playlistID);

            return(pl == null ? "Error: Can't find Playlist" : pl.Name);
        }
Example #23
0
 private static int CompareByPlaylistName(CPlaylistFile a, CPlaylistFile b)
 {
     return(String.Compare(a.PlaylistName, b.PlaylistName));
 }
Example #24
0
 private static int _CompareByName(CPlaylistFile a, CPlaylistFile b)
 {
     return(String.CompareOrdinal(a.Name, b.Name));
 }
Example #25
0
        public static bool ContainsSong(int playlistID, int songID)
        {
            CPlaylistFile pl = Get(playlistID);

            return(pl != null && pl.Songs.Find((x) => x.SongID == songID) != null);
        }
Example #26
0
        public static int GetSongCount(int playlistID)
        {
            CPlaylistFile pl = Get(playlistID);

            return(pl != null ? pl.Songs.Count : -1);
        }