Пример #1
0
        public static bool SetActiveConfig(string File)
        {
            var cfg = "profiles/" + File;

            if (!System.IO.File.Exists(cfg))
            {
                return(false);
            }

            lock (ActiveConfig) {
                Data d = Data.Load(File);
                ActiveConfig = d;
            }

            // Make sure the ini file exists
            ReadConfiguration(File);

            ReloadActiveConfig();

            IniFile appcfg = new IniFile("config.ini");

            appcfg.AddSetting("Xbox", "KeyProfile", File);
            appcfg.SaveSettings();

            return(true);
        }
Пример #2
0
        public static bool SetActiveConfig(string file)
        {
            var profilePath = Path.Combine("profiles", file);

            if (!File.Exists(profilePath))
            {
                return(false);
            }

            lock (ActiveConfig) {
                Data d = Data.Load(file);
                ActiveConfig = d;
            }

            // Make sure the ini file exists
            ReadConfiguration(file);

            ReloadActiveConfig();

            IniFile appcfg = new IniFile("config.ini");

            appcfg.AddSetting("Xbox", "KeyProfile", file);
            appcfg.SaveSettings();

            return(true);
        }
Пример #3
0
        public static void ReadConfiguration(string defaultProfile = "default.ini")
        {
            // Setup the default application cfg file if does not exist
            IniFile appcfg = null;

            if (!System.IO.File.Exists("config.ini"))
            {
                System.IO.File.Create("config.ini").Close();

                appcfg = new IniFile("config.ini");
                appcfg.AddSetting("Xbox", "KeyProfile", defaultProfile);
            }

            if (appcfg == null)
            {
                appcfg = new IniFile("config.ini");
            }

            if (string.IsNullOrWhiteSpace(appcfg.GetSetting("Xbox", "KeyProfile")))
            {
                appcfg.AddSetting("Xbox", "KeyProfile", defaultProfile);
            }

            appcfg.SaveSettings();

            ActiveConfigFile = appcfg.GetSetting("Xbox", "KeyProfile");
        }
Пример #4
0
        private void GenerateGui()
        {
            var s = config.GetSections().ToList();

            s.Sort();

            foreach (var section in s)
            {
                var page  = new TabPage(Utilities.GetPrettyName(section));
                var panel = new TableLayoutPanel {
                    Dock = DockStyle.Fill, ColumnCount = 2
                };
                var lastComment = "";
                var i           = 0;

                foreach (var option in config.EnumSection(section))
                {
                    if (!new[] { "#", ";", "//" }.Any(c => option.StartsWith(c)))
                    {
                        var l = new Label
                        {
                            Text      = Utilities.GetPrettyName(option) + ":",
                            TextAlign = ContentAlignment.MiddleLeft,
                            //Width = tabControlMain.Width/4,
                            AutoEllipsis = true
                        };
                        panel.SetColumn(l, 0);
                        panel.SetRow(l, i);
                        panel.Controls.Add(l);

                        Control t            = null;
                        var     defaultValue = config.GetSetting(section, option);
                        var     tooltip      = "";

                        // Check previous comment
                        if (!String.IsNullOrEmpty(lastComment))
                        {
                            var tmp = lastComment.Trim().Split(new[] { ']' }, 2);

                            if (tmp.Length > 1)
                            {
                                tooltip = tmp[1].Trim();
                            }

                            var m = Regex.Match(lastComment, @"\[(?<min>[-]?[\d.]{1,8}):(?<max>[-]?[\d.]{1,8})\]");
                            if (m.Success)
                            {
                                t = new NumericUpDown
                                {
                                    Minimum = decimal.Parse(m.Groups["min"].Value),
                                    Maximum = decimal.Parse(m.Groups["max"].Value),
                                    Value   = decimal.Parse(defaultValue)
                                };

                                ((NumericUpDown)t).ValueChanged += (o, args) => { config.AddSetting(section, option, ((NumericUpDown)o).Value.ToString()); };
                            }
                            else
                            {
                                m = Regex.Match(lastComment, @"\[(?<value>.+,.+)\]");
                                if (m.Success)
                                {
                                    t = new ComboBox {
                                        DropDownStyle = ComboBoxStyle.DropDownList, Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                                    };

                                    var items       = new List <String>();
                                    var description = new List <string>();
                                    foreach (var v in m.Groups["value"].Value.Split(new[] { ',' }))
                                    {
                                        String name, value;
                                        if (v.Contains(':'))
                                        {
                                            var parts = v.Split(new[] { ':' }, 2);
                                            name  = parts[1];
                                            value = parts[0];
                                            description.Add(String.Format(" {0} ({1})", name, value));
                                        }
                                        else
                                        {
                                            name  = v;
                                            value = v;
                                        }

                                        items.Add(value);
                                        ((ComboBox)t).Items.Add(name);

                                        if (defaultValue.Equals(value))
                                        {
                                            ((ComboBox)t).SelectedIndex = ((ComboBox)t).Items.Count - 1;
                                        }
                                    }

                                    if (description.Count > 0)
                                    {
                                        if (!String.IsNullOrEmpty(tooltip))
                                        {
                                            tooltip += Environment.NewLine + Environment.NewLine;
                                        }
                                        tooltip += "Available options:" + Environment.NewLine +
                                                   String.Join(Environment.NewLine, description);
                                    }
                                    t.Tag = items;

                                    // No default value match
                                    if (((ComboBox)t).SelectedIndex < 0)
                                    {
                                        ((ComboBox)t).DropDownStyle = ComboBoxStyle.DropDown;
                                        t.Text = defaultValue;
                                    }

                                    ((ComboBox)t).SelectedValueChanged += (o, args) =>
                                    {
                                        var c = o as ComboBox;
                                        if (c != null)
                                        {
                                            string v = null;
                                            if (c.Tag != null)
                                            {
                                                var list = c.Tag as List <string>;
                                                if (list != null)
                                                {
                                                    v = list[c.SelectedIndex];
                                                }
                                            }

                                            if (v == null)
                                            {
                                                v = c.SelectedValue.ToString();
                                            }

                                            config.AddSetting(section, option, v);
                                        }
                                    };
                                }
                            }
                        }

                        if (t == null)
                        {
                            t = new TextBox
                            {
                                Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                                Text   = defaultValue /*, Width = (int) (tabControlMain.Width / 1.5)*/
                            };

                            t.TextChanged += (o, args) => { config.AddSetting(section, option, ((TextBox)o).Text); };
                        }

                        panel.SetColumn(t, 1);
                        panel.SetRow(l, i++);
                        panel.Controls.Add(t);

                        if (!String.IsNullOrEmpty(tooltip) && toolTipInfo != null)
                        {
                            toolTipInfo.SetToolTip(t, tooltip);
                        }

                        lastComment = "";
                    }
                    else
                    {
                        lastComment = option;
                    }
                }

                if (panel.Controls.Count > 0)
                {
                    panel.AutoScroll = true;
                    page.Controls.Add(panel);
                    tabControlMain.Controls.Add(page);
                }
                else
                {
                    page.Dispose();
                    panel.Dispose();
                }
            }
        }