示例#1
0
        internal static ZipFile Read(string zipfilename, bool TurnOnDebug)
        {
            ZipFile zf = new ZipFile();

            zf._Debug   = TurnOnDebug;
            zf._name    = zipfilename;
            zf._entries = new System.Collections.Generic.List <ZipEntry>();
            ZipEntry e;

            while ((e = ZipEntry.Read(zf.ReadStream, zf._Debug)) != null)
            {
                if (zf._Debug)
                {
                    System.Console.WriteLine("  ZipFile::Read(): ZipEntry: {0}", e.FileName);
                }
                zf._entries.Add(e);
            }

            // read the zipfile's central directory structure here.
            zf._direntries = new System.Collections.Generic.List <ZipDirEntry>();

            ZipDirEntry de;

            while ((de = ZipDirEntry.Read(zf.ReadStream, zf._Debug)) != null)
            {
                if (zf._Debug)
                {
                    System.Console.WriteLine("  ZipFile::Read(): ZipDirEntry: {0}", de.FileName);
                }
                zf._direntries.Add(de);
            }

            return(zf);
        }
示例#2
0
        internal static ZipDirEntry Read(System.IO.Stream s, bool TurnOnDebug)
        {
            int signature = TomShane.Neoforce.External.Zip.Shared.ReadSignature(s);

            // return null if this is not a local file header signature
            if (SignatureIsNotValid(signature))
            {
                s.Seek(-4, System.IO.SeekOrigin.Current);
                if (TurnOnDebug)
                {
                    System.Console.WriteLine("  ZipDirEntry::Read(): Bad signature ({0:X8}) at position {1}", signature, s.Position);
                }
                return(null);
            }

            byte[] block = new byte[42];
            int    n     = s.Read(block, 0, block.Length);

            if (n != block.Length)
            {
                return(null);
            }

            int         i   = 0;
            ZipDirEntry zde = new ZipDirEntry();

            zde._Debug             = TurnOnDebug;
            zde._VersionMadeBy     = (short)(block[i++] + block[i++] * 256);
            zde._VersionNeeded     = (short)(block[i++] + block[i++] * 256);
            zde._BitField          = (short)(block[i++] + block[i++] * 256);
            zde._CompressionMethod = (short)(block[i++] + block[i++] * 256);
            zde._LastModDateTime   = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._Crc32             = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._CompressedSize    = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._UncompressedSize  = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

            zde._LastModified = TomShane.Neoforce.External.Zip.Shared.PackedToDateTime(zde._LastModDateTime);

            Int16 filenameLength    = (short)(block[i++] + block[i++] * 256);
            Int16 extraFieldLength  = (short)(block[i++] + block[i++] * 256);
            Int16 commentLength     = (short)(block[i++] + block[i++] * 256);
            Int16 diskNumber        = (short)(block[i++] + block[i++] * 256);
            Int16 internalFileAttrs = (short)(block[i++] + block[i++] * 256);
            Int32 externalFileAttrs = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            Int32 Offset            = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

            block         = new byte[filenameLength];
            n             = s.Read(block, 0, block.Length);
            zde._FileName = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);

            zde._Extra = new byte[extraFieldLength];
            n          = s.Read(zde._Extra, 0, zde._Extra.Length);

            block        = new byte[commentLength];
            n            = s.Read(block, 0, block.Length);
            zde._Comment = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);

            return(zde);
        }
