public void CheckExtension() { if (!File.Exists(OriginalFilename)) { Extension = null; return; } try { using Stream stream = new FileStream(OriginalFilename, FileMode.Open, FileAccess.Read, FileShare.Read); if (stream.Length == 0) { Extension = null; return; } var detector = DetectorService.DetectDetector(stream); if (detector == null || !(ProcessingFormat.IsSupportContainerFormat(detector.Extension) || ProcessingFormat.IsSupportImageFormat(detector.Extension))) { Extension = null; } else { Extension = detector.Extension; } } catch { Extension = null; } }
public bool DoCommand(FileInfo file) { if (!File.Exists(file.OriginalFullPath)) return false; using Stream stream = File.OpenRead(file.OriginalFullPath); var detector = DetectorService.DetectDetector(stream); if (detector == null) return false; file.ChangedFilename = $"{file.ChangedFilename}.{detector.Extension}"; return true; }
public bool Process(FileInfo file) { if (!File.Exists(file.OriginalFullPath)) { return(false); } using (Stream stream = File.OpenRead(file.OriginalFullPath)) { var detector = DetectorService.DetectDetector(stream); if (detector == null) { return(false); } file.ChangedFilename = $"{file.ChangedFilename}.{detector.Extension}"; } return(true); }