private static TextWriter OpenWriter(string filePath) { var directoryPath = Path.GetDirectoryName(filePath); Debug.Assert(directoryPath != null); var metadataPath = Path.Combine(directoryPath, "metadata"); var fileName = Path.GetFileName(filePath); // Create the output directory if it doesn't exist if (!System.IO.Directory.Exists(metadataPath)) { System.IO.Directory.CreateDirectory(metadataPath); } var outputPath = $"{directoryPath}/metadata/{fileName}.txt"; var stream = File.Open(outputPath, FileMode.Create); var writer = new StreamWriter(stream, new UTF8Encoding(false)); writer.Write("FILE: {0}\n", fileName); // Detect file type using (var fileTypeDetectStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var fileType = FileTypeDetector.DetectFileType(fileTypeDetectStream); writer.Write("TYPE: {0}\n\n", fileType.ToString().ToUpper()); } return(writer); }
private FileInfo TryGetFileInfo(string path) { Stream fileStream = new FileStream(path, FileMode.Open); FileType fileType = FileTypeDetector.DetectFileType(fileStream); switch (fileType) { case FileType.Jpeg: return(FromJpeg(fileStream)); case FileType.Gif: return(FromGif(fileStream)); case FileType.Tiff: return(FromTiff(fileStream)); case FileType.Bmp: return(FromBmp(fileStream)); case FileType.Png: return(FromPng(fileStream)); case FileType.Pcx: return(FromPcx(fileStream)); case FileType.Unknown: default: return(new FileInfo { Name = Path.GetFileName(path) }); } }
/// <summary> /// Converts binary to blob pointer /// </summary> /// <param name="category">The file category.</param> /// <param name="data">The data.</param> /// <param name="name">The name.</param> /// <returns>Blob Pointer</returns> public static string ConvertToFile(string category, string name, byte[] data) { if (data == null) { return(null); } using (Stream stream = new MemoryStream(data)) { // convert doc, xls -> docx, xlsx Stream streamToSave = new MemoryStream(); if (FileTypeDetector.IsDoc(data)) { Aspose.Words.Document doc = new Aspose.Words.Document(stream); doc.RemoveMacros(); doc.Save(streamToSave, Aspose.Words.SaveFormat.Docx); } else if (FileTypeDetector.IsXls(data)) { Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(stream); xls.RemoveMacro(); xls.Save(streamToSave, Aspose.Cells.SaveFormat.Xlsx); } else { streamToSave = stream; } // save to file streamToSave.Position = 0; string result = BlobStoreProvider.Instance.PutBlob(category, name, streamToSave); return(result); } }
/// <summary>Reads metadata from an <see cref="Stream"/>.</summary> /// <param name="stream">A stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.</param> /// <returns>A list of <see cref="Directory"/> instances containing the various types of metadata found within the file's data.</returns> /// <exception cref="ImageProcessingException">The file type is unknown, or processing errors occurred.</exception> /// <exception cref="System.IO.IOException"/> public static DirectoryList ReadMetadata(Stream stream) { var fileType = FileTypeDetector.DetectFileType(stream); var directories = new List <Directory>(); directories.AddRange(fileType switch { FileType.Arw => TiffMetadataReader.ReadMetadata(stream), FileType.Avi => AviMetadataReader.ReadMetadata(stream), FileType.Bmp => BmpMetadataReader.ReadMetadata(stream), FileType.Crx => QuickTimeMetadataReader.ReadMetadata(stream), FileType.Cr2 => TiffMetadataReader.ReadMetadata(stream), FileType.Eps => EpsMetadataReader.ReadMetadata(stream), FileType.Gif => GifMetadataReader.ReadMetadata(stream), FileType.Ico => IcoMetadataReader.ReadMetadata(stream), FileType.Jpeg => JpegMetadataReader.ReadMetadata(stream), FileType.Mp3 => Mp3MetadataReader.ReadMetadata(stream), FileType.Nef => TiffMetadataReader.ReadMetadata(stream), FileType.Netpbm => new Directory[] { NetpbmMetadataReader.ReadMetadata(stream) }, FileType.Orf => TiffMetadataReader.ReadMetadata(stream), FileType.Pcx => new Directory[] { PcxMetadataReader.ReadMetadata(stream) }, FileType.Png => PngMetadataReader.ReadMetadata(stream), FileType.Psd => PsdMetadataReader.ReadMetadata(stream), FileType.QuickTime => QuickTimeMetadataReader.ReadMetadata(stream), FileType.Raf => RafMetadataReader.ReadMetadata(stream), FileType.Rw2 => TiffMetadataReader.ReadMetadata(stream), FileType.Tga => TgaMetadataReader.ReadMetadata(stream), FileType.Tiff => TiffMetadataReader.ReadMetadata(stream), FileType.Wav => WavMetadataReader.ReadMetadata(stream), FileType.WebP => WebPMetadataReader.ReadMetadata(stream), FileType.Unknown => throw new ImageProcessingException("File format could not be determined"), _ => Enumerable.Empty <Directory>() });
public ActionResult EditWatch([Bind(Include = "WatchId, WatchCode, WatchDescription, Quantity, Price, " + "MovementID, ModelID, BandMaterial, CaseMaterial, " + "CaseRadius, Discount, Guarantee, PublishedBy, PublishedTime")] Watch watch, HttpPostedFileBase thumbnail) { if (ModelState.IsValid) { watch.WaterResistant = Request["water"] == "yes"; watch.LEDLight = Request["led"] == "yes"; watch.Alarm = Request["alarm"] == "yes"; watch.Status = Request["status"] == "yes"; watch.WatchCode = watch.WatchCode.ToUpper(); bool duplicateCode = watchService.IsDuplicatedWatchCode(watch.WatchCode, watch.WatchID); bool validImage = true; if (thumbnail != null) { validImage = FileTypeDetector.IsImageFile(thumbnail); ; } if (duplicateCode || !validImage) { var movement = movementService.GetMovementList(); var watchModel = watchModelService.GetModelsList(); ManageWatchDetailViewModel viewModel = watchService.PrepopulateEditValue(watch, movement, watchModel); if (duplicateCode) { viewModel.DuplicateErrorMessage = "Watch with code '" + watch.WatchCode + "' already existed. Please choose another one"; } if (!validImage) { viewModel.InvalidImageFileMessage = "Invalid Thumbnail. Upload file is not image"; } return(View("~/Views/Admin/admin_manage_watch_detail.cshtml", viewModel)); } String oldValue = watchService.SerializeOldValue(watch.WatchID); //thumbnail.InputStream.Position = 0; if (watchService.UpdateWatchInfo(watch, thumbnail)) { //save old value to modification table String userId = Session.GetCurrentUserInfo("Username"); if (modificationService.CreateNewModificationHistory(watch.WatchID, oldValue, userId)) { TempData["SHOW_MODAL"] = @"<script>$('#successModal').modal();</script>"; return(RedirectToAction("ViewWatch", "Admin")); } } return(Content("Unexpected Error")); //change to 404 } return(RedirectToAction("NotFound", "Home")); }
/// <summary> /// Loads and parses input file or archive to ePub in memory representation /// </summary> /// <param name="fileName">file to load</param> /// <returns></returns> public bool LoadAndCheckFB2Files(string fileName) { Logger.Log.InfoFormat("Starting to convert {0}", fileName); _fb2Files.Clear(); if (!File.Exists(fileName)) { Logger.Log.ErrorFormat("Unable to locate file {0} on disk.", fileName); return(false); } switch (FileTypeDetector.DetectFileType(fileName)) { case FileTypeDetector.FileTypesEnum.FileTypeZIP: Logger.Log.InfoFormat("Loading ZIP : {0}", fileName); var fb2ZipLoader = new FB2ZipFileLoader(); try { _fb2Files.AddRange(fb2ZipLoader.LoadFile(fileName, Settings.FB2ImportSettings)); } catch (Exception) { Logger.Log.ErrorFormat("Error loading ZIP {0} :", fileName); return(false); } break; case FileTypeDetector.FileTypesEnum.FileTypeFB2: Logger.Log.InfoFormat("Processing {0} ...", fileName); var fb2FileLoader = new FB2FileLoader(); try { _fb2Files.AddRange(fb2FileLoader.LoadFile(fileName, Settings.FB2ImportSettings)); } catch (Exception) { Logger.Log.ErrorFormat("Error loading FB2 {0} :", fileName); return(false); } break; case FileTypeDetector.FileTypesEnum.FileTypeRAR: Logger.Log.InfoFormat("Loading RAR : {0}", fileName); var fb2RarLoader = new FB2RarLoader(); try { _fb2Files.AddRange(fb2RarLoader.LoadFile(fileName, Settings.FB2ImportSettings)); } catch (Exception) { Logger.Log.ErrorFormat("Error loading RAR {0} :", fileName); return(false); } break; default: Logger.Log.InfoFormat("File {0} is of unsupported type", fileName); return(false); } return(true); }
/// <summary> /// Method for finding files that are supported by MetadataExtractor. /// </summary> /// <param name="filePath">Path to file to check.</param> /// <returns>Photo object of the <paramref name="filePath" />, or <see langword="null" /> if file type is not supported.</returns> private static Photo?FindPhoto(string filePath) { using var stream = File.OpenRead(filePath); if (FileTypeDetector.DetectFileType(stream) != FileType.Unknown) { return(new Photo(filePath)); } return(null); }
private static void TryVideo(IEnumerable <FileInfo> files) { var mp4 = files.FirstOrDefault(f => f.Extension == ".mp4"); using (var stream = mp4.OpenRead()) { var detectFileType = FileTypeDetector.DetectFileType(stream); var directories = ImageMetadataReader.ReadMetadata(stream); } }
public ActionResult AddWatch([Bind(Include = "WatchDescription, WatchCode, Quantity, Price, MovementID, ModelId, BandMaterial, CaseRadius, CaseMaterial, Discount, Guarantee")] Watch watch, HttpPostedFileBase thumbnail) { if (ModelState.IsValid) { watch.WaterResistant = Request["water"] == "yes"; watch.LEDLight = Request["led"] == "yes"; watch.Alarm = Request["alarm"] == "yes"; watch.WatchCode = watch.WatchCode.ToUpper(); bool duplicateCode = watchService.IsDuplicatedWatchCode(watch.WatchCode); bool validImage = FileTypeDetector.IsImageFile(thumbnail); //check if watch code is unique if (!validImage || duplicateCode) { //code đã tồn tại hoặc hình ảnh không hợp lệ //thông báo điền lại code //prefill các field var movement = movementService.GetMovementList(); var watchModel = watchModelService.GetModelsList(); var viewModel = watchService.PrepopulateInputValue(watch, movement, watchModel); if (duplicateCode) { viewModel.DuplicateErrorMessage = "Watch with code '" + watch.WatchCode + "' already existed"; } if (!validImage) { viewModel.InvalidImageFileMessage = "Invalid Thumbnail. Upload file is not an image"; } return(View("~/Views/Admin/admin_manage_watch_add.cshtml", viewModel)); } //lưu hình ảnh xuống máy string path = HostingEnvironment.MapPath("~/Content/img/ProductThumbnail/") + watch.WatchCode + DateTime.Now.ToBinary(); //thumbnail.InputStream.Position = 0; ImageProcessHelper.ResizedImage(thumbnail.InputStream, 360, 500, ResizeMode.Pad, ref path); watch.Thumbnail = path; watch.PublishedTime = DateTime.Now; watch.PublishedBy = Session.GetCurrentUserInfo("Username"); watch.Status = true; if (watchService.AddNewWatch(watch)) { TempData["SHOW_MODAL"] = @"<script>$('#successModal').modal();</script>"; return(RedirectToAction("AddWatch", "Admin")); } return(Content("Unexpected Error")); } return(RedirectToAction("NotFound", "Home")); }
public virtual Task <Size> GetImageSize(byte[]?bytes) { return(Task.Run(() => { if (bytes == null) { return Size.Empty; } try { using (var stream = new MemoryStream(bytes)) { var type = FileTypeDetector.DetectFileType(stream); stream.Seek(0, SeekOrigin.Begin); switch (type) { case FileType.Jpeg: var jpeg = JpegMetadataReader.ReadMetadata(stream); var jpegdir = jpeg.OfType <JpegDirectory>().FirstOrDefault(); return new Size(jpegdir.GetImageWidth(), jpegdir.GetImageHeight()); case FileType.Png: var png = PngMetadataReader.ReadMetadata(stream); var pngdir = png.OfType <PngDirectory>().FirstOrDefault(); return new Size(pngdir.GetInt32(PngDirectory.TagImageWidth), pngdir.GetInt32(PngDirectory.TagImageHeight)); case FileType.Gif: var gif = GifMetadataReader.ReadMetadata(stream); var gifdir = gif.OfType <GifHeaderDirectory>().FirstOrDefault(); return new Size(gifdir.GetInt32(GifHeaderDirectory.TagImageWidth), gifdir.GetInt32(GifHeaderDirectory.TagImageHeight)); case FileType.WebP: var webp = WebPMetadataReader.ReadMetadata(stream); var webpdir = webp.OfType <WebPDirectory>().FirstOrDefault(); return new Size(webpdir.GetInt32(WebPDirectory.TagImageWidth), webpdir.GetInt32(WebPDirectory.TagImageHeight)); case FileType.Bmp: var bmp = BmpMetadataReader.ReadMetadata(stream); var bmpdir = bmp.OfType <BmpHeaderDirectory>().FirstOrDefault(); return new Size(bmpdir.GetInt32(BmpHeaderDirectory.TagImageWidth), bmpdir.GetInt32(BmpHeaderDirectory.TagImageHeight)); default: return Size.Empty; } } } catch (Exception) { //Crashes.TrackError(e); // No need to track this } return Size.Empty; })); }
private static void FindUnknown(IEnumerable <FileInfo> files) { Parallel.ForEach( files, fileInfo => { using var stream = fileInfo.OpenRead(); if (FileTypeDetector.DetectFileType(stream) == FileType.Unknown) { Console.WriteLine($"Unknown File detected: {fileInfo.FullName}"); } }); }
static FileType GetFileType(string file) { try { using (var stream = File.OpenRead(file)) return(FileTypeDetector.DetectFileType(stream)); } catch (Exception ex) { Logger.Error(ex.Message); throw ex; } }
ReadMetadata([NotNull] Stream stream) { var fileType = FileTypeDetector.DetectFileType(stream); switch (fileType) { case FileType.Jpeg: return(JpegMetadataReader.ReadMetadata(stream)); case FileType.Tiff: case FileType.Arw: case FileType.Cr2: case FileType.Nef: case FileType.Orf: case FileType.Rw2: return(TiffMetadataReader.ReadMetadata(stream)); case FileType.Psd: return(PsdMetadataReader.ReadMetadata(stream)); case FileType.Png: return(PngMetadataReader.ReadMetadata(stream)); case FileType.Bmp: return(new Directory[] { BmpMetadataReader.ReadMetadata(stream) }); case FileType.Gif: return(GifMetadataReader.ReadMetadata(stream)); case FileType.Ico: return(IcoMetadataReader.ReadMetadata(stream)); case FileType.Pcx: return(new Directory[] { PcxMetadataReader.ReadMetadata(stream) }); case FileType.Riff: return(WebPMetadataReader.ReadMetadata(stream)); case FileType.Raf: return(RafMetadataReader.ReadMetadata(stream)); case FileType.QuickTime: return(QuickTimeMetadataReader.ReadMetadata(stream)); case FileType.Netpbm: return(new Directory[] { NetpbmMetadataReader.ReadMetadata(stream) }); } throw new ImageProcessingException("File format is not supported"); }
private static bool ContainsFileInPath(string path, FileTypeDetector fileDetector) { bool isDir = (File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory; if (!isDir) { return(fileDetector(path)); } else { foreach (string subPath in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)) { if (fileDetector(subPath)) { return(true); } } return(false); } }
public static MemoryStream SubstituteXmp([NotNull] Stream stream, XDocument xmp) { var fileType = FileTypeDetector.DetectFileType(stream); stream.Seek(0, SeekOrigin.Begin); byte[] original = new byte[stream.Length]; stream.Read(original, 0, (int)stream.Length); switch (fileType) { case FileType.Jpeg: return(JpegMetadataSubstitutor.SubstituteXmp(original, xmp)); //case FileType.Tiff: //case FileType.Arw: //case FileType.Cr2: //case FileType.Nef: //case FileType.Orf: //case FileType.Rw2: // return TiffMetadataReader.ReadMetadata(stream); //case FileType.Psd: // return PsdMetadataReader.ReadMetadata(stream); //case FileType.Png: // return PngMetadataReader.ReadMetadata(stream); //case FileType.Bmp: // return new[] { BmpMetadataReader.ReadMetadata(stream) }; //case FileType.Gif: // return new[] { GifMetadataReader.ReadMetadata(stream) }; //case FileType.Ico: // return IcoMetadataReader.ReadMetadata(stream); //case FileType.Pcx: // return new[] { PcxMetadataReader.ReadMetadata(stream) }; //case FileType.Riff: // return WebPMetadataReader.ReadMetadata(stream); //case FileType.Raf: // return RafMetadataReader.ReadMetadata(stream); //case FileType.QuickTime: // return QuicktimeMetadataReader.ReadMetadata(stream); } throw new ImageProcessingException("File format is not supported"); }
private static void TryImages(IEnumerable <FileInfo> files) { foreach (var fileInfo in files) { using var stream = fileInfo.OpenRead(); var detectedType = FileTypeDetector.DetectFileType(stream); if (detectedType == FileType.Unknown) { continue; } var directories = ImageMetadataReader.ReadMetadata(stream); var original = GetDateTimeOriginal(directories); // var allTags = directories.SelectMany(d => d.Tags.Select(t => $"{d.GetTagName(t.Type)}: {d.GetDescription(t.Type)}")); // var tagsFormatted = string.Join($"{Environment.NewLine}\t", allTags); Console.WriteLine($"Image: {fileInfo.FullName} / {original}:"); // Console.WriteLine(tagsFormatted); } }
MyExifData get_exif_data(string str_file) { MyExifData myExifData; myExifData.bSuccessExifData = false; myExifData.strFileExt = null; myExifData.bImage = false; myExifData.bVideo = false; myExifData.dtDate = new DateTime(); myExifData.bLoadFileFail = true; FileStream myStream = null; try { myStream = new FileStream(str_file, FileMode.Open); FileType fileType = FileTypeDetector.DetectFileType(myStream); myStream.Close(); IEnumerable <MetadataExtractor.Directory> directories; directories = ImageMetadataReader.ReadMetadata(str_file); DateTime dtTime; myExifData.bLoadFileFail = false; if (fileType == FileType.Jpeg || fileType == FileType.Png || fileType == FileType.Bmp) { var subIfdDirectory = directories.OfType <ExifSubIfdDirectory>().FirstOrDefault(); var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTimeOriginal); if (dateTime != null) { dtTime = ConvertDateExif(dateTime); myExifData.bSuccessExifData = true; myExifData.strFileExt = Path.GetExtension(str_file); myExifData.bImage = true; myExifData.bVideo = false; myExifData.dtDate = dtTime; } } else if (fileType == FileType.QuickTime)//동영상일 경우 { bool bUseVideoFile = UseVideoFile(str_file); if (bUseVideoFile) { var subIfdDirectory = directories.OfType <QuickTimeMovieHeaderDirectory>().FirstOrDefault(); var dateTime = subIfdDirectory?.GetDescription(QuickTimeMovieHeaderDirectory.TagCreated); if (dateTime != null) { dtTime = ConvertDateVideo(dateTime); myExifData.bSuccessExifData = true; myExifData.strFileExt = Path.GetExtension(str_file); myExifData.bImage = false; myExifData.bVideo = true; myExifData.dtDate = dtTime; } } } } catch (MetadataExtractor.ImageProcessingException e) { //WriteLog("Exception-" + str_file); string strMsg = string.Format("Exception-{0}", str_file); m_queueLogMsg.Enqueue(strMsg); return(myExifData); } catch (System.UnauthorizedAccessException e) { //WriteLog("Exception-" + str_file); if (myStream != null) { myStream.Close(); } string strMsg = string.Format("Exception-{0}", str_file); m_queueLogMsg.Enqueue(strMsg); return(myExifData); } catch (System.IO.IOException e) { //WriteLog("Exception-" + str_file); string strMsg = string.Format("Exception-{0}", str_file); m_queueLogMsg.Enqueue(strMsg); return(myExifData); } return(myExifData); }
/// <summary>Reads metadata from an <see cref="Stream"/>.</summary> /// <param name="stream">A stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.</param> /// <returns>A list of <see cref="Directory"/> instances containing the various types of metadata found within the file's data.</returns> /// <exception cref="ImageProcessingException">The file type is unknown, or processing errors occurred.</exception> /// <exception cref="System.IO.IOException"/> public static DirectoryList ReadMetadata(Stream stream) { var fileType = FileTypeDetector.DetectFileType(stream); var fileTypeDirectory = new FileTypeDirectory(fileType); switch (fileType) { case FileType.Jpeg: return(Append(JpegMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Tiff: case FileType.Arw: case FileType.Cr2: case FileType.Nef: case FileType.Orf: case FileType.Rw2: return(Append(TiffMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Psd: return(Append(PsdMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Png: return(Append(PngMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Bmp: return(Append(BmpMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Gif: return(Append(GifMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Ico: return(Append(IcoMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Pcx: return(new Directory[] { PcxMetadataReader.ReadMetadata(stream), fileTypeDirectory }); case FileType.WebP: return(Append(WebPMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Avi: return(Append(AviMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Wav: return(Append(WavMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Raf: return(Append(RafMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.QuickTime: case FileType.Crx: return(Append(QuickTimeMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Netpbm: return(new Directory[] { NetpbmMetadataReader.ReadMetadata(stream), fileTypeDirectory }); case FileType.Unknown: throw new ImageProcessingException("File format could not be determined"); case FileType.Riff: case FileType.Crw: default: throw new ImageProcessingException("File format is not supported"); }
public static Image FromFile(string path) { var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); var image = new Image(); try { var format = FileTypeDetector.DetectFileType(stream); stream.Seek(0, SeekOrigin.Begin); image.Metadata = new Metadata(path); stream.Seek(0, SeekOrigin.Begin); byte[] data; switch (format) { case FileType.Bmp: data = new byte[stream.Length]; stream.Read(data, 0, data.Length); image.source = BmpDecoder.FromBytes(data); break; case FileType.WebP: data = new byte[stream.Length]; stream.Read(data, 0, data.Length); image.source = WebpDecoder.FromBytes(data); break; case FileType.QuickTime: var qtFt = image.Metadata.Directories .OfType <QuickTimeFileTypeDirectory>() .FirstOrDefault() ?.GetDescription(1); if (qtFt != "avif" && qtFt != "avis" && qtFt != "av01") { return(null); } data = new byte[stream.Length]; stream.Read(data, 0, data.Length); image.source = AvifDecoder.FromBytes(data); break; case FileType.Heif: data = new byte[stream.Length]; stream.Read(data, 0, data.Length); image.source = HeifDecoder.FromBytes(data); break; case FileType.Jpeg: case FileType.Tiff: case FileType.Png: case FileType.Gif: case FileType.Ico: image.source = WpfDecoder.FromStream(stream); break; case FileType.Unknown: if (stream.Length < 4) { return(null); } var header = new byte[4]; stream.Read(header, 0, 4); if (FlifDecoder.MagicDetect(header) == DetectResult.Yes) { data = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(data, 0, data.Length); image.source = FlifDecoder.FromBytes(data); } break; default: return(null); } return(image.source != null ? image : null); } catch (Exception e) { return(null); } finally { stream.Dispose(); } }
private static bool ContainsFileInPath(string path, FileTypeDetector fileDetector) { bool isDir = (File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory; if (!isDir) { return fileDetector(path); } else { foreach (string subPath in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)) { if (fileDetector(subPath)) return true; } return false; } }