/// <summary> /// Search file from the read-only archive index. /// </summary> /// <param name="path"></param> /// <returns></returns> public virtual IFileInfo GetFileInfo(string path) { if (IsDisposing) { throw new ObjectDisposedException(GetType().FullName); } if (path == null) { path = ""; } string canonizedPath = CanonizePath(path); ArchiveFileEntry zipFile = root.GetFile(canonizedPath); return((IFileInfo)zipFile ?? new NotFoundFileInfo(path)); }
/// <summary> /// Find file /// </summary> /// <param name="canonizedPath">file path</param> /// <returns>file or null</returns> public ArchiveFileEntry GetFile(string canonizedPath) { if (canonizedPath == null) { throw new ArgumentNullException(nameof(canonizedPath)); } if (canonizedPath == "") { return(null); } // Find slash int slashIX = canonizedPath.IndexOf('/'); // No slash, return direct file if (slashIX < 0) { ArchiveFileEntry result = null; files.TryGetValue(canonizedPath, out result); return(result); } // Got slash, find local dir string localDirectoryName = canonizedPath.Substring(0, slashIX); ArchiveDirectoryEntry localDirectory = null; if (!directories.TryGetValue(localDirectoryName, out localDirectory)) { return(null); } // Use recursion for the rest the path string restOfThePath = canonizedPath.Substring(slashIX + 1); return(localDirectory.GetFile(restOfThePath)); }