示例#3
0
        /// <summary>
        /// Opens a stream for reading the specified asset contained inside the archive.
        /// </summary>
        /// <param name="assetName">Name of the asset to read.</param>
        /// <returns>Returns the opened stream.</returns>
        protected override Stream OpenStream(string assetName)
        {
            if (useArchive && archive != null)
            {
                assetName = assetName.Replace("\\", "/");
                if (assetName.StartsWith("/")) assetName = assetName.Remove(0, 1);

                string fullAssetName = (assetName + ".xnb").ToLower();

                foreach (ZipEntry entry in archive)
                {
                    ZipDirEntry ze = new ZipDirEntry(entry);

                    string entryName = entry.FileName.ToLower();

                    if (entryName == fullAssetName)
                    {
                        return entry.GetStream();
                    }
                }
                throw new Exception("Cannot find asset \"" + assetName + "\" in the archive.");
            }
            else
            {
                return base.OpenStream(assetName);
            }
        }
        internal static ZipDirEntry Read(System.IO.Stream s, bool TurnOnDebug)
        {

            int signature = TomShane.Neoforce.External.Zip.Shared.ReadSignature(s);
            // return null if this is not a local file header signature
            if (SignatureIsNotValid(signature))
            {
                s.Seek(-4, System.IO.SeekOrigin.Current);
                if (TurnOnDebug) System.Console.WriteLine("  ZipDirEntry::Read(): Bad signature ({0:X8}) at position {1}", signature, s.Position);
                return null;
            }

            byte[] block = new byte[42];
            int n = s.Read(block, 0, block.Length);
            if (n != block.Length) return null;

            int i = 0;
            ZipDirEntry zde = new ZipDirEntry();

            zde._Debug = TurnOnDebug;
            zde._VersionMadeBy = (short)(block[i++] + block[i++] * 256);
            zde._VersionNeeded = (short)(block[i++] + block[i++] * 256);
            zde._BitField = (short)(block[i++] + block[i++] * 256);
            zde._CompressionMethod = (short)(block[i++] + block[i++] * 256);
            zde._LastModDateTime = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._Crc32 = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._CompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._UncompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

            zde._LastModified = TomShane.Neoforce.External.Zip.Shared.PackedToDateTime(zde._LastModDateTime);

            Int16 filenameLength = (short)(block[i++] + block[i++] * 256);
            Int16 extraFieldLength = (short)(block[i++] + block[i++] * 256);
            Int16 commentLength = (short)(block[i++] + block[i++] * 256);
            Int16 diskNumber = (short)(block[i++] + block[i++] * 256);
            Int16 internalFileAttrs = (short)(block[i++] + block[i++] * 256);
            Int32 externalFileAttrs = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            Int32 Offset = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

            block = new byte[filenameLength];
            n = s.Read(block, 0, block.Length);
            zde._FileName = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);

            zde._Extra = new byte[extraFieldLength];
            n = s.Read(zde._Extra, 0, zde._Extra.Length);

            block = new byte[commentLength];
            n = s.Read(block, 0, block.Length);
            zde._Comment = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);

            return zde;
        }
示例#5
0
        internal static ZipDirEntry Read(Stream s, bool TurnOnDebug)
        {
            var signature = Shared.ReadSignature(s);

            // return null if this is not a local file header signature
            if (SignatureIsNotValid(signature))
            {
                s.Seek(-4, SeekOrigin.Current);
                if (TurnOnDebug)
                {
                    Console.WriteLine("  ZipDirEntry::Read(): Bad signature ({0:X8}) at position {1}", signature,
                                      s.Position);
                }
                return(null);
            }

            var block = new byte[42];
            var n     = s.Read(block, 0, block.Length);

            if (n != block.Length)
            {
                return(null);
            }

            var i   = 0;
            var zde = new ZipDirEntry();

            zde._Debug            = TurnOnDebug;
            zde.VersionMadeBy     = (short)(block[i++] + block[i++] * 256);
            zde.VersionNeeded     = (short)(block[i++] + block[i++] * 256);
            zde._BitField         = (short)(block[i++] + block[i++] * 256);
            zde.CompressionMethod = (short)(block[i++] + block[i++] * 256);
            zde._LastModDateTime  = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde._Crc32            = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde.CompressedSize    = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
            zde.UncompressedSize  = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

            zde.LastModified = Shared.PackedToDateTime(zde._LastModDateTime);

            var filenameLength    = (short)(block[i++] + block[i++] * 256);
            var extraFieldLength  = (short)(block[i++] + block[i++] * 256);
            var commentLength     = (short)(block[i++] + block[i++] * 256);
            var diskNumber        = (short)(block[i++] + block[i++] * 256);
            var internalFileAttrs = (short)(block[i++] + block[i++] * 256);
            var externalFileAttrs = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 +
                                    block[i++] * 256 * 256 * 256;
            var Offset = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;

            block        = new byte[filenameLength];
            n            = s.Read(block, 0, block.Length);
            zde.FileName = Shared.StringFromBuffer(block, 0, block.Length);

            zde._Extra = new byte[extraFieldLength];
            n          = s.Read(zde._Extra, 0, zde._Extra.Length);

            block       = new byte[commentLength];
            n           = s.Read(block, 0, block.Length);
            zde.Comment = Shared.StringFromBuffer(block, 0, block.Length);

            return(zde);
        }