Beispiel #1
0
        private List <object> GetZipFileItems(string path, bool recurse)
        {
            string        pwd             = path.Replace(this.PSDriveInfo.Root + "\\", "").Replace("\\", "/").ToUpper();
            List <object> foldersAndFiles = new List <object>();
            List <object> folders         = new List <object>();
            List <object> files           = new List <object>();

            using (ZipArchive archive = System.IO.Compression.ZipFile.OpenRead(this.PSDriveInfo.Root))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    string n = entry.FullName.ToUpper();
                    if (n.StartsWith(pwd))
                    {
                        if (pwd != "")
                        {
                            n = n.Substring(pwd.Length, (n.Length - pwd.Length)).Remove(0, 1);
                        }
                        if (!n.Contains("/"))
                        {
                            files.Add(new ZipFileObject(entry, PSDriveInfo.Name, pwd, entry.Name, false));
                        }
                        else
                        {
                            string name = n.Split('/')[0] + "/";

                            ZipFileObject obj   = new ZipFileObject(null, PSDriveInfo.Name, pwd, name, true);
                            bool          found = false;
                            foreach (ZipFileObject i in folders)
                            {
                                if (i.Name == name)
                                {
                                    found = true;
                                }
                            }
                            if (!found)
                            {
                                folders.Add(obj);
                            }
                        }
                    }
                }
            }
            foreach (object i in folders)
            {
                foldersAndFiles.Add(i);
            }
            foreach (object i in files)
            {
                foldersAndFiles.Add(i);
            }
            return(foldersAndFiles);
        }
Beispiel #2
0
        public IContentReader GetContentReader(string path)
        {
            //GetZipFileItem(path)
            if (PathIsDirectory(path))
            {
                // ("Directories have no content", path, ErrorCategory.InvalidOperation);
                throw new Exception("Directories have no content");
            }

            ZipFileObject v = GetZipFileItem(path);

            if (v != null)
            {
                ZipFileStream obj = new ZipFileStream(v._archive, false);
                return(obj);
            }
            return(null);
        }