示例#1
0
        /// <summary>List files by the specified filter.</summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Filter list of files.</returns>
        public override IFile[] ListFilesFiltered(IFileFilter filter)
        {
            ArrayList files = new ArrayList();
            int       slashes;
            string    entryPath, listPrefix = "/";

            if (this.innerPath != "/")
            {
                listPrefix = this.innerPath + "/";
            }

            slashes = CountChar(listPrefix, '/');

            ZipFile zipFile = this.OpenZipFile();

            foreach (ZipEntry entry in zipFile)
            {
                entryPath = "/" + (entry.IsDirectory ? entry.Name.Substring(0, entry.Name.Length - 1) : entry.Name);

                //Debug("entryPath: " + entryPath +",listPrefix: "+ listPrefix +",CountChar:"+ CountChar(entryPath, '/') +",slashes:"+ slashes + ",indexof:" + entryPath.IndexOf(listPrefix));

                if (entryPath.StartsWith(listPrefix) && CountChar(entryPath, '/') == slashes)
                {
                    ZipFileImpl file = new ZipFileImpl(this.manager, this.zipPath, entryPath.Substring(1), FileType.Unknown);

                    file.ZipEntry = entry;

                    files.Add(file);
                }
            }

            zipFile.Close();

            return((IFile[])files.ToArray(typeof(ZipFileImpl)));
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="mode"></param>
        public ZipFileStream(ZipFileImpl file, FileMode mode) : base()
        {
            this.zipFile = file;
            this.mode    = mode;

            // Read in whole zip entry
            if (this.mode == FileMode.Open || this.mode == FileMode.Append)
            {
                // Can't open non existing zip
                if (!File.Exists(this.zipFile.ZipPath))
                {
                    return;
                }

                ZipFile zipFile = file.OpenZipFile();

                try {
                    if (file.ZipEntry == null)
                    {
                        zipFile.Close();
                        return;
                    }

                    Stream stream = zipFile.GetInputStream(file.ZipEntry);
                    byte[] buff   = new byte[1024];
                    int    len;

                    // Read and stream chunks
                    try {
                        while ((len = stream.Read(buff, 0, 1024)) > 0)
                        {
                            this.Write(buff, 0, len);
                        }
                    } finally {
                        stream.Close();
                    }

                    if (this.mode == FileMode.Open)
                    {
                        this.Seek(0, SeekOrigin.Begin);
                    }
                } finally {
                    zipFile.Close();
                }
            }
        }
示例#3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <param name="mode"></param>
        public ZipFileStream(ZipFileImpl file, FileMode mode)
            : base()
        {
            this.zipFile = file;
            this.mode = mode;

            // Read in whole zip entry
            if (this.mode == FileMode.Open || this.mode == FileMode.Append) {
                // Can't open non existing zip
                if (!File.Exists(this.zipFile.ZipPath))
                    return;

                ZipFile zipFile = file.OpenZipFile();

                try {
                    if (file.ZipEntry == null) {
                        zipFile.Close();
                        return;
                    }

                    Stream stream = zipFile.GetInputStream(file.ZipEntry);
                    byte[] buff = new byte[1024];
                    int len;

                    // Read and stream chunks
                    try {
                        while ((len = stream.Read(buff, 0, 1024)) > 0)
                            this.Write(buff, 0, len);
                    } finally {
                        stream.Close();
                    }

                    if (this.mode == FileMode.Open)
                        this.Seek(0, SeekOrigin.Begin);
                } finally {
                    zipFile.Close();
                }
            }
        }
示例#4
0
        /// <summary>List files by the specified filter.</summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Filter list of files.</returns>
        public override IFile[] ListFilesFiltered(IFileFilter filter)
        {
            ArrayList files = new ArrayList();
            int slashes;
            string entryPath, listPrefix = "/";

            if (this.innerPath != "/")
                listPrefix = this.innerPath + "/";

            slashes = CountChar(listPrefix, '/');

            ZipFile zipFile = this.OpenZipFile();
            foreach (ZipEntry entry in zipFile) {
                entryPath = "/" + (entry.IsDirectory ? entry.Name.Substring(0, entry.Name.Length - 1) : entry.Name);

                //Debug("entryPath: " + entryPath +",listPrefix: "+ listPrefix +",CountChar:"+ CountChar(entryPath, '/') +",slashes:"+ slashes + ",indexof:" + entryPath.IndexOf(listPrefix));

                if (entryPath.StartsWith(listPrefix) && CountChar(entryPath, '/') == slashes) {
                    ZipFileImpl file = new ZipFileImpl(this.manager, this.zipPath, entryPath.Substring(1), FileType.Unknown);

                    file.ZipEntry = entry;

                    files.Add(file);
                }
            }

            zipFile.Close();

            return (IFile[]) files.ToArray(typeof(ZipFileImpl));
        }