예제 #1
0
파일: Form1.cs 프로젝트: umby24/D3GUI
        public void SaveSettings()
        {
            // -- Save bot settings
            SettingsReader rc;

            if (!File.Exists("GUI.ini"))
                rc = new SettingsReader("GUI.ini", true);
            else {
                rc = new SettingsReader("GUI.ini");
                rc.ReadSettings();
            }

            var settings = new byte[1];
            new BitArray(CSettings).CopyTo(settings, 0);

            if (!rc.Settings.ContainsKey("Console"))
                rc.Settings.Add("Console", settings[0].ToString());
            else
                rc.Settings["Console"] = settings[0].ToString();

            if (!rc.Settings.ContainsKey("server"))
                rc.Settings.Add("server", ServerVersion);
            else
                rc.Settings["server"] = ServerVersion;

            rc.SaveSettings();

            // -- Save server settings.

            var files = new List<string> { "Data\\System.txt", "Data\\Player.txt", "Data\\Network.txt", "Data\\Heartbeat.txt" }; // -- The files the contain GUI configurable items.
            var tempFile = "";

            foreach (var file in files) {
                var fileReader = new StreamReader(file);

                do {
                    string myLine = fileReader.ReadLine();

                    if (myLine == "") {
                        continue;
                    }

                    var instruction = myLine.Substring(0, myLine.IndexOf(" "));

                    switch (instruction) {
                        case "Server_Name":
                            myLine = "Server_Name = " + boxSName.Text;
                            break;
                        case "MOTD":
                            myLine = "MOTD = " + boxMOTD.Text;
                            break;
                        case "Click_Distance":
                            myLine = "Click_Distance = " + txtClickDistance.Text;
                            break;
                        case "Message_Welcome":
                            myLine = "Message_Welcome = " + boxLogin.Text;
                            break;
                        case "Players_Max":
                            myLine = "Players_Max = " + boxMax.Text;
                            break;
                        case "Name_Verification":
                            myLine = "Name_Verification = " + Convert.ToByte(chkNameVerif.Checked);
                            break;
                        case "Port":
                            myLine = "Port = " + boxPort.Text;
                            break;
                        case "Public":
                            myLine = "Public = " + Convert.ToByte(chkPub.Checked);
                            break;
                    }
                    tempFile += myLine + "\n";
                } while (!fileReader.EndOfStream);

                tempFile = tempFile.Substring(0, tempFile.Length - 1); // -- Remove the extra new line.
                fileReader.Close();

                var fileWriter = new StreamWriter(file); // -- Write the settings to file.
                fileWriter.Write(tempFile);
                fileWriter.Close();
                tempFile = "";
            }
            LoadSettings(); // -- Reload the settings so the GUI's variables are all updated accordingly.
        }
