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 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; }
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 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); }
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); }
public InZipFileSystem(ZipFile? file) : base(null, "zip::", InternalZipDirectory.ReadZipDirectory(file), file, string.Empty) { _file = file; SaveAfterDispose = true; }