public static int NewPlaylist() { CPlaylistFile pl = new CPlaylistFile(); pl.PlaylistName = "New Playlist"; _Playlists.Add(pl); return(_Playlists.Count - 1); }
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); }
public static int NewPlaylist(string name = "New Playlist") { CPlaylistFile pl = new CPlaylistFile { Name = name }; _Playlists.Add(pl); return(pl.Id); }
public static void MoveSong(int playlistID, int sourceIndex, int destIndex) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.MoveSong(sourceIndex, destIndex); } }
public static void DeleteSong(int playlistID, int songIndex) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.DeleteSong(songIndex); } }
public static void InsertSong(int playlistID, int positionIndex, int songID, EGameMode gameMode) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.InsertSong(positionIndex, songID, gameMode); } }
public static void Save(int playlistID) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.Save(); } }
public static void SetName(int playlistID, string name) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.Name = name; } }
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); }
public static void MoveSongUp(int playlistID, int songIndex) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.MoveSongUp(songIndex); } }
public static void AddSong(int playlistID, int songID, EGameMode gameMode) { CPlaylistFile pl = Get(playlistID); if (pl != null) { pl.AddSong(songID, gameMode); } }
private static SPlaylistData _GetPlaylistInfo(CPlaylistFile playlist) { return(new SPlaylistData { PlaylistId = playlist.Id, PlaylistName = playlist.Name, SongCount = playlist.Songs.Count, LastChanged = DateTime.Now.ToLongDateString() }); }
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)); }
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]); }
public static SPlaylistSongInfo[] GetPlaylistSongs(int playlistId) { CPlaylistFile pl = CPlaylists.Get(playlistId); if (pl == null) { throw new ArgumentException("invalid playlistId"); } return(_GetPlaylistSongInfos(pl)); }
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); } }
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(); }
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); } } }
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(); }
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); }
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(); }
public static string GetName(int playlistID) { CPlaylistFile pl = Get(playlistID); return(pl == null ? "Error: Can't find Playlist" : pl.Name); }
private static int CompareByPlaylistName(CPlaylistFile a, CPlaylistFile b) { return(String.Compare(a.PlaylistName, b.PlaylistName)); }
private static int _CompareByName(CPlaylistFile a, CPlaylistFile b) { return(String.CompareOrdinal(a.Name, b.Name)); }
public static bool ContainsSong(int playlistID, int songID) { CPlaylistFile pl = Get(playlistID); return(pl != null && pl.Songs.Find((x) => x.SongID == songID) != null); }
public static int GetSongCount(int playlistID) { CPlaylistFile pl = Get(playlistID); return(pl != null ? pl.Songs.Count : -1); }