예제 #1
0
            public void WriteZipDataHeader(ref ZipDataHeader h, bool writeSizes)
            {
                h.Signature = Signature;
                h.NeedVer   = Version;
                h.CompType  = 0;
                h.FileTime  = Util.DateTimeToDosTime(this.DateTime);
                h.FileDate  = Util.DateTimeToDosDate(this.DateTime);
                h.Option    = 8;

                if (writeSizes == false)
                {
                    h.CompSize = h.UncompSize = 0;
                    h.Crc32    = 0;

                    if (this.Compress)
                    {
                        h.NeedVer  = VersionWithCompress;
                        h.CompType = 8;
                    }
                }
                else
                {
                    h.CompSize = h.UncompSize = (uint)this.Size;
                    if (this.Compress)
                    {
                        h.CompSize = (uint)this.CompressSize;
                        h.CompType = 8;
                    }
                    h.Crc32 = this.Crc32;
                }

                h.FileNameLen = (ushort)this.Encoding !.GetByteCount(this.Name !);
                h.ExtraLen    = 0;
            }
예제 #2
0
        public void Finish()
        {
            long posStart = fifo.TotalWriteSize;

            foreach (File f in this.fileList)
            {
                ZipDirHeader d = new ZipDirHeader();
                d.Signature = 0x02014B50;// ZipPacker.Signature;
                d.MadeVer   = Version;
                ZipDataHeader dh = new ZipDataHeader();
                f.WriteZipDataHeader(ref dh, true);
                if (f.Compress)
                {
                    dh.CompType = 8;
                    dh.CompSize = (uint)f.CompressSize;
                    dh.NeedVer  = ZipPacker.VersionWithCompress;
                }
                d.NeedVer     = dh.NeedVer;
                d.Option      = dh.Option;
                d.CompType    = dh.CompType;
                d.FileTime    = dh.FileTime;
                d.FileDate    = dh.FileDate;
                d.Crc32       = dh.Crc32;
                d.CompSize    = dh.CompSize;
                d.UncompSize  = dh.UncompSize;
                d.FileNameLen = dh.FileNameLen;
                d.ExtraLen    = dh.ExtraLen;
                d.CommentLen  = 0;
                d.DiskNum     = 0;
                d.InAttr      = 0;
                d.OutAttr     = (ushort)f.Attributes;
                d.HeaderPos   = f.HeaderPos;

                fifo.Write(Util.Legacy_StructToByte(d));
                fifo.Write(this.Encoding.GetBytes(f.Name !));
            }
            long posEnd = fifo.TotalWriteSize;

            ZipEndHeader e = new ZipEndHeader();

            e.Signature    = ZipPacker.SignatureEnd;
            e.DiskNum      = e.StartDiskNum = 0;
            e.DiskDirEntry = e.DirEntry = (ushort)this.fileList.Count;
            e.DirSize      = (uint)(posEnd - posStart);
            e.StartPos     = (uint)posStart;
            e.CommentLen   = 0;
            fifo.Write(Util.Legacy_StructToByte(e));
        }
예제 #3
0
        public void AddFileStart(string name, long size, DateTime dt, FileAttributes attribute, bool compress)
        {
            if (currentFile != null)
            {
                throw new ApplicationException("currentFile != null");
            }

            name = name.Replace("/", "\\");

            File f = new File();

            f.Encoding   = this.Encoding;
            f.Name       = name;
            f.Size       = size;
            f.DateTime   = dt;
            f.Attributes = attribute;
            f.Compress   = compress;

            this.fileList.Add(f);

            ZipDataHeader h = new ZipDataHeader();

            f.HeaderPos = (uint)fifo.TotalWriteSize;
            f.WriteZipDataHeader(ref h, false);
            fifo.Write(Util.Legacy_StructToByte(h));
            fifo.Write(this.Encoding.GetBytes(f.Name));
            f.Crc32 = 0xffffffff;

            if (compress)
            {
                f.ZStream = new Basic.Internal.ZStream();
                f.ZStream.deflateInit(-1, -15);
            }

            currentFile = f;
        }