예제 #2
0
파일: Form1.cs 프로젝트: umby24/D3GUI
        private void LoadSettings()
        {
            // -- Load settings in from the various .txt files.
            var files = new List<string> { "Data\\System.txt", "Data\\Player.txt", "Data\\Network.txt", "Data\\Heartbeat.txt" };

            foreach (var file in files) {
                var fileReader = new StreamReader(file);

                do {
                    string myLine = fileReader.ReadLine();

                    if (myLine == "")
                        continue;

                    var instruction = myLine.Substring(0, myLine.IndexOf(" "));
                    var data = myLine.Substring(myLine.IndexOf("=") + 2, myLine.Length - (myLine.IndexOf("=") + 2));

                    switch (instruction) {
                        case "Server_Name":
                            _serverName = data;
                            break;
                        case "MOTD":
                            _motd = data;
                            break;
                        case "Click_Distance":
                            _clickDistance = data;
                            break;
                        case "Message_Welcome":
                            _welcomeMessage = data;
                            break;
                        case "Players_Max":
                            _maxPlayers = data;
                            break;
                        case "Name_Verification":
                            _nameVerify = (byte)int.Parse(data);
                            break;
                        case "Port":
                            _port = data;
                            break;
                        case "Public":
                            _pub = (byte)int.Parse(data);
                            break;
                    }

                } while (!fileReader.EndOfStream);
                fileReader.Close();
            }

            boxMax.Text = _maxPlayers;
            boxMOTD.Text = _motd;
            boxSName.Text = _serverName;
            boxLogin.Text = _welcomeMessage;
            boxPort.Text = _port;
            txtClickDistance.Text = _clickDistance;

            chkNameVerif.Checked = BitConverter.ToBoolean(new[] { _nameVerify }, 0);
            chkPub.Checked = BitConverter.ToBoolean(new[] { _pub }, 0);

            // -- Now load settings specific to the GUI.
            byte settings = 62;
            var buttons = "";

            if (File.Exists("GUI.ini")) {
                var sc = new SettingsReader("GUI.ini");
                sc.ReadSettings();
                if (sc.Settings.ContainsKey("Console"))
                    settings = (byte)int.Parse(sc.Settings["Console"]);
                if (sc.Settings.ContainsKey("luas"))
                    buttons = sc.Settings["luas"];
                if (sc.Settings.ContainsKey("server"))
                    ServerVersion = sc.Settings["server"];
            }

            CSettings = new[] { Convert.ToBoolean(settings & 0x1), Convert.ToBoolean(settings & 0x2), Convert.ToBoolean(settings & 0x4), Convert.ToBoolean(settings & 0x8), Convert.ToBoolean(settings & 0x10), Convert.ToBoolean(settings & 0x20), Convert.ToBoolean(settings & 0x40) };

            // -- Custom buttons...

            if (buttons == "")
                return;

            var splits = buttons.Split(new[] { '|' },StringSplitOptions.RemoveEmptyEntries);

            foreach (var c in splits) {
                var name = c.Substring(0, c.IndexOf(","));
                var fileName = c.Substring(c.IndexOf(",") + 1, c.Length - (c.IndexOf(",") + 1));
                AddButton(name, fileName);
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: umby24/D3GUI
        private void btnAddLua_Click(object sender, EventArgs e)
        {
            var fileName = "";
            var p = MessageBox.Show("Would you like to create a new script, or run an existing one? Yes for new.", "New LUA", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (p == DialogResult.Cancel)
                return;

            if (p == DialogResult.Yes) {
                var newFile = new SaveFileDialog
                {
                    InitialDirectory = _serverProc.StartInfo.WorkingDirectory + "\\Lua\\",
                    Filter = "Lua Scripts | *.lua"
                };

                newFile.ShowDialog();
                fileName = newFile.FileName;

                var sNewFile = new StreamWriter(newFile.FileName);
                sNewFile.Write(" ");
                sNewFile.Close();

                if (fileName == "")
                    return;
            }
            if (p == DialogResult.No) {
                var newFile = new OpenFileDialog
                {
                    InitialDirectory = _serverProc.StartInfo.WorkingDirectory + "\\Lua\\",
                    Filter = "Lua Scripts | *.lua"
                };

                newFile.ShowDialog();
                fileName = newFile.FileName;

                if (fileName == "")
                    return;
            }
            var buttonName = Interaction.InputBox("Please give a name for the custom button", "Adding LUA");

            if (buttonName == "")
                return;

            var thisresult = MessageBox.Show("Would you like to edit the file now?", "Lua Add", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (thisresult == DialogResult.Yes) {
                var tm = new TimedMessages {File = fileName};
                tm.Show();
            }

            SettingsReader rc;

            if (!File.Exists("GUI.ini"))
                rc = new SettingsReader("GUI.ini", true);
            else {
                rc = new SettingsReader("GUI.ini");
                rc.ReadSettings();
            }

            var oldButtons = "";

            if (rc.Settings.ContainsKey("luas"))
                oldButtons = rc.Settings["luas"];

            oldButtons += buttonName + "," + fileName + "|";
            rc.Settings["luas"] = oldButtons;

            rc.SaveSettings();

            AddButton(buttonName, fileName);
        }
예제 #4
0
파일: Form1.cs 프로젝트: umby24/D3GUI
        private void HandleButtons(object sender, EventArgs e)
        {
            var clicked = (Button)sender;

            string fileName;
            _cButtons.TryGetValue(clicked.Text, out fileName);

            if (fileName == "") {
                MessageBox.Show("An error has occured.");
                return;
            }
            if (_removing) {
                _removing = false;
                var sc = new SettingsReader("GUI.ini");
                sc.ReadSettings();

                var oldString = "";
                if (sc.Settings.ContainsKey("luas"))
                    oldString = sc.Settings["luas"];

                oldString = oldString.Replace(clicked.Text + "," + fileName + "|", "");
                sc.Settings["luas"] = oldString;
                sc.SaveSettings();

                Controls.Remove(clicked);
                tabPage9.Controls.Remove(clicked);
                clicked.Dispose();
                return;
            }

            if (fileName != null) File.SetLastWriteTime(fileName, DateTime.Now);
        }