public UserNameFinder() { InitializeComponent(); this.Text = "Username Parser v0.42"; OpenFileDialog.Filter = extensionName + " files (*" + extension + ")|*" + extension; saveFileDialog_Export.Filter = extensionName + " files (*" + extension + ")|*" + extension; meChats = new User("Unknown /me Chat Posts", 0); }
public void ParseUsers(string[] lines) { listBox_Users.Items.Clear(); //Removes what was previous in the list box. users.Clear(); //Removes the entries in the user list. meChats = new User("Unknown /me Chat Posts", 0); // Recreates meChats which also removes any previous chat messages. foreach (string line in lines) { int indexStart = line.IndexOf(']'); int indexEnd = line.IndexOf(':'); indexEnd = line.IndexOf(':', indexEnd + 1); indexStart += 2; //Adds one to account for the bracket, and another for the space after the time stamp. string username = string.Empty; if (indexStart != 0 && indexEnd != -1) { username = line.Substring(indexStart, (indexEnd - indexStart)); } User newUser = new User(username, indexEnd); newUser.AddMessage(line); bool passed = true; //I dislike this. if (newUser.ToString() != "") // /me posts end up having no defined username and thus are "". { foreach (User u in users) { if (u.ToString() == newUser.ToString()) { u.AddMessage(newUser.UserChatMessages[0]); passed = false; break; } } if (passed) { users.Add(newUser); //Adds it to the users list. } } else { meChats.AddMessage(line); //Add the /me post to the meChats user. } } List<string> tempMeChatList = meChats.UserChatMessages; for (int j = 0; j < users.Count; j++) { for (int i = tempMeChatList.Count - 1; i >= 0; i--) //Now it loops back through all the meChats and assigns the /me post to a known user. { if (tempMeChatList[i].IndexOf(users[j].ToString()) == 8) { users[j].AddMessage(tempMeChatList[i]); meChats.RemoveMessage(i); } } } }