Example #1
0
        private void PerformEnumeration()
        {
            String zipPath = VPPUtil.ConvertVirtualPathToZipPath(_virtualPath, false);

            if (zipPath[zipPath.Length - 1] != '/')
            {
                ZipEntry entry = _zipFile.GetEntry(zipPath);
                if (entry != null)
                {
                    _paths.Add(new ZipVirtualFile(zipPath, _zipFile));
                }
                return;
            }
            else
            {
                foreach (ZipEntry entry in _zipFile)
                {
                    Console.WriteLine(entry.Name);
                    if (entry.Name == zipPath)
                    {
                        continue;
                    }
                    if (entry.Name.StartsWith(zipPath))
                    {
                        // if we're looking for files and current entry is a directory, skip it
                        if (_requestType == VirtualPathType.Files && entry.IsDirectory)
                        {
                            continue;
                        }
                        // if we're looking for directories and current entry its not one, skip it
                        if (_requestType == VirtualPathType.Directories && !entry.IsDirectory)
                        {
                            continue;
                        }

                        int pos = entry.Name.IndexOf('/', zipPath.Length);
                        if (pos != -1)
                        {
                            if (entry.Name.Length > pos + 1)
                            {
                                continue;
                            }
                        }
                        //    continue;
                        if (entry.IsDirectory)
                        {
                            _paths.Add(new ZipVirtualDirectory(VPPUtil.ConvertZipPathToVirtualPath(entry.Name), _zipFile));
                        }
                        else
                        {
                            _paths.Add(new ZipVirtualFile(VPPUtil.ConvertZipPathToVirtualPath(entry.Name), _zipFile));
                        }
                    }
                }
            }
        }
Example #2
0
        public override bool DirectoryExists(string virtualDir)
        {
            string   zipPath  = VPPUtil.ConvertVirtualPathToZipPath(virtualDir, false);
            ZipEntry zipEntry = _zipFile.GetEntry(zipPath);

            if (zipEntry != null)
            {
                return(zipEntry.IsDirectory);
            }
            else
            {
                // Here you may want to return Previous.DirectoryExists(virtualDir) instead of false
                // if you want to give the previously registered provider a chance to process the directory
                return(false);
            }
        }
Example #3
0
        public override bool FileExists(string virtualPath)
        {
            string   zipPath  = VPPUtil.ConvertVirtualPathToZipPath(virtualPath, true);
            ZipEntry zipEntry = _zipFile.GetEntry(zipPath);

            if (zipEntry != null)
            {
                return(!zipEntry.IsDirectory);
            }
            else
            {
                // Here you may want to return Previous.FileExists(virtualPath) instead of false
                // if you want to give the previously registered provider a process to serve the file
                return(false);
            }
        }
Example #4
0
        public override System.IO.Stream Open()
        {
            ZipEntry entry = _zipFile.GetEntry(VPPUtil.ConvertVirtualPathToZipPath(base.VirtualPath, true));

            using (Stream st = _zipFile.GetInputStream(entry))
            {
                MemoryStream ms = new MemoryStream();
                ms.SetLength(entry.Size);
                byte[] buf = new byte[2048];
                while (true)
                {
                    int r = st.Read(buf, 0, 2048);
                    if (r == 0)
                    {
                        break;
                    }
                    ms.Write(buf, 0, r);
                }
                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
        }