private void UpdateVirInfoListView(VirInfo content)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         if (content.FinishFlag)
         {
             ButtonStart.Content  = "开始";
             TbCurrentTarget.Text = "扫描完毕";
             try
             {
                 _watcher.EnableRaisingEvents = false;
                 _watcher.Dispose();
             }
             catch
             {
                 //ignored
             }
             ProcessMetro.Visibility = Visibility.Hidden;
             MetroProcessbar.Stop();
             ScanProcessBar.Visibility  = Visibility.Hidden;
             FileNameTextBox.Visibility = Visibility.Visible;
             SpeedLabel.Content         = (long)(_lastcount / (Math.Abs((DateTime.Now - _startDateTime).TotalSeconds) < 0.5 ? 1 : (DateTime.Now - _startDateTime).TotalSeconds)) + " 个/s";
             EnableAllFuncBtn();
             _isfinished = true;
         }
         else
         {
             if (_lastcount++ == 0)
             {
                 _watcher.EnableRaisingEvents = false;
                 _watcher.Dispose();
                 _startDateTime          = DateTime.Now;
                 ProcessMetro.Visibility = Visibility.Hidden;
                 MetroProcessbar.Stop();
                 ScanProcessBar.Visibility = Visibility.Visible;
                 ScanRunning();
             }
             FileCountLabel.Content = _lastcount.ToString();
             if (string.IsNullOrEmpty(content.VirName) || string.IsNullOrEmpty(content.DetectEngine))
             {
                 TbCurrentTarget.Text = content.FileName;
             }
             else
             {
                 VirInfoList.Add(new VirInfo(content.FileName, content.VirName, content.DetectEngine, content.FinishFlag, content.IsSelected, "尚未处理"));
                 ThreatLabel.Content  = ++_threat;
                 TbCurrentTarget.Text = content.FileName;
             }
         }
     }));
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonStart.Content == "开始")
            {
                if (!File.Exists("ramecl.exe"))
                {
                    MessageBox.Show("未找到扫描引擎! 请将引擎安装至当前目录", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                _lastcount    = 0;
                _threat       = 0;
                _isfinished   = false;
                _scanInstance = new Scan();
                _fileCountTot = 0;
                string paras = null;
                VirInfoList.Clear();
                DisableAllFuncBtn();
                TbCurrentTarget.Text    = TbCurrentTarget.Text = @"正在初始化引擎并更新病毒库, 可能需要较长时间...
-->检查病毒库更新";
                ProcessMetro.Visibility = Visibility.Visible;
                MetroProcessbar.Start();
                FileNameTextBox.Visibility = Visibility.Hidden;
                FileCountLabel.Content     = "0";
                TimeLabel.Content          = "00:00:00";
                ThreatLabel.Content        = "0";
                SpeedLabel.Content         = "0 个/s";
                if (!(EngineCloud.IsChecked ?? false))
                {
                    paras += " -!cloud";
                }
                if (!(EngineRdmPlus.IsChecked ?? false))
                {
                    paras += " -!rdm+";
                }
                if (EngineWorkers.IsChecked ?? false)
                {
                    var workers = ((int)SliderWorkers.Value).ToString();
                    paras += " -workers=";
                    paras += workers;
                }
                if (LogOutput.IsChecked ?? false)
                {
                    paras += $" \"-log={Environment.CurrentDirectory}\\ScanLog_{DateTime.Now:yyMMddHHmmss}.log\"";
                }
                if (_scanInstance.Start(FileNameTextBox.Text, paras, UpdateVirInfoListView, UpdateResUsageInfoView))
                {
                    ButtonStart.Content = "停止";
                    EngineUpdateWatcher();
                    FileProcessUpdate(FileNameTextBox.Text);
                }
                else
                {
                    MessageBox.Show("指定扫描对象不存在", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    TbCurrentTarget.Text    = "";
                    ProcessMetro.Visibility = Visibility.Hidden;
                    MetroProcessbar.Stop();
                    FileNameTextBox.Visibility = Visibility.Visible;
                }
            }
            else
            {
                _scanInstance.StopScan();
                ButtonStart.Content = "开始";
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonStart.Content == "开始")
            {
                if (!File.Exists("conscan.exe"))
                {
                    MessageBox.Show("未找到扫描引擎! 请将引擎安装至当前目录", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                _lastcount    = 0;
                _threat       = 0;
                _isfinished   = false;
                _scanInstance = new Scan();
                _fileCountTot = 0;
                string paras = null;
                VirInfoList.Clear();
                DisableAllFuncBtn();
                TbCurrentTarget.Text    = TbCurrentTarget.Text = @"正在初始化引擎并更新病毒库, 可能需要较长时间...
-->检查病毒库更新";
                ProcessMetro.Visibility = Visibility.Visible;
                MetroProcessbar.Start();
                FileNameTextBox.Visibility = Visibility.Hidden;
                FileCountLabel.Content     = "0";
                TimeLabel.Content          = "00:00:00";
                ThreatLabel.Content        = "0";
                SpeedLabel.Content         = "0 个/s";
                if (!(EngineCloud.IsChecked ?? false))
                {
                    paras += " -cloud=0";
                }
                else
                {
                    paras += " -cloud=1";
                }
                if (!(EngineAsg.IsChecked ?? false))
                {
                    paras += " -enable-asg=0";
                }
                else
                {
                    paras += " -enable-asg=1";
                }
                if (!(EngineTfe.IsChecked ?? false))
                {
                    paras += " -enable-tfe=0";
                }
                else
                {
                    paras += " -enable-tfe=1";
                }
                if (Treat.IsChecked ?? false)
                {
                    paras += " -kill";
                }
                if (NonCompound.IsChecked ?? false)
                {
                    paras += " -!scan-compound";
                }
                if (Thershold.IsChecked ?? false)
                {
                    paras += $" -rdm.thershold={(int)(ThersholdValue.Value / 10)}";
                }
                if (!(CloudCheck.IsChecked ?? false))
                {
                    paras += " -cav.md5=0 -cav.sha1=0";
                }
                if (Filter.IsChecked ?? false)
                {
                    paras += " \"-regex=#" + FilterValue.Text + "\"";
                }
                if (EngineWorkers.IsChecked ?? false)
                {
                    paras += $" -workers={(int)SliderWorkers.Value}";
                }
                if (LogOutput.IsChecked ?? false)
                {
                    paras += $" \"-log={Environment.CurrentDirectory}\\ScanLog_{DateTime.Now:yyMMddHHmmss}.log\"";
                }
                if (_scanInstance.Start(FileNameTextBox.Text, paras, UpdateVirInfoListView, UpdateResUsageInfoView))
                {
                    ButtonStart.Content = "停止";
                    EngineUpdateWatcher();
                    FileProcessUpdate(FileNameTextBox.Text);
                }
                else
                {
                    MessageBox.Show("指定扫描对象不存在", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                    TbCurrentTarget.Text    = "";
                    ProcessMetro.Visibility = Visibility.Hidden;
                    MetroProcessbar.Stop();
                    FileNameTextBox.Visibility = Visibility.Visible;
                }
            }
            else
            {
                _scanInstance.StopScan();
                ButtonStart.Content = "开始";
            }
        }