// Initializes, attaches it to archive
        internal ZipArchiveEntry(ZipArchiveFast archive, ZipCentralDirectoryFileHeader cd)
        {
            Archive = archive;

            _diskNumberStart       = cd.DiskNumberStart;
            _generalPurposeBitFlag = (BitFlagValues)cd.GeneralPurposeBitFlag;
            _compressionMethod     = (CompressionMethodValues)cd.CompressionMethod;

            // Leave this as a uint and let the caller convert it if it wants (perf optimization)
            LastWriteTime = cd.LastModified;

            CompressedLength     = cd.CompressedSize;
            Length               = cd.UncompressedSize;
            _offsetOfLocalHeader = cd.RelativeOffsetOfLocalHeader;

            // we don't know this yet: should be _offsetOfLocalHeader + 30 + _storedEntryNameBytes.Length + extrafieldlength
            // but entryname/extra length could be different in LH
            _storedOffsetOfCompressedData = null;

            // Sacrifice a slight amount of time for safety. Zips entry names are emphatically NOT supposed to
            // have backslashes according to the spec, but they might anyway, so normalize them all to forward slashes.
            FullName = DecodeEntryName(cd.Filename).Replace('\\', '/');
            // Lazy-load Name so we don't preemptively do a ton of Substring() calls when we don't need to.
            _versionMadeByCompatibility = (ZipVersionMadeByPlatform)cd.VersionMadeByCompatibility;
        }
 /// <summary>
 /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
 /// on the path specifications and requirements of the OS that ZipArchive was created on.
 /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
 /// the platform-correct file name.
 /// </summary>
 /// <remarks>This method ensures no validation on the paths. Invalid characters are allowed.</remarks>
 internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
 {
     if (madeByPlatform == ZipVersionMadeByPlatform.Unix)
         return GetFileName_Unix(path);
     else
         return GetFileName_Windows(path);
 }
Beispiel #3
0
 /// <summary>
 /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
 /// on the path specifications and requirements of the OS that ZipArchive was created on.
 /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
 /// the platform-correct file name.
 /// </summary>
 /// <remarks>This method ensures no validation on the paths. Invalid characters are allowed.</remarks>
 internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
 {
     if (madeByPlatform == ZipVersionMadeByPlatform.Unix)
     {
         return(GetFileName_Unix(path));
     }
     else
     {
         return(GetFileName_Windows(path));
     }
 }
Beispiel #4
0
		internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
		{
			switch (madeByPlatform) {
			case ZipVersionMadeByPlatform.Windows:
				return GetFileName_Windows(path);
			case ZipVersionMadeByPlatform.Unix:
				return GetFileName_Unix(path);
			default:
				return ParseFileName (path, CurrentZipPlatform);
			}
		}
        internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
        {
            switch (madeByPlatform)
            {
            case ZipVersionMadeByPlatform.Windows:
                return(GetFileName_Windows(path));

            case ZipVersionMadeByPlatform.Unix:
                return(GetFileName_Unix(path));

            default:
                return(ParseFileName(path, CurrentZipPlatform));
            }
        }
        /// <summary>
        /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
        /// on the path specifications and requirements of the OS that ZipArchive was created on.
        /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
        /// the platform-correct file name.
        /// </summary>
        /// <remarks>This method ensures no validation on the paths. Invalid characters are allowed.</remarks>
        internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
        {
            string retFileName;

            if (madeByPlatform == ZipVersionMadeByPlatform.Windows)
            {
                retFileName = GetFileName_Windows(path);
            }
            else
            {
                retFileName = GetFileName_Unix(path);
            }

            return(retFileName);
        }
