public ArchiveExtraction ReadFromFile(string archiveFileName, string metadataFileName) { Log.Information("Reading archive from file: " + archiveFileName); Log.Information("Reading archive metadata from file: " + metadataFileName); ArchiveExtraction archiveExtraction = _archiveExtractor.Extract(archiveFileName); archiveExtraction.ArchiveType = _archiveIdentifier.Identify(metadataFileName); return(archiveExtraction); }
private void UnpackIfRequired() { RootPath = Path.Combine(ExtractPath, Name); if (Rewrite || IsDirectoryNotExistsOrEmpty()) { using (var zipFileNameMutex = new Mutex(false, ConvertToValidMutexName(ArchiveName))) { if (!zipFileNameMutex.WaitOne()) { return; } try { if (Rewrite || IsDirectoryNotExistsOrEmpty()) { Logger.LogInfo($"{Name} extraction..."); if (DirectoryExt.Exists(RootPath)) { DirectoryExt.Delete(RootPath); } IArchiveExtractor extractor = SevenZipExtractor.Is7zInstalled ? (IArchiveExtractor) new SevenZipExtractor() : new StandardArchiveExtractor(); extractor.Logger = Logger; extractor.Extract(ArchiveName, RootPath); if (RemoveAfterExtraction) { FileExt.Delete(ArchiveName); } Logger.LogInfo($"{Name} extracted."); string[] directories = DirectoryExt.GetDirectories(RootPath); if (directories.Length == 1) { DirectoryExt.CreateDirectory(RootPath); foreach (string fileSystemEntry in DirectoryExt.EnumerateFileSystemEntries(directories[0])) { string shortName = Path.GetFileName(fileSystemEntry); string newName = Path.Combine(RootPath, shortName); if (FileExt.Exists(fileSystemEntry)) { FileExt.Move(fileSystemEntry, newName); } else { try { DirectoryExt.Move(fileSystemEntry, newName); } catch { DirectoryExt.Move(fileSystemEntry, newName); } } } DirectoryExt.Delete(directories[0]); } } } catch (Exception ex) when(!(ex is ThreadAbortException)) { RootPath = null; Logger.LogError(ex); } finally { zipFileNameMutex.ReleaseMutex(); } } } }