public InZipFile(IDirectory parentDirectory, string originalPath, ZipFile file, InternalZipDirectory directory, ZipEntry?entry)
     : base(() => parentDirectory, originalPath, Path.GetFileName(entry?.FileName ?? string.Empty))
 {
     _file      = file;
     _directory = directory;
     _entry     = entry;
 }
        private static void Add(InternalZipDirectory directory, ZipEntry entry)
        {
            var parts = entry.FileName.Split(PathSplit, StringSplitOptions.RemoveEmptyEntries);

            var mainDic = directory;

            for (var i = 0; i < parts.Length; i++)
            {
                if (i == parts.Length - 1)
                {
                    if (entry.IsDirectory)
                    {
                        mainDic          = mainDic.GetOrAdd(parts[i]);
                        mainDic.ZipEntry = entry;
                    }
                    else
                    {
                        mainDic.AddFile(entry);
                    }
                }
                else
                {
                    mainDic = mainDic.GetOrAdd(parts[i]);
                }
            }
        }
        public static InternalZipDirectory ReadZipDirectory([NotNull] ZipFile file)
        {
            if (file == null) throw new ArgumentNullException("file");
            var directory = new InternalZipDirectory(string.Empty);

            foreach (var entry in file)
            {
                Add(directory, entry);
            }

            return directory;
        }
        internal InternalZipDirectory GetOrAdd(string name)
        {
            var dic = Directorys.FirstOrDefault(d => d.Name == name);

            if (dic != null)
            {
                return(dic);
            }
            dic = new InternalZipDirectory(name);
            Directorys.Add(dic);
            return(dic);
        }
        public static InternalZipDirectory ReadZipDirectory(ZipFile?file)
        {
            var directory = new InternalZipDirectory(string.Empty);

            if (file == null)
            {
                return(directory);
            }

            foreach (var entry in file)
            {
                Add(directory, entry);
            }

            return(directory);
        }
Exemplo n.º 6
0
        public void Reload(string source)
        {
            if (SaveAfterDispose)
            {
                _file?.Save();
            }
            _file?.Dispose();

            if (!ZipFile.IsZipFile(source))
            {
                return;
            }

            _file = ZipFile.Read(source);
            ResetDirectory(_file, InternalZipDirectory.ReadZipDirectory(_file));
            Reset(OriginalPath, null);
        }
 internal InternalZipDirectory GetOrAdd([NotNull] string name)
 {
     var dic = _directories.FirstOrDefault(d => d.Name == name);
     if (dic != null) return dic;
     dic = new InternalZipDirectory(name);
     _directories.Add(dic);
     return dic;
 }
Exemplo n.º 8
0
 public InZipFileSystem(ZipFile?file)
     : base(null, "", InternalZipDirectory.ReadZipDirectory(file), file, string.Empty)
 {
     _file            = file;
     SaveAfterDispose = true;
 }