Beispiel #7
0
        // Initializes new entry
        internal ZipArchiveEntry(ZipArchive archive, string entryName)
        {
            _archive = archive;

            _originallyInArchive = false;

            _diskNumberStart            = 0;
            _versionMadeByPlatform      = CurrentZipPlatform;
            _versionMadeBySpecification = ZipVersionNeededValues.Default;
            _versionToExtract           = ZipVersionNeededValues.Default; // this must happen before following two assignment
            _generalPurposeBitFlag      = 0;
            CompressionMethod           = CompressionMethodValues.Deflate;
            _lastModified = DateTimeOffset.Now;

            _compressedSize               = 0; // we don't know these yet
            _uncompressedSize             = 0;
            _externalFileAttr             = 0;
            _offsetOfLocalHeader          = 0;
            _storedOffsetOfCompressedData = null;
            _crc32 = 0;

            _compressedBytes        = null;
            _storedUncompressedData = null;
            _currentlyOpenForWrite  = false;
            _everOpenedForWrite     = false;
            _outstandingWriteStream = null;

            FullName = entryName;

            _cdUnknownExtraFields = null;
            _lhUnknownExtraFields = null;
            _fileComment          = null;

            _compressionLevel = null;

            if (_storedEntryNameBytes.Length > ushort.MaxValue)
            {
                throw new ArgumentException();
            }

            // grab the stream if we're in create mode
            if (_archive.Mode == ZipArchiveMode.Create)
            {
                _archive.AcquireArchiveStream(this);
            }
        }
        /// <summary>
        /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
        /// on the path specifications and requirements of the OS that ZipArchive was created on.
        /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
        /// the platform-correct file name.
        /// </summary>
        internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
        {
            // Validation checking is done based on current OS, not source OS.
            PathInternal.CheckInvalidPathChars(path);

            if (madeByPlatform == ZipVersionMadeByPlatform.Unix)
            {
                int length = path.Length;
                for (int i = length; --i >= 0;)
                    if (path[i] == '/')
                        return path.Substring(i + 1);
                return path;
            }
            else
            {
                return Path.GetFileName(path);
            }
        }
        /// <summary>
        /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
        /// on the path specifications and requirements of the OS that ZipArchive was created on.
        /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
        /// the platform-correct file name.
        /// </summary>
        internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
        {
            // Validation checking is done based on current OS, not source OS.
            PathInternal.CheckInvalidPathChars(path);

            if (madeByPlatform == ZipVersionMadeByPlatform.Unix)
            {
                int length = path.Length;
                for (int i = length; --i >= 0;)
                {
                    if (path[i] == '/')
                    {
                        return(path.Substring(i + 1));
                    }
                }
                return(path);
            }
            else
            {
                return(Path.GetFileName(path));
            }
        }
Beispiel #10
0
        //Initializes, attaches it to archive
        internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd)
        {
            _archive = archive;

            _originallyInArchive = true;

            _diskNumberStart = cd.DiskNumberStart;
            _versionMadeByPlatform = (ZipVersionMadeByPlatform)cd.VersionMadeByCompatibility;
            _versionMadeBySpecification = (ZipVersionNeededValues)cd.VersionMadeBySpecification;
            _versionToExtract = (ZipVersionNeededValues)cd.VersionNeededToExtract;
            _generalPurposeBitFlag = (BitFlagValues)cd.GeneralPurposeBitFlag;
            CompressionMethod = (CompressionMethodValues)cd.CompressionMethod;
            _lastModified = new DateTimeOffset(ZipHelper.DosTimeToDateTime(cd.LastModified));
            _compressedSize = cd.CompressedSize;
            _uncompressedSize = cd.UncompressedSize;
            _offsetOfLocalHeader = cd.RelativeOffsetOfLocalHeader;
            /* we don't know this yet: should be _offsetOfLocalHeader + 30 + _storedEntryNameBytes.Length + extrafieldlength
                * but entryname/extra length could be different in LH
                */
            _storedOffsetOfCompressedData = null;
            _crc32 = cd.Crc32;

            _compressedBytes = null;
            _storedUncompressedData = null;
            _currentlyOpenForWrite = false;
            _everOpenedForWrite = false;
            _outstandingWriteStream = null;

            FullName = DecodeEntryName(cd.Filename);

            _lhUnknownExtraFields = null;
            //the cd should have these as null if we aren't in Update mode
            _cdUnknownExtraFields = cd.ExtraFields;
            _fileComment = cd.FileComment;

            _compressionLevel = null;
        }
