Exemple #1
0
        public frmSettings()
        {
            InitializeComponent();
            string[] portNames = SerialPort.GetPortNames();
            foreach (string port in portNames)
            {
                if (port.StartsWith("COM"))
                {
                    cbWidebandComPort.Properties.Items.Add(port);
                }
            }
            cbWidebandComPort.SelectedIndex = 0;

            // Fetch adapter types from TrionicCANLib.API
            cbAdapterType.Properties.Items.Clear();
            foreach (var AdapterType in Enum.GetValues(typeof(CANBusAdapter)))
            {
                try
                {
                    cbAdapterType.Properties.Items.Add(((DescriptionAttribute)AdapterType.GetType().GetField(AdapterType.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false)[0]).Description.ToString());
                    cbAdapterType.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
                }
                catch (Exception ex)
                {
                    logger.Debug(ex.Message);
                }
            }
        }
Exemple #2
0
        public void LoadRegistrySettings()
        {
            // Fetch adapter types from TrionicCANLib.API
            cbxAdapterType.Items.Clear();

            foreach (var AdapterType in Enum.GetValues(typeof(CANBusAdapter)))
            {
                try
                {
                    cbxAdapterType.Items.Add(((DescriptionAttribute)AdapterType.GetType().GetField(AdapterType.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false)[0]).Description.ToString());
                }

                catch (Exception ex)
                {
                    logger.Debug(ex.Message);
                }
            }

            RegistryKey SoftwareKey     = Registry.CurrentUser.CreateSubKey("Software");
            RegistryKey ManufacturerKey = SoftwareKey.CreateSubKey("MattiasC");

            using (RegistryKey Settings = ManufacturerKey.CreateSubKey("TrionicCANFlasher"))
            {
                if (Settings != null)
                {
                    string[] vals = Settings.GetValueNames();
                    foreach (string a in vals)
                    {
                        try
                        {
                            if (a == "AdapterType")
                            {
                                AdapterType.Name = Settings.GetValue(a).ToString();
                            }
                            else if (a == "Adapter")
                            {
                                Adapter.Name = Settings.GetValue(a).ToString();
                            }
                            else if (a == "ComSpeed")
                            {
                                Baudrate.Name = Settings.GetValue(a).ToString();
                            }
                            else if (a == "ECU")
                            {
                                SelectedECU.Name = Settings.GetValue(a).ToString();
                            }

                            else if (a == "EnableLogging")
                            {
                                m_enablelog = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "OnboardFlasher")
                            {
                                m_onbflash = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "OnlyPBus")
                            {
                                m_onlypbus = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "UseLegionBootloader")
                            {
                                m_uselegion = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }

                            else if (a == "PowerUser")
                            {
                                m_poweruser = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "FormatSystemPartitions")
                            {
                                m_unlocksys = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "FormatBootPartition")
                            {
                                m_unlckboot = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "AutoChecksum")
                            {
                                m_autocsum = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }

                            else if (a == "SuperUser")
                            {
                                m_enablesufeatures = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "UseLastAddressPointer")
                            {
                                m_uselastpointer = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }

                            else if (a == "ViewRemember")
                            {
                                m_remember = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewWidth")
                            {
                                m_width = Convert.ToInt32(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewHeight")
                            {
                                m_height = Convert.ToInt32(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewFullscreen")
                            {
                                m_fullscreen = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                            else if (a == "ViewCollapsed")
                            {
                                m_collapsed = Convert.ToBoolean(Settings.GetValue(a).ToString());
                            }
                        }

                        catch (Exception ex)
                        {
                            logger.Debug(ex.Message);
                        }
                    }
                }
            }

            try
            {
                if (AdapterType.Name != null)
                {
                    cbxAdapterType.SelectedItem = AdapterType.Name;
                    AdapterType.Index           = cbxAdapterType.SelectedIndex;
                }

                if (Adapter.Name != null)
                {
                    cbxAdapterItem.SelectedItem = Adapter.Name;
                    Adapter.Index = cbxAdapterItem.SelectedIndex;
                }

                if (Baudrate.Name != null)
                {
                    cbxComSpeed.SelectedItem = Baudrate.Name;
                    Baudrate.Index           = cbxComSpeed.SelectedIndex;
                }
            }

            catch (Exception ex)
            {
                logger.Debug(ex.Message);
            }

            /////////////////////////////////////////////
            // Recover from strange settings in registry

            // Make sure settings are returned to safe values in case power user is not enabled
            if (!m_poweruser)
            {
                m_unlocksys = false;
                m_unlckboot = false;
                m_autocsum  = false;

                m_enablesufeatures = false;
            }

            // We have to plan this section..
            if (!m_enablesufeatures)
            {
                m_verifychecksum      = true;
                m_uselastpointer      = true;
                m_faster              = false;
                InterframeDelay.Index = 9;
            }

            // Maybe we should have different unlock sys for ME9 and T8?
            if (!m_unlocksys)
            {
                m_unlckboot = false;
            }

            if ((m_fullscreen && m_collapsed) || !m_remember)
            {
                m_collapsed  = false;
                m_fullscreen = false;
            }
        }