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); } }
private void WriteFolderContents(AnnoRDA.Folder folder, string fullPathSoFar, ArchiveFileMap archiveFiles, IList <AnnoRDA.BlockContentsSource> residentBuffers) { this.WriteListStart(); this.WritePathMap(folder.Folders, fullPathSoFar, archiveFiles, residentBuffers); this.WriteFileMap(folder.Files, fullPathSoFar, archiveFiles, residentBuffers); this.WriteListEnd(); }
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); } }
internal static void ContainsFolder(AnnoRDA.Folder folder, string path) { if (path == null) { throw new ArgumentNullException("path"); } ContainsFolder(folder, Enumerable.Repeat(path, 1)); }
public bool OnAttribute(string name, AttributeValue value) { switch (name) { case Tags.BuiltinTags.Names.String: { this.currentFolder = new Folder(value.GetUnicodeString()); this.parentFolder.Add(this.currentFolder); return(true); } default: return(false); } }
internal static void ContainsFolder(AnnoRDA.Folder folder, IEnumerable <string> path) { if (path == null) { throw new ArgumentNullException("path"); } if (!path.Any()) { throw new ArgumentException("path cannot be empty", "path"); } ContainsFolder(folder, path, Enumerable.Empty <string>()); }
public void TestOverwriteFileInFileSystem() { var folderPath = new AnnoRDA.Folder("path"); { var folderTo = new AnnoRDA.Folder("to"); { folderTo.Add(new AnnoRDA.File("file.txt") { ModificationDate = new DateTime(), }); } folderPath.Add(folderTo); } var file = new AnnoRDA.FileEntities.FileHeader() { Path = "path/to/file.txt", DataOffset = 11111111, CompressedFileSize = 36960, UncompressedFileSize = 36960, ModificationTimestamp = 1448398881, }; var loader = new ContainerFileLoader(); AnnoRDA.FileSystem fileSystem; using (var context = new ContainerFileLoader.Context("dummy.rda", TestData.GetStream(), false, new PassThroughFileHeaderTransformer())) { fileSystem = context.FileSystem; fileSystem.Root.Add(folderPath); loader.AddFileToFileSystem(context, file, TestData.GetDummyBlockContentsSource()); } Assert.FolderAndFileCountAreEqual(1, 0, fileSystem.Root); Assert.FolderAndFileCountAreEqual(1, 0, fileSystem.Root.Folders.First()); Assert.FolderAndFileCountAreEqual(0, 1, fileSystem.Root.Folders.First().Folders.First()); Assert.ContainsFile(fileSystem, new Assert.FileSpec("path", "to", "file.txt") { CompressedFileSize = 36960, UncompressedFileSize = 36960, ModificationTimestamp = 1448398881, }); }
private static AnnoRDA.Folder ContainsFolder(AnnoRDA.Folder folder, IEnumerable <string> path, IEnumerable <string> pathSoFar) { if (folder == null) { throw new ArgumentNullException("folder"); } if (path == null) { throw new ArgumentNullException("path"); } if (pathSoFar == null) { throw new ArgumentNullException("pathSoFar"); } string first = path.First(); IEnumerable <string> newPathSoFar = pathSoFar.Concat(Enumerable.Repeat(first, 1)); AnnoRDA.Folder subFolder = folder.Folders.FirstOrDefault((f) => f.Name == first); if (subFolder == null) { throw new Xunit.Sdk.AssertActualExpectedException( String.Join(PathSeparator, newPathSoFar), folder, "Assert.ContainsFolder() Failure", "Not found", "In value" ); } IEnumerable <string> restPath = path.Skip(1); if (restPath.Any()) { return(ContainsFolder(subFolder, restPath, newPathSoFar)); } else { return(subFolder); } }
public FileMapState(AnnoRDA.Folder parentFolder, Writer.ArchiveFileMap archiveFiles) { this.parentFolder = parentFolder; this.archiveFiles = archiveFiles; }
public PathMapContentsState(AnnoRDA.Folder folder, Writer.ArchiveFileMap archiveFiles) { this.folder = folder; this.archiveFiles = archiveFiles; }
public void OnStructureEnd(IState state) { this.currentFolder = null; }
public void TestMergeFileSystemsWithFilesAndFolders() { AnnoRDA.FileSystem baseFS = new FileSystem(); baseFS.Root.Add(new File("root file")); var baseFSFolder1 = new AnnoRDA.Folder("Max Design"); { baseFSFolder1.Add(new File("1602") { ModificationDate = new DateTime(1998, 9, 24, 0, 0, 0, DateTimeKind.Utc) }); } baseFS.Root.Add(baseFSFolder1); var baseFSFolder2 = new AnnoRDA.Folder("Related Designs"); { baseFSFolder2.Add(new File("1701") { ModificationDate = new DateTime(2006, 10, 25, 0, 0, 0, DateTimeKind.Utc) }); baseFSFolder2.Add(new File("2070") { ModificationDate = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc) }); } baseFS.Root.Add(baseFSFolder2); AnnoRDA.FileSystem overwriteFS = new FileSystem(); var overwriteFSFolder1 = new AnnoRDA.Folder("Max Design"); { overwriteFSFolder1.Add(new File("1503") { ModificationDate = new DateTime(2003, 3, 23, 0, 0, 0, DateTimeKind.Utc) }); } overwriteFS.Root.Add(overwriteFSFolder1); var overwriteFSFolder2 = new AnnoRDA.Folder("Related Designs"); { overwriteFSFolder2.Add(new File("1404") { ModificationDate = new DateTime(2009, 6, 25, 0, 0, 0, DateTimeKind.Utc) }); overwriteFSFolder2.Add(new File("2070") { ModificationDate = new DateTime(2011, 11, 17, 0, 0, 0, DateTimeKind.Utc) }); } overwriteFS.Root.Add(overwriteFSFolder2); var overwriteFSFolder3 = new AnnoRDA.Folder("Blue Byte"); { overwriteFSFolder3.Add(new File("1404") { ModificationDate = new DateTime(2009, 6, 25, 0, 0, 0, DateTimeKind.Utc) }); overwriteFSFolder3.Add(new File("2070") { ModificationDate = new DateTime(2011, 11, 17, 0, 0, 0, DateTimeKind.Utc) }); overwriteFSFolder3.Add(new File("2205") { ModificationDate = new DateTime(2015, 11, 3, 0, 0, 0, DateTimeKind.Utc) }); } overwriteFS.Root.Add(overwriteFSFolder3); baseFS.OverwriteWith(overwriteFS, null, System.Threading.CancellationToken.None); Assert.FolderAndFileCountAreEqual(3, 1, baseFS); Assert.ContainsFile(baseFS, new Assert.FileSpec("root file")); Assert.ContainsFile(baseFS, new Assert.FileSpec("Max Design", "1503") { ModificationDate = new DateTime(2003, 3, 23, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Max Design", "1602") { ModificationDate = new DateTime(1998, 9, 24, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Related Designs", "1701") { ModificationDate = new DateTime(2006, 10, 25, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Related Designs", "1404") { ModificationDate = new DateTime(2009, 6, 25, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Related Designs", "2070") { ModificationDate = new DateTime(2011, 11, 17, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Blue Byte", "1404") { ModificationDate = new DateTime(2009, 6, 25, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Blue Byte", "2070") { ModificationDate = new DateTime(2011, 11, 17, 0, 0, 0, DateTimeKind.Utc) }); Assert.ContainsFile(baseFS, new Assert.FileSpec("Blue Byte", "2205") { ModificationDate = new DateTime(2015, 11, 3, 0, 0, 0, DateTimeKind.Utc) }); }
internal static void FolderAndFileCountAreEqual(int expectedFolders, int expectedFiles, AnnoRDA.Folder actual) { NotNull(actual); Equal(expectedFolders, actual.Folders.Count()); Equal(expectedFiles, actual.Files.Count()); }
internal static void Empty(AnnoRDA.Folder actual) { FolderAndFileCountAreEqual(0, 0, actual); }
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()); } } } } }