public void EnumerateFiles(List <DataSource> dataSources) { _popup.Show(); _popup.Text = "Starting the parse"; var dic = new Dictionary <string, Func <string, List <FileReadObject> > >(); //SevenZipExtractor.SetLibraryPath(Application.ExecutablePath + @"\7z.dll"); int i = 1; foreach (var source in dataSources) { PacketCounter = 0; PacketTotal = source.Packets; string pre = i + "/" + dataSources.Count + " "; _popup.Text = pre + "Reading from " + source.FileInfo.Name; if (source.SourceType == SourceType.PCAP) { pcapReader.Read(source.FileInfo.FullName); } else if (source.SourceType == SourceType.PCAPNG) { pcapngReader.Read(source.FileInfo.FullName); } else if (source.SourceType == SourceType.Zip) { if (SevenZipArchive.IsSevenZipFile(source.FileInfo.FullName)) { using (SevenZipArchive sevenZipArchive = SevenZipArchive.Open(source.FileInfo.FullName)) { using (var reader = sevenZipArchive.ExtractAllEntries()) { ZipReader(reader, source); } } GC.Collect(); } else { try { using (var filestream = File.OpenRead(source.FileInfo.FullName)) { using (var reader = ReaderFactory.Open(filestream)) { ZipReader(reader, source); } } } catch (InvalidOperationException ex) { } GC.Collect(); } } } _popup.Close(); }
private void InspectFiles(List <string> fileNames) { var threads = new List <Thread>(); foreach (var fileName in fileNames) { var finfo = new FileInfo(fileName); if (pcapReader.CanRead(fileName)) { var reader = new PCAPReader(); var fileReadObjects = reader.Read(fileName); var first = (PCAPBlock)fileReadObjects.First().ReadObject; var last = (PCAPBlock)fileReadObjects.Last().ReadObject; var dsource = new DataSource { FileInfo = finfo, StartTime = first.DateTime, EndTime = last.DateTime, SourceType = SourceType.PCAP, Packets = fileReadObjects.Count }; UpdateList(dsource); continue; } else if (pcapngReader.CanRead(fileName)) { var reader = new PCAPNGReader(); var fileReadObjects = reader.Read(fileName); var first = (PCAPNGBlock)fileReadObjects.First().ReadObject; var last = (PCAPNGBlock)fileReadObjects.Last().ReadObject; var dsource = new DataSource { FileInfo = finfo, StartTime = first.Timestamp, EndTime = last.Timestamp, SourceType = SourceType.PCAPNG, Packets = fileReadObjects.Count }; UpdateList(dsource); continue; } if (SevenZipArchive.IsSevenZipFile(fileName)) { // because of lousy performance when operating on 7zip, we launch a new thread instead of using tasks var thread = new Thread(() => DoSevenZip(finfo)); thread.Start(); threads.Add(thread); continue; } // zip performance is much better and we will not thread DoZip(finfo); } UpdateList("Waiting for all threads to finish"); foreach (Thread thread in threads) { thread.Join(); } UpdateList("All threads finished"); }