public Track(NowPlayingTrackInfo trackInfo) { XmlPath = new Uri($"{trackInfo.FilePath}.xml", UriKind.Absolute); NowPlayingTrackInfo = trackInfo; ChapterList = new ChapterList(); ChapterList.ChapterListUpdated += ChapterList_ChapterListUpdated; }
/// <summary> /// Reads ChapterList data into the provided ChapterList object /// </summary> /// <param name="chapList">Object to read XML chapters into</param> internal static void ReadChapterListFromXml(ChapterList chapList) { try { if (!System.IO.File.Exists(Track.XmlPath.LocalPath)) { throw new FileNotFoundException(); } var chaptersListDoc = XDocument.Load(Track.XmlPath.LocalPath); if (chaptersListDoc.Root.Attribute("version").Value == "1.0") // 1.0 is original chapterlist XML format { foreach (var xElement in chaptersListDoc.Descendants("Chapter")) { chapList.CreateNewChapter(xElement.Attribute("name").Value, int.Parse(xElement.Attribute("pos").Value)); } } } catch (FileNotFoundException) { // ignored } catch (Exception) { // ignored } }
public bool Equals(Track other) { if ((object)other == null) { return(false); } return(ChapterList.Equals(other.ChapterList) && NowPlayingTrackInfo.Equals(other.NowPlayingTrackInfo)); }
public override bool Equals(object obj) { if (obj == null) { return(false); } Track track = obj as Track; if ((object)track == null) { return(false); } return(ChapterList.Equals(track.ChapterList) && NowPlayingTrackInfo.Equals(track.NowPlayingTrackInfo)); }
/// <summary> /// Saves provided ChapterList to XML format /// </summary> /// <param name="chapList"></param> internal static void SaveChapterListToXml(ChapterList chapList) { var xmlDoc = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XElement("Chapterlist", new XAttribute("version", "1.0") ) ); foreach (var chapter in chapList) { var newElement = new XElement("Chapter", new XAttribute("pos", chapter.Position), new XAttribute("name", chapter.Title) ); xmlDoc.Root.Add(newElement); } xmlDoc.Save(Track.XmlPath.LocalPath); }
private void ChapterList_ChapterListUpdated(object sender, EventArgs e) { ChapterList.SaveChaptersToFile(); }