Exemplo n.º 1
0
        public void logcat(Form1 form)
        {
            clearLogcat(form);
            curDev = form.getLogcatParams();
            Process p = new Process();

            p.StartInfo.FileName               = CMD;                                        //设定程序名
            p.StartInfo.Arguments              = "-s " + form.getLogcatParams() + " logcat"; //设定程式执行參數
            p.StartInfo.UseShellExecute        = false;                                      //关闭Shell的使用
            p.StartInfo.RedirectStandardInput  = true;                                       //重定向标准输入
            p.StartInfo.RedirectStandardOutput = true;                                       //重定向标准输出
            p.StartInfo.RedirectStandardError  = true;                                       //重定向错误输出
            p.StartInfo.CreateNoWindow         = true;                                       //设置不显示窗口
            p.StartInfo.StandardOutputEncoding = Encoding.UTF8;                              // 一定要事先设置编码

            p.OutputDataReceived += (sender, outputLine) =>
            {
                if (outputLine.Data != null && outputLine.Data.Length > 2)
                {
                    String data = outputLine.Data;
                    if (data.StartsWith("---"))
                    {
                        return;
                    }

                    LogCatLog log = new LogCatLog(data);
                    form.receive_data(log);
                }
            };

            p.Start();
            p.BeginOutputReadLine();

            killLogcatProcess();

            logCatProcess = p;
        }
Exemplo n.º 2
0
        /* 回调函数
         *  aa | bb 显示包含aa或bb的数据
         *  aaaa n 3为 包含aaa接下来的3行显示
         */
        public void receive_data(Object data, Boolean isAddList = true)
        {
            LogCatLog log = (LogCatLog)data;

            if (searchData != null && searchData.isStop && isAddList)
            {
                return;    // 按下了stop按键
            }
            if (isAddList) // 保存暂时的log信息
            {
                if (isAddList)
                {
                    listLogs.Add(log);
                }
                if (listLogs.Count > 2000)
                {
                    listLogs.RemoveAt(0);
                }
            }

            if (!String.IsNullOrEmpty(log.Tag))
            {
                String        tag  = log.Tag;
                List <String> list = new List <string>();
                //list.Add("CaOptCtrl");
                //list.Add("DEBUG   (");
                //list.Add("DVBService(");
                //list.Add("ConnectivityService(");
                //list.Add("libhi_common(");
                //list.Add("DVBStackImp(");
                //list.Add("hidvbjava(");
                //list.Add("MessageParser(");
                //list.Add("FCDvb   (");
                //list.Add("hidvb   (");
                //list.Add("UpgradeS(");
                //list.Add("DMRService(");
                //list.Add("CityInitialization(");
                //list.Add("BookedService(");
                //list.Add("        (");
                //list.Add("");
                //list.Add("");
                //list.Add("");
                //list.Add("");
                //list.Add("");
                for (int i = 0; i < list.Count(); i++)
                {
                    if (!String.IsNullOrEmpty(list[i]) && log.Tag.StartsWith(list[i]))
                    {
                        return;
                    }
                }
            }
            if (searchData != null)
            {
                mReMainNum--;

                // 过滤字符串
                if (!String.IsNullOrEmpty(searchData.filterStr))
                {
                    String filteStr = searchData.filterStr.Trim();
                    if (filteStr.Contains(" | ")) //正则表达
                    {
                        String[] strs = filteStr.Split(new char[3] {
                            ' ', '|', ' '
                        }, StringSplitOptions.RemoveEmptyEntries);
                        bool isReturn = true;
                        for (int i = 0; i < strs.Length; i++)
                        {
                            if (log.contains(strs[i]))
                            {
                                isReturn = false;
                                break;
                            }
                        }
                        if (isReturn)
                        {
                            return;
                        }
                    }
                    else if (filteStr.Contains(" n ")) // aaaa n 3为 包含aaa接下来的3行显示
                    {                                  // 包含空格
                        String[] strs = filteStr.Split(new char[3] {
                            ' ', 'n', ' '
                        }, StringSplitOptions.RemoveEmptyEntries);
                        if (!log.contains(strs[0]))
                        {
                            if (mReMainNum < 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (strs.Length > 1)
                            {
                                mReMainNum = Int32.Parse(strs[strs.Length - 1]);
                            }
                        }
                    }
                    else if (!log.contains(searchData.filterStr))
                    {
                        return;
                    }
                }

                // 过滤debug level
                if (!String.IsNullOrEmpty(searchData.logLevel))
                {
                    switch (searchData.logLevel.ToCharArray()[0])
                    {
                    case 'E':
                        if (log.Type != 'E')
                        {
                            return;
                        }
                        break;

                    case 'W':
                        if (log.Type != 'E' && log.Type != 'W')
                        {
                            return;
                        }
                        break;

                    case 'I':
                        if (log.Type == 'V')
                        {
                            return;
                        }
                        break;
                    }
                }
            }
            LogAppendDelegate la = new LogAppendDelegate(LogAppend);

            txtLogcat.Invoke(la, log.GetBgColor(), log.CreationDate + " " + log.Tag + " " + log.Message);
        }