PSDText.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. namespace PSDText
  5. {
  6. public class PSDText
  7. {
  8. private readonly string _xmlData;
  9. private string Readxmpmeta(string path)
  10. {
  11. var sb = new StringBuilder(1000);
  12. using (var sr = new StreamReader(path))
  13. {
  14. sr.ReadLine(); //skip first line
  15. var line = sr.ReadLine();
  16. if (string.IsNullOrWhiteSpace(line))
  17. return string.Empty;
  18. var read = line.StartsWith("<x:xmpmeta");
  19. while (read)
  20. {
  21. if (line.StartsWith("</x:xmpmeta>"))
  22. read = false;
  23. sb.Append(line);
  24. line = sr.ReadLine();
  25. if (string.IsNullOrWhiteSpace(line))
  26. return sb.ToString();
  27. }
  28. }
  29. return sb.ToString();
  30. }
  31. public PSDText(string path)
  32. {
  33. if (!File.Exists(path))
  34. throw new Exception($"File {path} doesn't exist!");
  35. _xmlData = Readxmpmeta(path);
  36. }
  37. }
  38. }