/// <summary> /// Extract a found entry /// </summary> /// <param name="s">Instance of the search result</param> /// <param name="savePath">Path to be saved to</param> /// <returns>True if successful</returns> public bool extract(SearchResultInstance s, string savePath) { try { using (ZipArchive zip = ZipFile.Open(Path, ZipArchiveMode.Read)) { if (!s.IsDir) { foreach (ZipArchiveEntry entry in zip.GetRawEntries().Where(entry => entry.FullName == s.FolderPath)) { entry.ExtractToFile(savePath); } } else { var result = from currEntry in zip.GetRawEntries() where System.IO.Path.GetDirectoryName(currEntry.FullName) == System.IO.Path.GetDirectoryName(s.FolderPath) where !String.IsNullOrEmpty(currEntry.Name) select currEntry; foreach (ZipArchiveEntry entry in result) { string endPath = System.IO.Path.Combine(savePath, entry.FullName); if (!Directory.Exists(System.IO.Path.GetDirectoryName(endPath))) { Directory.CreateDirectory(System.IO.Path.GetDirectoryName(endPath)); } entry.ExtractToFile(endPath); } } } return(true); } catch { return(false); } }
/// <summary> /// Extract a found entry /// </summary> /// <param name="s">Instance of the search result</param> /// <param name="savePath">Path to be saved to</param> /// <returns>True if successful</returns> public bool extract(SearchResultInstance s, string savePath) { try { using (SevenZipExtractor extr = new SevenZipExtractor(Path)) if (s.IsDir) { extr.ExtractFiles(savePath, extr.ArchiveFileData.Where(archiveFileInfo => archiveFileInfo.FileName.StartsWith(s.FolderPath)).Select(t => t.Index).ToArray()); } else { using (FileStream fs = new FileStream(savePath, FileMode.Create)) //replace empty string with desired destination { extr.ExtractFile(s.FolderPath, fs); } } return(true); } catch { return(false); } }