private void ConvertToArchosFormat(ref M3UEditor me, ref OperationResult op) { List <string> list = new List <string>(); string rootMusicDir = dddtbMusicDir.ItemText; int rootPos = -1; string archosVer = string.Empty; foreach (string song in me.M3USongList) { archosVer = song; rootPos = archosVer.IndexOf(rootMusicDir, StringComparison.CurrentCultureIgnoreCase); if (rootPos > -1) { list.Add(archosVer.Substring(rootPos).Replace("\\", "/")); } else { op.AddError("One or more songs do not contain " + rootMusicDir + " in it's path"); return; } } me.SetM3USongs(list, false, ref op); }
private void openM3UToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); if (openFileDialog1.FileName.Trim().Length < 1 || !File.Exists(openFileDialog1.FileName)) { MessageBox.Show("You must choose a file!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OperationResult op = new OperationResult(); M3UEditor me = new M3UEditor(); me.SetM3U(openFileDialog1.FileName, new List <string>(), false, ref op); if (!op.Success) { MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } uftM3U.SetListBox(me.M3USongList, BCHControls.UCFromToEnum.To, true); uftM3U.SetListBox(me.M3USongList, BCHControls.UCFromToEnum.From, true); tbM3UFileName.Text = me.M3UFileName; dddtbM3uPath.ItemText = me.M3UPath; }
private void saveM3uToolStripMenuItem_Click(object sender, EventArgs e) { if (!pnlM3UPlayList.Visible) { return; } string msg = string.Empty; if (tbM3UDir.Text.Length < 0) { msg = "You must have a valid M3U path selected! \n"; } if (tbM3UFileName.Text.Length < 0 || tbM3UFileName.Text.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { msg += "You must have a valid file name! \n File name cannot cantain any of these characters:" + Path.GetInvalidFileNameChars().ToString(); } if (msg.Length < 0) { MessageBox.Show("Error!", msg, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OperationResult op = new OperationResult(); M3UEditor me = new M3UEditor(); string fileName = Path.Combine(tbM3UDir.Text, tbM3UFileName.Text); me.SetM3U(fileName, uftM3U.GetStrList(BCHControls.UCFromToEnum.To), true, ref op); if (!op.Success) { MessageBox.Show("Error!", op.GetAllMessages("\n"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } me.CreateM3U(ref op); if (!op.Success) { MessageBox.Show("Error!", op.GetAllMessages("\n"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Complete!", "M3U File Created.", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void SaveMediaPlayerFormat(string fileName, ref M3UEditor me, ref OperationResult op) { List <string> list = new List <string>(); XmlDocument wpl = new XmlDocument(); XmlNode smil = wpl.CreateElement("smil"); wpl.AppendChild(smil); XmlNode head = wpl.CreateElement("head"); smil.AppendChild(head); XmlNode meta = wpl.CreateElement("meta"); head.AppendChild(meta); XmlAttribute attribute = wpl.CreateAttribute("name"); attribute.Value = "Generator"; meta.Attributes.Append(attribute); attribute = wpl.CreateAttribute("content"); attribute.Value = "Microsoft Windows Media Player -- 12.0.7600.20792"; meta.Attributes.Append(attribute); meta = wpl.CreateElement("meta"); head.AppendChild(meta); attribute = wpl.CreateAttribute("name"); attribute.Value = "ItemCount"; meta.Attributes.Append(attribute); attribute = wpl.CreateAttribute("content"); attribute.Value = me.M3USongList.Count.ToString(); meta.Attributes.Append(attribute); XmlNode title = wpl.CreateElement("title"); head.AppendChild(title); title.AppendChild(wpl.CreateTextNode(Path.GetFileNameWithoutExtension(tbM3UFileName.Text))); XmlNode body = wpl.CreateElement("body"); smil.AppendChild(body); XmlNode seq = wpl.CreateElement("seq"); body.AppendChild(seq); string rootMusicDir = dddtbMusicDir.ItemText; foreach (string song in me.M3USongList) { XmlNode media = wpl.CreateElement("media"); seq.AppendChild(media); attribute = wpl.CreateAttribute("src"); attribute.Value = HttpUtility.HtmlEncode(song); media.Attributes.Append(attribute); } wpl.Save(fileName + ".wpl"); }
private void saveM3uToolStripMenuItem_Click(object sender, EventArgs e) { if (!pnlM3UPlayList.Visible) { return; } string msg = string.Empty; if (dddtbM3uPath.ItemText.Length < 0) { msg = "You must have a valid M3U path selected! \n"; } if (tbM3UFileName.Text.Length < 0 || tbM3UFileName.Text.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { msg += "You must have a valid file name! \n File name cannot cantain any of these characters:" + Path.GetInvalidFileNameChars().ToString(); } if (ckbDoArchosFormat.Checked && string.IsNullOrEmpty(dddtbMusicDir.ItemText)) { msg += "You must have an Archos Directory"; } if (msg.Length < 0) { MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OperationResult op = new OperationResult(); M3UEditor me = new M3UEditor(); string fileName = Path.Combine(dddtbM3uPath.ItemText, tbM3UFileName.Text); me.SetM3U(fileName, uftM3U.GetStrList(BCHControls.UCFromToEnum.To), true, ref op); if (!op.Success) { MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (rbDoArchosM3UFormat.Checked || rbPlainM3U.Checked) { if (rbDoArchosM3UFormat.Checked) { ConvertToArchosFormat(ref me, ref op); if (!op.Success) { MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } me.CreateM3U(ref op); } else { SaveMediaPlayerFormat(fileName, ref me, ref op); } MessageBox.Show("M3U File Created.", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information); }