Example #1
0
        public IFileSystem Generate(ZipFile zipFile, IDictionary <string, int> fileTypes)
        {
            _root = P4kDirectory.Root();

            var files = new List <IFile>();

            foreach (ZipEntry item in zipFile.Cast <ZipEntry>()
                     .Where(f => f.IsFile))
            {
                var directory = EnsureDirectoryExists(item.Name);
                var file      = new P4kFile(item, zipFile);

                files.Add(file);
                directory.Add(file);

                // statistics
                var extension = Path.GetExtension(file.Name)
                                .TrimStart('.');

                if (!fileTypes.ContainsKey(extension))
                {
                    fileTypes.Add(extension, 1);
                }
                else
                {
                    fileTypes[extension]++;
                }
            }

            return(new P4kFileSystem(_root, Convert.ToInt32(zipFile.Count), files));
        }
Example #2
0
        public IFileSystem Generate(ZipFile zipFile)
        {
            _root = P4kDirectory.Root();
            foreach (ZipEntry item in zipFile.Cast <ZipEntry>()
                     .Where(f => f.IsFile))
            {
                var directory = EnsureDirectoryExists(item.Name);
                directory.Add(new P4kFile(item, zipFile));
            }

            return(new P4kFileSystem(_root));
        }
Example #3
0
        private P4kDirectory EnsureDirectoryExists(string zipItemName)
        {
            var          pathSegments = zipItemName.Split('/');
            P4kDirectory current      = _root;

            for (int i = 0; i < pathSegments.Length - 1; i++)
            {
                var name      = pathSegments[i];
                var directory = current.Directories.SingleOrDefault(d => d.Name == name);
                if (directory == null)
                {
                    string path = $"{current.Path}\\{name}";
                    directory = new P4kDirectory(pathSegments[i], path);
                    current.Add(directory);
                }

                current = (P4kDirectory)directory;
            }

            return(current);
        }