Stream GetStream(string archiveFileName, Extractors.ExtractFileInfo fileInfo) { try { return(fileInfo.GetStream()); } catch { var extractor = Extractors.ExtractorFactory.GetFileExtractor(archiveFileName); var task = extractor.ExtractFile(archiveFileName, fileInfo.FileName); task.Wait(); //if (task.Exception != null) // throw task.Exception; return(task.Result); } }
Models.File ExtractFileInfo(GalleryContext db, Pack pack, Extractors.ExtractFileInfo fileInfo, Func <Stream> getStream) { var fileName = Scanner.NormalizedPath(fileInfo.FileName).TrimStart('\\'); var file = pack.GetFileByName(fileName); var name = CanonicalName(fileName.Replace("\\", "/")); while (pack.Files.Any(r => r.Name == name && !ReferenceEquals(r, file))) { name += "_"; } file.Name = name; file.Order = fileInfo.Order++; //updateStatus(string.Format("Processing file '{0}'", file.FileName)); var format = FileFormat.FindByExtension(Path.GetExtension(file.NativeFileName)); if (format != null) { file.Format = format.Name; file.Type = format.Type.Name; } else { file.Format = "ansi"; file.Type = FileType.Character.Name; } if (file.Type == FileType.Character.Name) { if (false && file.Content == null) { using (var stream = getStream()) { using (var outStream = new MemoryStream()) { var parameters = new PabloDraw.ConvertParameters { InputStream = stream, InputFormat = file.Format, OutputFormat = "ascii", OutputStream = outStream }; Global.PabloEngine.Convert(parameters); outStream.Position = 0; using (var reader = new StreamReader(outStream, Encoding.GetEncoding(437))) { var content = file.Content ?? (file.Content = new FileContent { File = file }); content.Text = reader.ReadToEnd().Replace((char)0, ' '); } } } } } else if (file.Content != null) { file.Content = null; } return(file); }