internal static void ContainsFile(AnnoRDA.Folder folder, FileSpec fileSpec) { if (fileSpec == null) { throw new ArgumentNullException("fileSpec"); } IEnumerable <string> folderPath; string fileName = fileSpec.Path.SplitOffLast(out folderPath); AnnoRDA.Folder subFolder = folderPath.Any() ? ContainsFolder(folder, folderPath, Enumerable.Empty <string>()) : folder; if (subFolder == null) { throw new Xunit.Sdk.AssertActualExpectedException( String.Join(PathSeparator, folderPath), folder, "Assert.ContainsFile() Failure", "Folder not found", "In value" ); } else { AnnoRDA.File file = subFolder.Files.FirstOrDefault((f) => f.Name == fileName); FileMatches(fileSpec, file, folder); } }
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); }
public static bool IsContainerFile(AnnoRDA.File file) { if (file.Name == "rd3d.data") { return(true); } else { string extension = GetExtension(file.Name); return(CONTAINER_FILE_EXTENSIONS.Contains(extension)); } }
public bool OnAttribute(string name, AttributeValue value) { switch (name) { case Tags.BuiltinTags.Names.String: { this.currentFile = new File(value.GetUnicodeString()); this.parentFolder.Add(this.currentFile); return(true); } default: return(false); } }
private void WriteFileContents(AnnoRDA.File file, string fullFilePath, ArchiveFileMap archiveFiles, IList <AnnoRDA.BlockContentsSource> residentBuffers) { this.WriteListStart(); this.WriteAttribute(FileSystemTags.Attributes.Names.FileName, (string)fullFilePath); int archiveFileIndex = archiveFiles.GetIndexForLoadPath(file.ContentsSource.BlockContentsSource.ArchiveFilePath); if (archiveFileIndex < 0) { throw new System.ArgumentException("archive file path not present in archive file map"); } if (archiveFileIndex != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.ArchiveFileIndex, (int)archiveFileIndex); } if (file.ContentsSource.PositionInBlock != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.Position, (long)file.ContentsSource.PositionInBlock); } if (file.ContentsSource.CompressedSize != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.CompressedSize, (long)file.ContentsSource.CompressedSize); } if (file.ContentsSource.UncompressedSize != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.UncompressedSize, (long)file.ContentsSource.UncompressedSize); } if (file.ModificationTimestamp != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.ModificationTime, (long)file.ModificationTimestamp); } if (file.ContentsSource.BlockContentsSource.Flags.Value != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.Flags, (int)file.ContentsSource.BlockContentsSource.Flags.Value); } if (file.ContentsSource.BlockContentsSource.Flags.IsMemoryResident) { int residentBufferIndex = this.GetIndexInListAddIfMissing(residentBuffers, file.ContentsSource.BlockContentsSource); if (residentBufferIndex != 0) { this.WriteAttribute(FileSystemTags.Attributes.Names.ResidentBufferIndex, (int)residentBufferIndex); } } this.WriteListEnd(); }
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 FileMapContentsState(AnnoRDA.File file, Writer.ArchiveFileMap archiveFiles) { this.file = file; this.archiveFiles = archiveFiles; }
public void OnStructureEnd(IState state) { this.currentFile = null; }
internal static void FileMatches(FileSpec expected, AnnoRDA.File actual, AnnoRDA.Folder searchRootFolder) { if (expected == null) { throw new ArgumentNullException("expected"); } if (actual == null) { throw new Xunit.Sdk.AssertActualExpectedException( String.Join(PathSeparator, expected.Path), searchRootFolder, "Assert.ContainsFile() Failure", "File not found", "In value" ); } else { if (expected.DataOffset.HasValue) { Equal(expected.DataOffset.Value, actual.ContentsSource.PositionInBlock); } if (expected.IsCompressed.HasValue) { Equal(expected.IsCompressed.Value, actual.ContentsSource.BlockContentsSource.Flags.IsCompressed); } if (expected.IsEncrypted.HasValue) { Equal(expected.IsEncrypted.Value, actual.ContentsSource.BlockContentsSource.Flags.IsEncrypted); } if (expected.IsDeleted.HasValue) { Equal(expected.IsDeleted.Value, actual.ContentsSource.BlockContentsSource.Flags.IsDeleted); } if (expected.CompressedFileSize.HasValue) { Equal(expected.CompressedFileSize.Value, actual.ContentsSource.CompressedSize); } if (expected.UncompressedFileSize.HasValue) { Equal(expected.UncompressedFileSize.Value, actual.ContentsSource.UncompressedSize); } if (expected.ModificationDate.HasValue) { Equal(expected.ModificationDate.Value, actual.ModificationDate); } if (expected.ModificationTimestamp.HasValue) { Equal(expected.ModificationTimestamp.Value, actual.ModificationTimestamp); } if (expected.Contents != null) { using (Stream contentStream = actual.ContentsSource.GetReadStream()) { using (StreamReader reader = new StreamReader(contentStream)) { Equal(expected.Contents, reader.ReadToEnd()); } } } } }