Exemple #1
0
        private bool CheckJoystick()
        {
            var valid =
                __Panels.Count > 0 &&
                __Panels.Aggregate(true, (current, panel) => current & panel.Check());

            valid = valid &
                    ValidateControl(tbName, () => !string.IsNullOrWhiteSpace(tbName.Text));


            UInt16 v = 0;
            UInt16 p = 0;

            valid = valid & ValidateControl(tbVendorProduct, () =>
            {
                string[] vs = tbVendorProduct.Text.Split(':');
                if (vs.Length != 2)
                {
                    return(false);
                }

                return(UInt16.TryParse(vs[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out v) &
                       UInt16.TryParse(vs[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out p));
            });

            if (!valid)
            {
                return(false);
            }

            _joystickInfo = new JoystickConfig
            {
                Code            = wrex.Replace(tbName.Text, "").ToUpper(),
                Name            = tbName.Text,
                ProductID       = p,
                VendorID        = v,
                ReportStructure = __RepoprtStructure,
                ID = __ID != Guid.Empty ? __ID : Guid.NewGuid()
            };

            foreach (var panel in __Panels)
            {
                panel.FillJoyInfo(_joystickInfo);
            }

            if (_joystickInfo.Bits() % 8 != 0)
            {
                MessageBox.Show(this, "Wrong total bits number, must be multiple of 8", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            return(true);
        }
Exemple #2
0
        private bool CheckJoystick()
        {
            var valid =
                __Panels.Count > 0 &&
                __Panels.Aggregate(true, (current, panel) => current & panel.Check());

            valid = valid &
                    ValidateControl(tbName, () => !string.IsNullOrWhiteSpace(tbName.Text)) &
                    ValidateControl(tbCName, () => checkRex.IsMatch(tbCName.Text));

            if (!valid)
            {
                return(false);
            }

            _joystickInfo = new JoystickConfig
            {
                Code = tbCName.Text,
                Name = tbName.Text
            };

            foreach (var panel in __Panels)
            {
                panel.FillJoyInfo(_joystickInfo);
            }

            if (_joystickInfo.Bits() % 8 != 0)
            {
                MessageBox.Show(this, "Wrong total bits number, must be multiple of 8", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            return(true);
        }