public ZipFile( ICSharpCode.SharpZipLib.Zip.ZipEntry zipArchiveEntry, ICSharpCode.SharpZipLib.Zip.ZipFile zipArchive, string path, string zipPath, ZipOption zipOption = null) : base(path, "zip") { _zipArchiveEntry = zipArchiveEntry; _zipArchive = zipArchive; _zipOption = zipOption ?? new ZipOption(); ZipPath = zipPath; }
public static void LoadZip(this VirtualResources virtualResources, string zipPath, string rootPath, ZipOption zipOption) { if (!File.Exists(zipPath)) { throw new FileNotFoundException(); } var zipArchive = new ICSharpCode.SharpZipLib.Zip.ZipFile(zipPath); zipPath = Helper.NormalizePath(zipPath); _zipArchives[zipPath] = zipArchive; var dir = GetZipVirtualPath(zipPath); var fileMaps = GetFileMaps(zipArchive); foreach (ZipEntry item in zipArchive) { var path = Path.Combine(dir, item.Name); path = Helper.NormalizePath(path); if (item.IsDirectory) { var virtualDirectory = new VirtualDirectory(path, "zip"); virtualResources._entries[path] = virtualDirectory; } else { var fileMap = fileMaps.FirstOrDefault(f => f.To == item.Name); if (fileMap != null) { fileMap.From = fileMap.From.Trim(); if (fileMap.From.StartsWith("/")) { fileMap.From = fileMap.From.Substring(1); } var fromPath = Path.Combine(rootPath, fileMap.From); var fileMapFrom = Helper.NormalizePath(fromPath); var virtualFile = new ZipFile(item, zipArchive, fileMapFrom, zipPath, zipOption); virtualResources._fileMaps[fileMapFrom] = virtualFile; } virtualResources._entries[path] = new ZipFile(item, zipArchive, path, zipPath, zipOption); while (true) { if (path == dir) { break; } path = Path.GetDirectoryName(path); if (virtualResources._entries.Where(w => w.Value is VirtualDirectory).All(a => a.Key != path)) { virtualResources._entries[path] = new VirtualDirectory(path, "zip"); } } } } }