public AnnoRDA.File AddFileToFolder(AnnoRDA.Folder folder, FileHeader file, IEnumerable <string> filePathComponents, AnnoRDA.BlockContentsSource blockContentsSource) { if (!filePathComponents.Any()) { throw new ArgumentException("filePathComponents cannot be empty", "filePathComponents"); } string currentName = filePathComponents.First(); IEnumerable <string> filePathComponentsRemaining = filePathComponents.Skip(1); if (filePathComponentsRemaining.Any()) { AnnoRDA.Folder currentFolder = folder.Folders.FirstOrDefault((f) => f.Name == currentName); if (currentFolder == null) { currentFolder = new Folder(currentName); folder.Add(currentFolder); } return(this.AddFileToFolder(currentFolder, file, filePathComponentsRemaining, blockContentsSource)); } else { AnnoRDA.File rdaFile = new File(currentName) { ModificationTimestamp = file.ModificationTimestamp, ContentsSource = new AnnoRDA.FileContentsSource(blockContentsSource, file.DataOffset, file.CompressedFileSize, file.UncompressedFileSize), }; folder.Add(rdaFile); return(rdaFile); } }
public void AddContainedFilesToFileSystem(Context context, FileHeader fileHeader, AnnoRDA.File file, AnnoRDA.BlockContentsSource blockContentsSource) { if (!IsContainerFile(file)) { return; } using (var subContainerStream = file.ContentsSource.GetReadStream()) { var transformer = new PrefixingFileHeaderTransformer(fileHeader.Path + SUB_CONTAINER_SEPARATOR, fileHeader.DataOffset); FileSystem subFileSystem; try { using (var subContext = new Context(context.ContainerFilePath, subContainerStream, true, transformer)) { subFileSystem = this.Load(subContext, null, System.Threading.CancellationToken.None); } } catch (FormatException) { // not a container file return; } context.FileSystem.OverwriteWith(subFileSystem, null, System.Threading.CancellationToken.None); } }
public AnnoRDA.File AddFileToFileSystem(Context context, FileHeader fileHeader, AnnoRDA.BlockContentsSource blockContentsSource) { string[] filePathComponents = fileHeader.Path.Split('/'); AnnoRDA.File file = this.AddFileToFolder(context.FileSystem.Root, fileHeader, filePathComponents, blockContentsSource); this.AddContainedFilesToFileSystem(context, fileHeader, file, blockContentsSource); return(file); }