Beispiel #1
0
        private void OnDefaultSerialPortChange(object sender, EventArgs ea)
        {
            ToolStripMenuItem tsi = sender as ToolStripMenuItem;

            if (tsi != null)
            {
                MFSerialPort port = tsi.Tag as MFSerialPort;
                if (port != null)
                {
                    m_defaultSerialPort.Checked = false;
                    Properties.Settings.Default.DefaultSerialPort = port.Name;
                    tsi.Checked           = true;
                    m_defaultSerialPort   = tsi;
                    m_transportTinyBooter = port;
                }
            }
        }
Beispiel #2
0
        internal bool ValidateArgs(string args, out string error)
        {
            bool ret = true;

            error = "";

            try
            {
                Regex           rx = new Regex(ValidCommandExpression, RegexOptions.IgnoreCase);
                MatchCollection mc = rx.Matches(args);
                if (mc.Count != 1)
                {
                    // special case /? and /h for help commands
                    rx = new Regex(FlagPrefix + @"\?|" + FlagPrefix + "h", RegexOptions.IgnoreCase);
                    if (rx.IsMatch(args))
                    {
                        m_cmd = Commands.Help;
                    }
                    else
                    {
                        error += mc.Count == 0 ? Properties.Resources.ErrorCommandMissing : Properties.Resources.ErrorCommandsMultiple + "\r\n";
                    }
                    // don't return false, because we may be invoking the UI with a given interface
                }
                else
                {
                    if (mc[0].Groups[0].Success)
                    {
                        string[] data = mc[0].Groups[0].Value.Trim().Split(new char[] { ArgSeparator }, 2);

                        m_cmd = (Commands)Enum.Parse(typeof(Commands), data[0], true);
                        switch (m_cmd)
                        {
                        case Commands.Deploy:
                            data[1]      = data[1].Replace("\"", "");
                            m_flashFiles = data[1].Trim().Split(new char[] { FileSeparator }, StringSplitOptions.RemoveEmptyEntries);
                            break;

                        case Commands.Reboot:
                            m_fWarmReboot = data.Length > 1;
                            break;
                        }
                        args = args.Replace(mc[0].Groups[0].Value, "");
                    }
                }

                if (m_cmd != Commands.Help && m_cmd != Commands.List)
                {
                    rx = new Regex(ValidInterfaceExpression, RegexOptions.IgnoreCase);
                    mc = rx.Matches(args);
                    if (mc.Count <= 0 || mc.Count > 2)
                    {
                        error = mc.Count == 0 ? Properties.Resources.ErrorInterfaceMissing : Properties.Resources.ErrorInterfaceMultiple + "\r\n";
                        ret   = false;
                    }
                    else
                    {
                        for (int i = 0; i < mc.Count; i++)
                        {
                            if (mc[i].Groups[0].Success)
                            {
                                string[] data = mc[i].Groups[0].Value.Trim().Split(ArgSeparator);

                                TransportType type = (TransportType)Enum.Parse(typeof(TransportType), data[1], true);

                                switch (type)
                                {
                                case TransportType.Serial:
                                    m_transports[i] = new MFSerialPort(@"COM" + data[2], @"\\.\COM" + data[2]);
                                    break;

                                case TransportType.USB:
                                    m_transports[i] = new MFUsbPort(data[2]);
                                    break;

                                case TransportType.TCPIP:
                                    m_transports[i] = new MFTcpIpPort(data[2], "");
                                    break;
                                }
                            }
                            args = args.Replace(mc[i].Groups[0].Value, "");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ret    = false;
                error += e.ToString() + "\r\n";
            }

            if (m_cmd != Commands.Help && m_cmd != Commands.List && ret)
            {
                args = args.Trim();
                if (args.Length != 0)
                {
                    ret   = false;
                    error = Properties.Resources.ErrorArgumentsInvalid + args;
                }
            }

            return(ret);
        }