Inheritance: IArchiveFile
Ejemplo n.º 1
0
        public IArchiveFile OpenArchive(string filename)
        {
            var file = new ZipFile(filename);
            var root = new Archive(file, null, filename);
            foreach (ZipEntry entry in file)
            {
                string name = entry.Name;
                string[] pathComponents = name.Split(new[] { '/','\\' },StringSplitOptions.RemoveEmptyEntries);

                if (entry.IsFile)
                {
                    IArchiveFile parent = pathComponents.Length > 1 ? CreateDirectories(file, root, pathComponents, pathComponents.Length-1) : root;
                    IArchiveFile child = new Archive(file, parent, pathComponents[pathComponents.Length - 1], entry);
                    parent.Children.Add(child.Name.ToLowerInvariant(), child);
                }
                else
                {
                    CreateDirectories(file, root, pathComponents, pathComponents.Length);
                }
            }
            return root;
        }
Ejemplo n.º 2
0
 private static IArchiveFile CreateDirectories(ZipFile file, IArchiveFile root,string[] components,int length)
 {
     IArchiveFile parent = root;
     for (int i = 0; i < length; ++i)
     {
         if (!parent.Children.ContainsKey(components[i].ToLowerInvariant()))
         {
             var child = new Archive(file,parent, components[i]);
             parent.Children.Add(child.Name.ToLowerInvariant(), child);
             parent = child;
         }
         else
         {
             parent = parent.Children[components[i].ToLowerInvariant()];
         }
     }
     return parent;
 }