/// <summary> /// Initializes a new instance of the <see cref="ProcessCommandHandler"/> class. /// </summary> /// <param name="module">The command handler module.</param> /// <param name="mediator">The mediator.</param> /// <param name="configuration">The configuration.</param> /// <param name="archiveReader">The archive reader.</param> /// <param name="archiveExtractor">The archive extractor.</param> /// <param name="fileSystemStrategy">The file system strategy.</param> public ProcessCommandHandler( ICommandHandlerModule module, IMediator mediator, IAppConfiguration configuration, IArchiveReader archiveReader, IArchiveExtractor archiveExtractor, IFileSystemStrategy fileSystemStrategy) : base(module) { this.mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.archiveReader = archiveReader ?? throw new ArgumentNullException(nameof(archiveReader)); this.archiveExtractor = archiveExtractor ?? throw new ArgumentNullException(nameof(archiveExtractor)); Ensure.ArgumentNotNull(fileSystemStrategy, nameof(fileSystemStrategy)); fileSystem = fileSystemStrategy.Create(configuration.Options.WorkingDirectory); }
/// <summary> /// Initializes a new instance of the <see cref="ImageService"/> class. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="archiveReader">The archive reader.</param> /// <param name="archiveExtractor">The archive extractor.</param> /// <param name="fileSystemStrategy">The file system strategy.</param> /// <param name="appInfoFactory">The application information factory.</param> /// <param name="jsonWriter">The JSON writer.</param> /// <param name="imageExtractor">The image extractor.</param> /// <param name="gifImageWriter">The GIF image writer.</param> public ImageService( IAppConfiguration configuration, IArchiveReader archiveReader, IArchiveExtractor archiveExtractor, IFileSystemStrategy fileSystemStrategy, IAppInfoFactory appInfoFactory, IDefaultJsonWriter jsonWriter, IImageExtractor imageExtractor, IGifImageWriter gifImageWriter) { this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.archiveReader = archiveReader ?? throw new ArgumentNullException(nameof(archiveReader)); this.archiveExtractor = archiveExtractor ?? throw new ArgumentNullException(nameof(archiveExtractor)); this.fileSystemStrategy = fileSystemStrategy ?? throw new ArgumentNullException(nameof(fileSystemStrategy)); this.appInfoFactory = appInfoFactory ?? throw new ArgumentNullException(nameof(appInfoFactory)); this.jsonWriter = jsonWriter ?? throw new ArgumentNullException(nameof(jsonWriter)); this.imageExtractor = imageExtractor ?? throw new ArgumentNullException(nameof(imageExtractor)); this.gifImageWriter = gifImageWriter ?? throw new ArgumentNullException(nameof(gifImageWriter)); }
private bool ExtractVideoFiles(string fullPath) { _log.WriteEntry("Checking archive for video files: " + fullPath); bool filesExtracted = false; using (var archive = ArchiveFactory.Open(fullPath)) { IArchiveExtractor extractor = ArchiveExtractorFactory.Create(archive.Type); foreach (IExtractEntry entry in extractor.GetEntries(archive)) { if (_settings.GetVideoExtensions().Select(e => "." + e).Contains(entry.Extension)) { var info = new FileInfo(fullPath); entry.ExtractToFile(Path.Combine(info.DirectoryName, entry.Filename)); filesExtracted = true; } } } return(filesExtracted); }
/// <summary> /// Clears all controls. /// </summary> public void ClearView() { _archiveContent = null; _archiveExtractor = null; _metadataListView.Items.Clear(); _archiveItemInfoListView.Items.Clear(); _foldersTreeView.Nodes.Clear(); _attributesTabPage.Text = "Attributes (0)"; _fileIdLabel.Text = ""; _classificationLabel.Text = ""; _idMatchTypeLabel.Text = ""; _textSourceLabel.Text = ""; _contentResultLabel.Text = ""; _errorMessageLabel.Text = ""; _sha1BinaryHashLabel.Text = ""; _sha1ContentHashLabel.Text = ""; _fileEntropyLabel.Text = ""; _isEncryptedLabel.Text = ""; _attributesTextBox.Text = ""; _totalItemCountLabel.Text = ""; }
/// <summary> /// Displays archive content. /// </summary> /// <param name="archiveContent"></param> /// <param name="archiveExtractor"></param> /// <param name="filename"></param> /// <param name="filelength"></param> public void UpdateContentView(ArchiveContent archiveContent, IArchiveExtractor archiveExtractor, string filename, long filelength) { ClearView(); _archiveContent = archiveContent; _archiveExtractor = archiveExtractor; _fileNameLabel.Text = filename; _fileSizeLabel.Text = string.Format("{0:###,###,###,###}", filelength); if (_archiveContent == null) { return; } _fileIdLabel.Text = archiveContent.FormatId.ID.ToString(); _classificationLabel.Text = archiveContent.FormatId.Classification.ToString(); _idMatchTypeLabel.Text = archiveContent.FormatId.MatchType.ToString(); _textSourceLabel.Text = archiveContent.TextSourceType.ToString(); _contentResultLabel.Text = archiveContent.Result.ToString(); _errorMessageLabel.Text = archiveContent.ErrorMessage != null ? archiveContent.ErrorMessage : ""; _sha1BinaryHashLabel.Text = archiveContent.SHA1BinaryHash != null ? archiveContent.SHA1BinaryHash : ""; _sha1ContentHashLabel.Text = archiveContent.SHA1ContentHash != null ? archiveContent.SHA1ContentHash : ""; _fileEntropyLabel.Text = archiveContent.FileEntropy != null?archiveContent.FileEntropy.Value.ToString("F7") : ""; _isEncryptedLabel.Text = archiveContent.FormatId.IsEncrypted.ToString(); _totalItemCountLabel.Text = archiveContent.ItemCount.ToString(); // // Set metadata: // _metdataTabPage.Text = string.Format("Metadata ({0})", archiveContent.Metadata.Count + archiveContent.CustomMetadata.Count); if (archiveContent.Metadata.Count > 0 || archiveContent.CustomMetadata.Count > 0) { MetadataHelper.PopulateListViewWithMetadata(_metadataListView, archiveContent.Metadata); MetadataHelper.PopulateListViewWithMetadata(_metadataListView, archiveContent.CustomMetadata, false); } UpdateArchiveItemListView(); // // Set Attributes: // if (archiveContent.Attributes.Count > 0) { var attributeBuilder = new StringBuilder(); foreach (var flag in archiveContent.Attributes) { attributeBuilder.AppendLine(flag.ToString()); } _attributesTextBox.Text = attributeBuilder.ToString(); } else { _attributesTextBox.Text = ""; } _attributesTabPage.Text = string.Format("Attributes ({0})", archiveContent.Attributes.Count); // // // Set folders (note: not all archives have internally stored email folders): // if (archiveContent.Root != null) { SetFolders(archiveContent.Root, _foldersTreeView); if (_foldersTreeView.Nodes.Count > 0) { _foldersTreeView.ExpandAll(); _foldersTreeView.SelectedNode = _foldersTreeView.Nodes[0]; } } }
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(); } } } }
/// <summary> /// Constructor. /// </summary> /// <param name="archiveContent"></param> /// <param name="archiveExtractor"></param> /// <param name="host"></param> public ArchiveExtractorHelper(ArchiveContent archiveContent, IArchiveExtractor archiveExtractor, IHostUI host) { _archiveContent = archiveContent; _archiveExtractor = archiveExtractor; _hostUI = host; }
public ArchiveExtractionReader(IArchiveExtractor archiveExtractor, IArchiveIdentifier archiveIdentifier) { _archiveExtractor = archiveExtractor; _archiveIdentifier = archiveIdentifier; }