private bool LoadPlayers() { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load("Players.xml"); // Check version of Players.xml file string version = xmlDocument.ChildNodes[1].Attributes["version"].Value; if (!CheckVersion("Players.xml", version)) return false; XmlNodeList xmlPlayers = xmlDocument.GetElementsByTagName("player"); Properties.Settings.Default.Players.Clear(); for (int i = 0; i < xmlPlayers.Count; i++) { Player player = new Player(xmlPlayers[i]); Properties.Settings.Default.Players.Add(player); Console.WriteLine("Added player " + player.ToString()); } string[] extensions = new string[] { "mkv", "mp4", "avi", "m2ts", "webm", "m4a", "mka", "mp3", "flac" }; Properties.Settings.Default.Extensions = new ArrayList(extensions); Properties.Settings.Default.Save(); // Return success return true; }
private string ParseVideoTitle(Player player, string title) { Console.WriteLine("Title: " + title); // Remove prefix and suffix of the player from the title. title -= player.Title; Console.WriteLine("Title minus pre/suffix: " + title); // Remove the file extension from the title foreach (string extension in Properties.Settings.Default.Extensions) if (title.EndsWith(extension, true, null)) { title = title.Remove(title.Length - 1 - extension.Length); Console.WriteLine("Extension: " + extension); break; } Console.WriteLine("Title minus extension: " + title); // Remove square brackets and everything inbetween them. while (true) { int first = title.IndexOf('['); int last = title.IndexOf(']'); if (first < 0 || last < 0) break; title = title.Remove(first, last - first + 1); } Console.WriteLine("Title minus brackets: " + title); // Replace all underscores with whitespace. title = title.Replace('_', ' '); Console.WriteLine("Title minus underscores: " + title); // Remove all leading and trailing whitespace. title = title.Trim(); Console.WriteLine("Final title: " + title); return title; }
private void applyButton_Click(object sender, EventArgs e) { nameTextBox.Text = nameTextBox.Text.Trim(); fileNameTextBox.Text = fileNameTextBox.Text.Trim(); // If the video player has no name, color the relevant text box red and return if (nameTextBox.Text == string.Empty) { nameTextBox.BackColor = Color.Salmon; return; } else nameTextBox.BackColor = Color.White; // If the video player has no file name, color the relevant text box red and return if (fileNameTextBox.Text == string.Empty) { fileNameTextBox.BackColor = Color.Salmon; return; } else fileNameTextBox.BackColor = Color.White; // Remove .exe from the file name if possible if (fileNameTextBox.Text.Contains(".exe")) fileNameTextBox.Text = fileNameTextBox.Text.Replace(".exe", string.Empty); Player player = new Player(nameTextBox.Text, fileNameTextBox.Text, titlePrefixTextBox.Text, titleSuffixTextBox.Text, PlayerType.Player); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load("Players.xml"); if (playerList.SelectedItem is Player) { // If an existing player is being modified: Properties.Settings.Default.Players[playerList.SelectedIndex] = player; XmlNodeList xmlPlayers = xmlDocument.GetElementsByTagName("player"); XmlNode xmlPlayer = xmlPlayers[playerList.SelectedIndex]; xmlPlayer.Attributes["name"].Value = player.Name; xmlPlayer["filename"].InnerText = player.FileName; xmlPlayer["titleprefix"].InnerText = player.Title.Prefix; xmlPlayer["titlesuffix"].InnerText = player.Title.Suffix; } else { // If a new player is being added: Properties.Settings.Default.Players.Add(player); XmlElement xmlPlayer = xmlDocument.CreateElement("player"); XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("name"); xmlAttribute.Value = player.Name; xmlPlayer.SetAttributeNode(xmlAttribute); XmlElement fileName = xmlDocument.CreateElement("filename"); fileName.InnerText = player.FileName; xmlPlayer.AppendChild(fileName); XmlElement titlePrefix = xmlDocument.CreateElement("titleprefix"); titlePrefix.InnerText = player.Title.Prefix; xmlPlayer.AppendChild(titlePrefix); XmlElement titleSuffix = xmlDocument.CreateElement("titlesuffix"); titleSuffix.InnerText = player.Title.Suffix; xmlPlayer.AppendChild(titleSuffix); xmlDocument["players"].AppendChild(xmlPlayer); } xmlDocument.Save("Players.xml"); Properties.Settings.Default.Save(); int i = playerList.SelectedIndex; Reset(); playerList.SelectedIndex = i; }