3 using System.Runtime.InteropServices;
5 using NaGet.InteropServices;
7 namespace NaGet.SubCommands.SubTask
9 public class VirusScanSubTask : NaGetSubTask
11 private string targetFilePath = null;
13 private string targetUrl = null;
15 private DownloadScannerService scanner = null;
17 public VirusScanSubTask(DownloadScannerService scanner)
18 : this(scanner, null, null)
22 public VirusScanSubTask(DownloadScannerService scanner, string targetFilePath, string targetUrl)
24 this.scanner = scanner;
25 this.targetFilePath = targetFilePath;
26 this.targetUrl = targetUrl;
29 public string TargetFilePath {
30 get { return targetFilePath; }
31 set { targetFilePath = value; }
34 public string TargetUrl {
35 get { return targetUrl; }
36 set { targetUrl = value; }
39 private void runScanFile()
41 DownloadScannerResult result;
43 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, -1);
44 result = scanner.Scan(targetFilePath, targetUrl);
45 } catch (COMException ex) {
46 result = DownloadScannerResult.ScannerNotFound;
47 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0} (E{1})", ex.Message, ex.ErrorCode), 0);
48 } catch (FileNotFoundException) {
49 result = DownloadScannerResult.ErrorNotFound;
51 result = DownloadScannerResult.ScannerNotFound;
56 case DownloadScannerResult.OK:
57 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 100);
59 case DownloadScannerResult.ScannerNotFound:
60 RaiseTaskSetEvent(TaskEventType.INFO, "ダウンロードしたファイルへのウイルススキャンはされなかったか、スキャン結果は無視されました", 0);
62 case DownloadScannerResult.InfectedAndCleaned:
63 e = new ApplicationException("インストーラーファイルからウイルス感染が検出されたため、削除されました。");
65 case DownloadScannerResult.InfectedButNotCleaned:
66 e = new ApplicationException("インストーラーファイルからウイルス感染が検出されました。");
68 case DownloadScannerResult.ErrorNotFound:
69 e = new FileNotFoundException(string.Empty);
78 public override void Run()
81 RaiseTaskSetEvent(TaskEventType.STARTED, string.Format("ウイルススキャン: {0}", targetFilePath), 0);
84 if (! NaGet.Env.EnableScanInstallerFile) {
85 RaiseTaskSetEvent(TaskEventType.INFO, "ウイルススキャンを行わない設定のため、ダウンロードしたファイルはウイルススキャンされませんでした", 0);
86 } else if (!scanner.HasScanner) {
87 RaiseTaskSetEvent(TaskEventType.INFO, "ダウンロードしたファイルはウイルススキャンされませんでした(ウイルススキャンソフトが検出できませんでした)", 0);
88 } else if (! File.Exists(targetFilePath)) {
89 RaiseTaskSetEvent(TaskEventType.ERROR, "ダウンロードしたファイルは存在しませんでした(ウイルススキャンソフトが自動的に即座に削除した可能性があります)", 0);
94 RaiseTaskSetEvent(TaskEventType.COMPLETED, string.Format("ウイルススキャン: {0}", targetFilePath), 0);