public void AppendDirectory(string name, ArchivedAttributes? attributes, DateTime? creationDate, DateTime? lastWriteDate, DateTime? lastAccessDate)
        {
            CheckName(ref name);
            CheckAttributes(ref attributes, false);
            CheckDate(ref creationDate);
            CheckDate(ref lastWriteDate);
            CheckDate(ref lastAccessDate);

            // TODO: check attributes and reject invalid ones (replicate the check when writing the attributes so other metadata providers get the check too)

            Utilities.NeedsReview(); // TODO: which dates are recorded for a directory?

            mEntries.Add(new Entry {
                Name = name,
                IsDirectory = true,
                Attributes = attributes,
            });
        }
        private void CheckAttributes(ref ArchivedAttributes? attr, bool isFile)
        {
            if (attr.HasValue)
            {
                if (isFile)
                {
                    if ((attr.Value & ArchivedAttributesExtensions.DirectoryAttribute) != 0)
                        throw new InvalidOperationException("Directory attribute cannot be set on a file.");
                }
                else
                {
                    // Automatically add the directory attribute for directories.
                    attr = attr.Value | ArchivedAttributesExtensions.DirectoryAttribute;
                }

                if ((attr & ArchivedAttributesExtensions.InvalidAttributes) != 0)
                    throw new InvalidOperationException("Invalid attributes have been set.");

                if ((attr & ArchivedAttributesExtensions.ForbiddenAttributes) != 0)
                    throw new InvalidOperationException("Some attributes are set which should not be present in a 7z archive.");

                attr = attr.Value & ~ArchivedAttributesExtensions.StrippedAttributes;
            }
        }
        public void AppendFile(string name, long length, Checksum? checksum, ArchivedAttributes? attributes, DateTime? creationDate, DateTime? lastWriteDate, DateTime? lastAccessDate)
        {
            if (length < 0)
                throw new ArgumentOutOfRangeException(nameof(length));

            CheckName(ref name);
            CheckAttributes(ref attributes, true);
            CheckDate(ref creationDate);
            CheckDate(ref lastWriteDate);
            CheckDate(ref lastAccessDate);

            // TODO: replicate the checks when the metadata is queried from the provider (in particular don't forget to check that timestamps are UTC)

            mEntries.Add(new Entry {
                Name = name,
                HasStream = true,
                IsDirectory = false,
                IsDeleted = false,
                Length = length,
                Checksum = checksum,
                Attributes = attributes,
                CreationDate = creationDate,
                LastWriteDate = lastWriteDate,
                LastAccessDate = lastAccessDate,
            });
        }
Exemple #4
0
 public static FileAttributes ToFileAttributes(this ArchivedAttributes attributes)
 {
     return((FileAttributes)attributes);
 }