IEntry.Extensions.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 
  2. #if !NO_FILE
  3. using System.IO;
  4. using SharpCompress.Readers;
  5. namespace SharpCompress.Common
  6. {
  7. internal static class EntryExtensions
  8. {
  9. internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName,
  10. ExtractionOptions options)
  11. {
  12. if (options.PreserveFileTime || options.PreserveAttributes)
  13. {
  14. FileInfo nf = new FileInfo(destinationFileName);
  15. if (!nf.Exists)
  16. {
  17. return;
  18. }
  19. // update file time to original packed time
  20. if (options.PreserveFileTime)
  21. {
  22. if (entry.CreatedTime.HasValue)
  23. {
  24. nf.CreationTime = entry.CreatedTime.Value;
  25. }
  26. if (entry.LastModifiedTime.HasValue)
  27. {
  28. nf.LastWriteTime = entry.LastModifiedTime.Value;
  29. }
  30. if (entry.LastAccessedTime.HasValue)
  31. {
  32. nf.LastAccessTime = entry.LastAccessedTime.Value;
  33. }
  34. }
  35. if (options.PreserveAttributes)
  36. {
  37. if (entry.Attrib.HasValue)
  38. {
  39. nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. #endif