private void connectToolStripMenuItem_Click(object sender, EventArgs e) { ConnectionMenu connectionMenu = new ConnectionMenu(this); var path = Path.Combine(Path.GetTempPath(), "ServerList.txt"); if (!File.Exists(path)) { File.Create(path).Close(); } else { debugMenu.UpdateDebugText("Reading data from ServerList file:"); foreach (var s in File.ReadAllLines(path)) { debugMenu.UpdateDebugText(s); var serverProps = s.Split('_'); var server = new Server() { ServerName = serverProps[0], ConnectedClient = serverProps[1], ServerAddress = IPAddress.Parse(serverProps[2]), ServerPort = int.Parse(serverProps[3]) }; connectionMenu.AddServer(server); } } connectionMenu.ShowDialog(); }
/// <summary> /// splits ip and port and creates a remote IPEndPoint with that information /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCreateServer_Click(object sender, EventArgs e) { var filePath = @"C:\%temp%"; var fileName = "ServerList.txt"; var tempPath = Path.GetTempPath(); if (textBoxUserName.Text.Length >= 4) { try { string[] tempAddr = textBoxServerAddress.Text.Split(':'); IPEndPoint tempEndPoint = new IPEndPoint(IPAddress.Parse(tempAddr[0]), Convert.ToInt32(tempAddr[1])); Server newServer = new Server(textBoxServerName.Text, textBoxUserName.Text, tempEndPoint); //MessageBox.Show("Writing to file " + Path.Combine(tempPath, fileName) + "\nWith data:\n" + // newServer.ToSerializableString()); using (var sw = File.AppendText(Path.Combine(tempPath, fileName))) { sw.Write(newServer.ToSerializableString() + "\r\n"); } referencedConnectionMenu.AddServer(newServer); Close(); } catch (Exception f) { MessageBox.Show( $"Invalid Address specified, please rety.\nBe sure to input the address in the following format:\nXXX.XXX.X.X:XXXX\nFor debug:\nMessage:\n{f.Message}\nStack Trace:\n{f.StackTrace}", "Address error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Username must be atleast 4 characters long"); } }