public void Save(IEnumerable <object> items, IEnumerable <IDetector> detectors, IDataReaderPool dataReaderPool, string directory, IProgressReporter progressReporter, bool createForensicIntegrityLog) { PreConditions.Argument("items").Value(items).IsNotNull().And.IsNotEmpty(); PreConditions.Argument("detectors").Value(detectors).IsNotNull().And.DoesNotContainNull(); PreConditions.Argument("dataReaderPool").Value(dataReaderPool).IsNotNull(); PreConditions.Argument("directory").Value(directory).IsNotNull().And.IsNotEmpty(); PreConditions.Argument("progressReporter").Value(progressReporter).IsNotNull(); if (progressReporter.CancellationPending) { return; } var overallProgressReporter = new OverallProgressReporter(progressReporter); overallProgressReporter.CountNumberOfParts(items); var handledContainers = new HandledContainers(); int numSavedFiles = 0; handledContainers.ClearHandledFragmentedContainers(); foreach (object item in items) { string path = Path.Combine(directory, ReplaceIllegalPathCharactersByUnderscore(GetFileName(item))); numSavedFiles += SaveItem(item, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog); if (overallProgressReporter.CancellationPending) { break; } } }
/// <summary> /// Saves the <paramref name="codecStream"/> in the given <paramref name="path"/>. /// </summary> /// <param name="path">The directory to save the file to</param> /// <param name="codecStream">The <see cref="ICodecStream"/> to save</param> /// <returns>The number of files saved</returns> private int SaveCodecStream(ICodecStream codecStream, IDataReaderPool dataReaderPool, string path, OverallProgressReporter overallProgressReporter, HandledContainers handledContainers, bool createForensicIntegrityLog) { return(Write(codecStream, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog) == true ? 1 : 0); }
/// <summary> /// Saves a <paramref name="dataBlock"/> and its codec streams. /// </summary> /// <param name="dataBlock">The data block to save</param> /// <param name="dataReaderPool">The shared pool of file data readers</param> /// <param name="path">The directory in which to store the files</param> /// <param name="overallProgressReporter"></param> /// <param name="handledContainers"></param> /// <param name="forensicIntegrityLogFile"></param> /// <returns>The number of files saved</returns> private int SaveDataBlock(IDataBlock dataBlock, IDataReaderPool dataReaderPool, string path, OverallProgressReporter overallProgressReporter, HandledContainers handledContainers, bool createForensicIntegrityLog) { if (string.IsNullOrEmpty(path) || dataBlock == null) { return(0); } int numFullFiles = 0; path += string.Format("_{0}", ReplaceIllegalPathCharactersByUnderscore(dataBlock.Detectors.First().Name)); if (Write(dataBlock, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog)) { numFullFiles++; // Save all detectables foreach (ICodecStream codecStream in dataBlock.CodecStreams) { string fileName = string.Format("{0}_extracted_{1}_stream", path, ReplaceIllegalPathCharactersByUnderscore(codecStream.DataFormat.ToString())); numFullFiles += SaveCodecStream(codecStream, dataReaderPool, fileName, overallProgressReporter, handledContainers, createForensicIntegrityLog); } } return(numFullFiles); }
/// <summary> /// Saves all data blocks (and codec streams) for one <paramref name="inputFile"/>. /// </summary> /// <param name="inputFile">The input file to save</param> /// <param name="path">The directory in which to store the files</param> /// <returns>The number of files saved</returns> private int SaveInputFile(IInputFile inputFile, IDataReaderPool dataReaderPool, string path, OverallProgressReporter overallProgressReporter, HandledContainers handledContainers, bool createForensicIntegrityLog) { int numFullFiles = 0; foreach (IDataBlock dataBlock in inputFile.Project.GetDataBlocks(inputFile)) { numFullFiles += SaveDataBlock(dataBlock, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog); } return(numFullFiles); }
private int SaveItem(object item, IDataReaderPool dataReaderPool, string path, OverallProgressReporter overallProgressReporter, HandledContainers handledContainers, bool createForensicIntegrityLog) { IInputFile inputFile = item as IInputFile; if (inputFile != null) { return(SaveInputFile(inputFile, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog)); } IDataBlock dataBlock = item as IDataBlock; if (dataBlock != null) { return(SaveDataBlock(dataBlock, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog)); } ICodecStream codecStream = item as ICodecStream; if (codecStream != null) { path = string.Format("{0}__{1}", path, ReplaceIllegalPathCharactersByUnderscore(codecStream.Name)); return(SaveCodecStream(codecStream, dataReaderPool, path, overallProgressReporter, handledContainers, createForensicIntegrityLog)); } return(0); // TODO: is this an error? }