Example #1
0
        private void LoadConfig(string file = "")
        {
            FileStream stream = null;


            if (file == "")
            {
                var dialog = new OpenFileDialog();
                dialog.Filter = "JSON|*.json";
                dialog.Title  = "Load config file";
                dialog.ShowDialog();
                file = dialog.FileName;
                if (file != "")
                {
                    stream = (FileStream)dialog.OpenFile();
                }
            }
            else
            {
                stream = new FileStream(file, FileMode.Open, FileAccess.ReadWrite);
            }

            try
            {
                if (file != "")
                {
                    using (var fs = new StreamReader(stream))
                    {
                        dynamic obj = JObject.Parse(fs.ReadToEnd());

                        Program.controller    = obj.Buttons.ToObject <ControlMap>();
                        IconSize              = (int)obj.IconSize;
                        cmbTheme.SelectedItem = obj.Theme.ToString();
                        ImageMap              = obj.Images.ToObject <Dictionary <int, List <int> > >();
                        lblColor.BackColor    = obj.Color.ToObject <Color>();
                        chkFrames.Checked     = obj.ShowFrames.ToObject <bool>();
                        chkDirColumn.Checked  = obj.SeparateDirections.ToObject <bool>();
                        chkSound.Checked      = obj.Sounds.ToObject <bool>();
                        rdbVertical.Checked   = obj.Vertical.ToObject <bool>();
                        rdbHorizontal.Checked = !obj.Vertical.ToObject <bool>();


                        try
                        {
                            DeviceId = Guid.Parse(obj.deviceId.ToString());
                            SlimWrapper.Acquire(this, DeviceId);
                        }
                        catch
                        {
                            MessageBox.Show("Cant find the controller used in this config, please select another");
                            btnSelect_Click(null, EventArgs.Empty);
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("Cant load this config file.");
            }
        }
Example #2
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DeviceId = (Guid)cmdDevices.SelectedValue;

            SlimWrapper.Acquire(this, DeviceId);
            // Program.controller = new ControlMap();
            timer.Enabled       = true;
            pictureBox1.Visible = false;
        }