PPSXDetector.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.IO.Compression;
  5. using System.Reflection;
  6. using Masuit.Tools.Mime;
  7. namespace Masuit.Tools.Files.FileDetector.Detectors;
  8. [FormatCategory(FormatCategory.Document)]
  9. internal class PPSXDetector : AbstractZipDetailDetector
  10. {
  11. public override IEnumerable<string> Files
  12. {
  13. get
  14. {
  15. yield return "[Content_Types].xml";
  16. yield return "_rels/.rels";
  17. yield return "ppt/_rels/presentation.xml.rels";
  18. }
  19. }
  20. public override string Precondition => "zip";
  21. public override string Extension => "ppsx";
  22. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  23. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  24. protected override bool IsValid(string filename, ZipArchiveEntry entry)
  25. {
  26. if (filename == "[Content_Types].xml")
  27. {
  28. using StreamReader reader = new StreamReader(entry.Open());
  29. var text = reader.ReadToEnd();
  30. return text.IndexOf("<Override PartName=\"/ppt/presentation.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml\"/>") >= 0;
  31. }
  32. return base.IsValid(filename, entry);
  33. }
  34. public override string ToString() => "Microsoft PowerPoint Open XML Document for Slideshow(PPSX) Detector";
  35. }