private void Save()
        {
            var sprop = new ServerProperties();
            int p     = 0;

            foreach (TextBox tb in keys)
            {
                var stype = sprop.ServerVars[tb.Text].type;

                TextBox  valtext  = null;
                CheckBox valcheck = null;
                if (stype == 0 || stype == 1)
                {
                    valtext = (TextBox)values[p];
                    sprop.ServerVars[tb.Text].value = valtext.Text;
                }
                else
                {
                    valcheck = (CheckBox)values[p];
                    sprop.ServerVars[tb.Text].value = valcheck.Checked.ToString().ToLower();
                }

                p++;
            }

            File.WriteAllText(sPropFile == null ? sPropDir + "/server.properties" : sPropFile, sprop.ToString());
        }
Exemple #2
0
        public static ServerProperties FromFile(string file)
        {
            var spProp = new ServerProperties();

            if (File.Exists(file))
            {
                string[] lines = File.ReadAllLines(file);
                foreach (string line in lines)
                {
                    if (line[0] != '#')
                    {
                        var vs = line.Split('=');
                        spProp.ServerVars[vs[0]].value = vs[1];
                    }
                }
            }

            return(spProp);
        }
Exemple #3
0
 private bool BackupMode = false; // false Worlds -> Backups. true Backups -> Worlds, you get it
 public WorldMod(string dir)
 {
     InitializeComponent();
     svdir = dir;
     svp   = ServerProperties.FromFile(svdir + "/server.properties");
 }
        private void PropertiesEditor_Load(object sender, EventArgs e)
        {
            if (sPropFile == null)
            {
                sprop = ServerProperties.FromFile(sPropDir + "/server.properties");
            }
            else
            {
                sprop = ServerProperties.FromFile(sPropFile);
            }
            int  y   = 0;
            Font fnt = new Font("Consolas", 8);

            foreach (KeyValuePair <string, SPropSetting> KVP in sprop.ServerVars)
            {
                if (KVP.Value.value != null && !bShowAllSettings)
                {
                    var kvp_value = KVP.Value.value != null ? KVP.Value.value : bShowAllSettings ? "" : null;

                    var tbNewBox = new TextBox();
                    tbNewBox.Text     = KVP.Key;
                    tbNewBox.Location = new Point(0, y);

                    tbNewBox.BackColor = SystemColors.InactiveCaption;
                    tbNewBox.Size      = new Size(200, 20);
                    tbNewBox.TextAlign = HorizontalAlignment.Right;
                    tbNewBox.Font      = fnt;
                    tbNewBox.ReadOnly  = true;
                    keys.Add(tbNewBox);
                    switch (KVP.Value.type)
                    {
                    case 0:     // String
                    case 1:     // Int
                        var tbNewBox2 = new TextBox();
                        tbNewBox2.Text         = kvp_value;
                        tbNewBox2.Location     = new Point(200, y);
                        tbNewBox2.BackColor    = SystemColors.ActiveCaption;
                        tbNewBox2.Size         = new Size(200, 20);
                        tbNewBox2.TextAlign    = HorizontalAlignment.Left;
                        tbNewBox2.Font         = fnt;
                        tbNewBox2.TextChanged += ItemChanged;
                        values.Add(tbNewBox2);
                        Controls.Add(tbNewBox2);
                        break;

                    case 2:
                        var  chkNewCheck = new CheckBox();
                        bool check       = false;
                        bool cs          = bool.TryParse(KVP.Value.value, out check);
                        chkNewCheck.Checked         = cs ? check : false;
                        chkNewCheck.Location        = new Point(200, y);
                        chkNewCheck.Size            = new Size(200, 20);
                        chkNewCheck.CheckedChanged += ItemChanged;
                        Controls.Add(chkNewCheck);
                        values.Add(chkNewCheck);
                        break;

                    default: break;
                    }
                    y += 20;

                    Controls.Add(tbNewBox);
                }
            }
        }