Beispiel #11
0
        // Initializes, attaches it to archive
        internal ReadOnlyZipArchiveEntry(ReadOnlyZipArchive archive, ZipCentralDirectoryFileHeader cd)
        {
            _archive = archive;

            _originallyInArchive = true;

            _diskNumberStart            = cd.DiskNumberStart;
            _versionMadeByPlatform      = ( ZipVersionMadeByPlatform )cd.VersionMadeByCompatibility;
            _versionMadeBySpecification = ( ZipVersionNeededValues )cd.VersionMadeBySpecification;
            _versionToExtract           = ( ZipVersionNeededValues )cd.VersionNeededToExtract;
            _generalPurposeBitFlag      = ( BitFlagValues )cd.GeneralPurposeBitFlag;
            CompressionMethod           = ( CompressionMethodValues )cd.CompressionMethod;
            _lastModified        = new DateTimeOffset(ZipHelper.DosTimeToDateTime(cd.LastModified));
            _compressedSize      = cd.CompressedSize;
            _uncompressedSize    = cd.UncompressedSize;
            _externalFileAttr    = cd.ExternalFileAttributes;
            _offsetOfLocalHeader = cd.RelativeOffsetOfLocalHeader;
            // we don't know this yet: should be _offsetOfLocalHeader + 30 + _storedEntryNameBytes.Length + extrafieldlength
            // but entryname/extra length could be different in LH
            _storedOffsetOfCompressedData = null;
            _crc32 = cd.Crc32;

            _compressedBytes        = null;
            _storedUncompressedData = null;
            _currentlyOpenForWrite  = false;
            _everOpenedForWrite     = false;
            _outstandingWriteStream = null;

            FullName = DecodeEntryName(cd.Filename);

            _lhUnknownExtraFields = null;
            // the cd should have these as null if we aren't in Update mode
            _cdUnknownExtraFields = cd.ExtraFields;
            _fileComment          = cd.FileComment;

            _compressionLevel = null;
        }
Beispiel #12
0
        //Initializes new entry
        internal ZipArchiveEntry(ZipArchive archive, String entryName)
        {
            _archive = archive;

            _originallyInArchive = false;

            _diskNumberStart = 0;
            _versionMadeByPlatform = CurrentZipPlatform;
            _versionMadeBySpecification = ZipVersionNeededValues.Default;
            _versionToExtract = ZipVersionNeededValues.Default; //this must happen before following two assignment
            _generalPurposeBitFlag = 0;
            CompressionMethod = CompressionMethodValues.Deflate;
            _lastModified = DateTimeOffset.Now;

            _compressedSize = 0; //we don't know these yet
            _uncompressedSize = 0;
            _offsetOfLocalHeader = 0;
            _storedOffsetOfCompressedData = null;
            _crc32 = 0;

            _compressedBytes = null;
            _storedUncompressedData = null;
            _currentlyOpenForWrite = false;
            _everOpenedForWrite = false;
            _outstandingWriteStream = null;

            FullName = entryName;

            _cdUnknownExtraFields = null;
            _lhUnknownExtraFields = null;
            _fileComment = null;

            _compressionLevel = null;

            if (_storedEntryNameBytes.Length > UInt16.MaxValue)
                throw new ArgumentException(SR.EntryNamesTooLong);

            //grab the stream if we're in create mode
            if (_archive.Mode == ZipArchiveMode.Create)
            {
                _archive.AcquireArchiveStream(this);
            }
        }
Beispiel #13
0
 /// <summary>
 /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
 /// on the path specifications and requirements of the OS that ZipArchive was created on.
 /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
 /// the platform-correct file name.
 /// </summary>
 /// <remarks>This method ensures no validation on the paths. Invalid characters are allowed.</remarks>
 internal static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform) =>
 madeByPlatform == ZipVersionMadeByPlatform.Unix ? GetFileName_Unix(path) : GetFileName_Windows(path);
Beispiel #14
0
 /// <summary>
 /// To get the file name of a ZipArchiveEntry, we should be parsing the FullName based
 /// on the path specifications and requirements of the OS that ZipArchive was created on.
 /// This method takes in a FullName and the platform of the ZipArchiveEntry and returns
 /// the platform-correct file name.
 /// </summary>
 /// <remarks>This method ensures no validation on the paths. Invalid characters are allowed.</remarks>
 private static string ParseFileName(string path, ZipVersionMadeByPlatform madeByPlatform)
 {
     return(madeByPlatform == ZipVersionMadeByPlatform.Windows
         ? GetFileName_Windows(path)
         : GetFileName_Unix(path));
 }