public static void scanFile(string fnPath, ScannedFileItem _scannedFile) { try { if (File.Exists(fnPath)) { _scanW.WorkerReportsProgress = true; _scanW.WorkerSupportsCancellation = true; _scanW.RunWorkerAsync(); _scanW.DoWork += (o, e) => { var virusTotal = new VirusTotal(apiKey); virusTotal.UseTLS = true; var fInfo = new FileInfo(fnPath); _report = new FileReport(); var fReport = virusTotal.GetFileReport(fInfo); _report = fReport; bool hasFileBeenScannedBefore = fReport.ResponseCode == ReportResponseCode.Present; if (!hasFileBeenScannedBefore) { var fResult = virusTotal.ScanFile(fInfo); } }; _scanW.RunWorkerCompleted += (m, e) => { if (_report != null) { var scanWin = new ScanResultWin(); scanWin.init(_report, _scannedFile); scanWin.ShowDialog(); } }; } } catch (Exception ex) { GeneralSettings.LogException(ex); } }
private void cnvScanButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { try { if (File.Exists(_fileName)) { new Thread(() => { App.Current.Dispatcher.Invoke(() => { if (AppUpdate.checkForInternetConnection()) { Close(); var scannedFile = new ScannedFileItem(_fileName, _name, _creationDate, _fileSize); if(_scanStartedEventHandler != null) { _scanStartedEventHandler(_fileName, _name); } Scan.scanFile(_fileName, scannedFile); } else { cnvScanButton.IsEnabled = false; } }); }).Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void sysWatcher_Created(object sender, FileSystemEventArgs e) { if (!File.Exists(e.FullPath)) { return; } if (!_extensionList.Any(s => e.FullPath.Contains(s))) { return; } if (_ignoreList.Any(s => e.FullPath.Contains(s))) { return; } try { App.Current.Dispatcher.Invoke(delegate { if (File.Exists(e.FullPath)) { if (_warningSound) { GeneralSettings.PlaySound(); } var fileInfo = new FileInfo(e.FullPath); var wFunc = new WarningItem(e.FullPath, e.Name, AppSettings.SizeSuffix(fileInfo.Length), fileInfo.CreationTime.ToString("g"), fileInfo.Extension, "Datei", new Uri("/Images/inWatch.File.png", UriKind.RelativeOrAbsolute)); AddToWarningList(Path.GetDirectoryName(e.FullPath), DateTime.Now.ToString("g"), fileInfo.Extension, e.FullPath, fileInfo.Name, AppSettings.SizeSuffix(fileInfo.Length), new Uri("/Images/inWatch.File.png", UriKind.RelativeOrAbsolute)); lblActiveWarningsCount.Content = lstWarning.Items.Count; if (_warningPopUp && !_autoScan) { var wWin = new WarningWin(); wWin.init(wFunc); wWin.ShowDialog(); } else if(!_warningPopUp && _autoScan) { var scannedFile = new ScannedFileItem(e.FullPath, e.Name, fileInfo.CreationTime.ToString("g"), AppSettings.SizeSuffix(fileInfo.Length)); Scan.scanFile(e.FullPath, scannedFile); } else if (_warningPopUp) { var wWin = new WarningWin(); wWin.init(wFunc); wWin.ShowDialog(); } } }); } catch (Exception ex) { MessageBox.Show(ex.Message, "syswatcher_Created()"); } }
private void lstContextScan_Click(object sender, RoutedEventArgs e) { if (_warningList.Count != 0) { var fileName = _warningList[lstWarning.SelectedIndex].FullPath; var scanStatus = _warningList[lstWarning.SelectedIndex].StatusScan; if (scanStatus == "Gescannt: ") { var result = MessageBox.Show("Diese Datei wurde schon gescannt! Wollen Sie die Datei nochmal scannen?", "Information", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { if (File.Exists(fileName)) { var scannedFile = new ScannedFileItem(fileName, _warningList[lstWarning.SelectedIndex].FileName, _warningList[lstWarning.SelectedIndex].CreationDate, _warningList[lstWarning.SelectedIndex].FileSize); if (scannedFile != null) { new Thread(() => { Scan.scanFile(fileName, scannedFile); }).Start(); } else { MessageBox.Show("NULL lstContextScan_Click()"); } } } else { } } if (!string.IsNullOrEmpty(fileName)) { if (File.Exists(fileName)) { var scannedFile = new ScannedFileItem(fileName, _warningList[lstWarning.SelectedIndex].FileName, _warningList[lstWarning.SelectedIndex].CreationDate, _warningList[lstWarning.SelectedIndex].FileSize); if (scannedFile != null) { new Thread(() => { Scan.scanFile(fileName, scannedFile); }).Start(); } else { MessageBox.Show("NULL lstContextScan_Click()"); } } } } }
public void init(FileReport _scanResult, ScannedFileItem _scannedFile) { try { if (_scannedFile != null) { lblFullPath.Content = _scannedFile.FullPath; _fullPath = _scannedFile.FullPath; lblFileName.Content = _scannedFile.FileName; lblFileDate.Content = _scannedFile.Date; lblFileSize.Content = _scannedFile.FileSize; } if (_scanResult.ResponseCode == ReportResponseCode.Present) { foreach (ScanEngine scan in _scanResult.Scans) { if (scan.Detected == true) { howMany++; _scanResultItems.Add(new ScanResultItems { AvName = scan.Name, AvResult = new Uri("/Images/inWatch.avNOT.png", UriKind.RelativeOrAbsolute), AvStatus = scan.Result }); } else { _scanResultItems.Add(new ScanResultItems { AvName = scan.Name, AvResult = new Uri("/Images/inWatch.avOK.png", UriKind.RelativeOrAbsolute), AvStatus = "OK" }); } } lstScanResults.ItemsSource = _scanResultItems.OrderBy(item => item.AvName).ToList(); if (howMany == 0) { Title = "Es wurden keine Bedrohungen gefunden!"; cmdRemove.Visibility = Visibility.Collapsed; cmdIgnore.Visibility = Visibility.Collapsed; } else { Title = "Bedrohung gefunden!"; cmdRemove.Visibility = Visibility.Visible; cmdIgnore.Visibility = Visibility.Visible; } if (_scanStoppedEventHandler != null) { _scanStoppedEventHandler(_scannedFile.FullPath, howMany); } } } catch (Exception ex) { GeneralSettings.LogException(ex); } }