public static void OpenZipZip(ZipEntry zipEntry, DateValue.Operation oper, string path) { using (ZipFile zip = ZipFile.Read(zipEntry.ExtractToMemoryStream())) { foreach (var entry in zip.Entries) { using (var reader = entry.ExtractToMemoryStream()) { byte flag = GetTypeFile(reader); switch (flag) { case 0: //other file break; case 1: //exe DateValue.countFile++; Console.WriteLine(entry.FileName); reader.Position = 0; ScanFile.AddTask(new ScanObject(reader, path + '\\' + entry.FileName, oper, DateValue.Scan.SearchFile)); break; case 2: //zip OpenZipZip(entry, oper, path + '\\' + entry.FileName); break; } } } } }
public static void SearchFileDirectory(Object state) { object[] array = state as object[]; var path = Convert.ToString(array[0]); DateValue.Operation oper = (DateValue.Operation)(int) array[1]; if (File.Exists(path)) { if (GetTypeFile(path) == 1) { DateValue.countFile = 1; DateValue.isSearchFile = false; ScanFile.AddTask(new ScanObject(path, oper, DateValue.Scan.SearchFile)); } else { DateValue.isScaning = false; } return; } int count = DateValue.countFile; string[] dirs = Directory.GetDirectories(path); foreach (string pathDir in dirs) { if (!DateValue.isScaning) { return; } SearchFileDirectory(new object[] { pathDir, oper }); } string[] files = Directory.GetFiles(path); foreach (string pathFile in files) { if (!DateValue.isScaning) { return; } byte flag = GetTypeFile(pathFile); switch (flag) { case 0: //other file break; case 1: //exe DateValue.countFile++; Console.WriteLine(pathFile); ScanFile.AddTask(new ScanObject(pathFile, oper, DateValue.Scan.SearchFile)); break; case 2: //zip Console.WriteLine(pathFile); OpenZip(pathFile, oper); break; } } if (count == 0) { DateValue.isSearchFile = false; if (DateValue.countCheckFile == DateValue.countFile) { DateValue.isScaning = false; DBManager.AddReport(DateValue.idReport, DateValue.dateStart, DateTime.Now.ToString("MM.dd.yyyy H:mm"), DateValue.path, DateValue.countFile, DateValue.countVirusFile); } } }