コード例 #1
0
ファイル: ZipArchiveEntry.cs プロジェクト: wise0704/SwcBuild
        private bool WriteLocalFileHeader(bool isEmptyFile)
        {
            uint            maxValue;
            uint            num2;
            ushort          num4;
            BinaryWriter    writer = new BinaryWriter(_archive.ArchiveStream);
            Zip64ExtraField field  = new Zip64ExtraField();
            bool            flag   = false;

            if (isEmptyFile)
            {
                CompressionMethod = CompressionMethodValues.Stored;
                maxValue          = 0;
                num2 = 0;
            }
            else if (((_archive.Mode == ZipArchiveMode.Create) && !_archive.ArchiveStream.CanSeek) && !isEmptyFile)
            {
                _generalPurposeBitFlag |= BitFlagValues.DataDescriptor;
                flag     = false;
                maxValue = 0;
                num2     = 0;
            }
            else if (SizesTooLarge())
            {
                flag                   = true;
                maxValue               = uint.MaxValue;
                num2                   = uint.MaxValue;
                field.CompressedSize   = new long?(_compressedSize);
                field.UncompressedSize = new long?(_uncompressedSize);
                VersionToExtractAtLeast(ZipVersionNeededValues.Zip64);
            }
            else
            {
                flag     = false;
                maxValue = (uint)_compressedSize;
                num2     = (uint)_uncompressedSize;
            }
            _offsetOfLocalHeader = writer.BaseStream.Position;
            int num3 = (flag ? field.TotalSize : 0) + ((_lhUnknownExtraFields != null) ? ZipGenericExtraField.TotalSize(_lhUnknownExtraFields) : 0);

            if (num3 > 0xffff)
            {
                num4 = flag ? field.TotalSize : ((ushort)0);
                _lhUnknownExtraFields = null;
            }
            else
            {
                num4 = (ushort)num3;
            }
            writer.Write((uint)0x4034b50);
            writer.Write((ushort)_versionToExtract);
            writer.Write((ushort)_generalPurposeBitFlag);
            writer.Write((ushort)CompressionMethod);
            writer.Write(ZipHelper.DateTimeToDosTime(_lastModified.DateTime));
            writer.Write(_crc32);
            writer.Write(maxValue);
            writer.Write(num2);
            writer.Write((ushort)_storedEntryNameBytes.Length);
            writer.Write(num4);
            writer.Write(_storedEntryNameBytes);
            if (flag)
            {
                field.WriteBlock(_archive.ArchiveStream);
            }
            if (_lhUnknownExtraFields != null)
            {
                ZipGenericExtraField.WriteAllBlocks(_lhUnknownExtraFields, _archive.ArchiveStream);
            }
            return(flag);
        }
コード例 #2
0
ファイル: ZipArchiveEntry.cs プロジェクト: wise0704/SwcBuild
        internal void WriteCentralDirectoryFileHeader()
        {
            uint            maxValue;
            uint            num2;
            uint            num3;
            ushort          num5;
            BinaryWriter    writer = new BinaryWriter(_archive.ArchiveStream);
            Zip64ExtraField field  = new Zip64ExtraField();
            bool            flag   = false;

            if (SizesTooLarge())
            {
                flag                   = true;
                maxValue               = uint.MaxValue;
                num2                   = uint.MaxValue;
                field.CompressedSize   = new long?(_compressedSize);
                field.UncompressedSize = new long?(_uncompressedSize);
            }
            else
            {
                maxValue = (uint)_compressedSize;
                num2     = (uint)_uncompressedSize;
            }
            if (_offsetOfLocalHeader > 0xffffffffL)
            {
                flag = true;
                num3 = uint.MaxValue;
                field.LocalHeaderOffset = new long?(_offsetOfLocalHeader);
            }
            else
            {
                num3 = (uint)_offsetOfLocalHeader;
            }
            if (flag)
            {
                VersionToExtractAtLeast(ZipVersionNeededValues.Zip64);
            }
            int num4 = (flag ? field.TotalSize : 0) + ((_cdUnknownExtraFields != null) ? ZipGenericExtraField.TotalSize(_cdUnknownExtraFields) : 0);

            if (num4 > 0xffff)
            {
                num5 = flag ? field.TotalSize : ((ushort)0);
                _cdUnknownExtraFields = null;
            }
            else
            {
                num5 = (ushort)num4;
            }
            writer.Write((uint)0x2014b50);
            writer.Write((ushort)_versionToExtract);
            writer.Write((ushort)_versionToExtract);
            writer.Write((ushort)_generalPurposeBitFlag);
            writer.Write((ushort)CompressionMethod);
            writer.Write(ZipHelper.DateTimeToDosTime(_lastModified.DateTime));
            writer.Write(_crc32);
            writer.Write(maxValue);
            writer.Write(num2);
            writer.Write((ushort)_storedEntryNameBytes.Length);
            writer.Write(num5);
            writer.Write((_fileComment != null) ? ((ushort)_fileComment.Length) : ((ushort)0));
            writer.Write((ushort)0);
            writer.Write((ushort)0);
            writer.Write((uint)0);
            writer.Write(num3);
            writer.Write(_storedEntryNameBytes);
            if (flag)
            {
                field.WriteBlock(_archive.ArchiveStream);
            }
            if (_cdUnknownExtraFields != null)
            {
                ZipGenericExtraField.WriteAllBlocks(_cdUnknownExtraFields, _archive.ArchiveStream);
            }
            if (_fileComment != null)
            {
                writer.Write(_fileComment);
            }
        }