示例#1
0
        public VfsEntry GetChild(string name, VfsEntry entry)
        {
            string realPath = System.IO.Path.Combine(_dirInfo.FullName, name);
            var    dir      = new DirectoryInfo(realPath);

            if (dir.Exists)
            {
                return(new VfsEntry(dir.Name, false, 0, entry, new VfsPhysicalDirectory(dir)));
            }
            var file = new FileInfo(realPath);

            if (file.Exists)
            {
                return(new VfsEntry(file.Name, true, file.Length, entry));
            }
            return(null);
        }
示例#2
0
        public VfsEntry GetChild(string name, VfsEntry entry)
        {
            string   realPath = System.IO.Path.Combine(_pathInZip, name);
            ZipEntry ze       = _zipFile.GetEntry(realPath + "/") ?? _zipFile.GetEntry(realPath);

            if (ze == null)
            {
                return(null);
            }
            if (ze.IsFile)
            {
                return(new VfsEntry(name, true, ze.Size, entry));
            }
            else
            {
                return(new VfsEntry(name, false, 0, entry, new VfsZipDirectory(_zipFile, Path.Combine(_pathInZip, name))));
            }
        }
示例#3
0
        public IEnumerator <VfsEntry> GetEnumerator(VfsEntry entry)
        {
            // adapter on top of ZipFile enumerator to filter only current directory
            return(_zipFile.Cast <ZipEntry>()
                   .Where((ze) => {
                // if it does not start with the current subdir, skip it
                if (!ze.Name.StartsWith(_pathInZip))
                {
                    return false;
                }
                // if its name starts with the path and is the same length, it is the same string
                // but we only want children, not the directory itself.
                if (ze.Name.Length == _pathInZip.Length)
                {
                    return false;
                }
                var firstSlash = ze.Name.IndexOf(System.IO.Path.DirectorySeparatorChar, _pathInZip.Length);
                // if we don't find any subsequent slashes, it has to be a file in the current subdir
                if (firstSlash == -1)
                {
                    return true;
                }
                // if we find a slash at the end of the entrys name it is a subdirectory in the current directory
                if (firstSlash == ze.Name.Length - 1)
                {
                    return true;
                }
                // otherwise it is something further down in the tree which we don't want here
                return false;
            })

                   .Select((e) => {
                if (e.IsDirectory)
                {
                    return new VfsEntry(Path.GetFileName(e.Name.Remove(e.Name.Length - 1)), false, 0, entry, new VfsZipDirectory(_zipFile, e.Name));
                }
                else
                {
                    return new VfsEntry(Path.GetFileName(e.Name), e.IsFile, e.Size, entry);
                }
            }).GetEnumerator());
        }
示例#4
0
        public Stream GetStreamForChild(VfsEntry child)
        {
            var ze = _zipFile.GetEntry(Path.Combine(_pathInZip, child.Name));

            return(_zipFile.GetInputStream(ze));
        }
示例#5
0
 public Stream GetStreamForChild(VfsEntry child) => null;
示例#6
0
 public IEnumerator <VfsEntry> GetEnumerator(VfsEntry entry)
 {
     yield break;
 }
示例#7
0
 public VfsEntry GetChild(string name, VfsEntry entry) => null;
示例#8
0
 public VfsPhysicalDirectory(VfsEntry entry)
 {
     _dirInfo = new DirectoryInfo(entry.Path);
 }