public void IsSelectFileEntryByPathWorkingTest() { string path = @"pc\textures\assets\file1.tgv"; EdataDictionaryDirEntry a1 = new EdataDictionaryDirEntry(@"pc\"); EdataDictionaryDirEntry a2 = new EdataDictionaryDirEntry(@"textures\"); EdataDictionaryDirEntry a2a = new EdataDictionaryDirEntry(@"textures2\"); EdataDictionaryDirEntry a3a = new EdataDictionaryDirEntry(@"assets2\"); EdataDictionaryDirEntry a3 = new EdataDictionaryDirEntry(@"assets\"); EdataDictionaryFileEntry a4 = new EdataDictionaryFileEntry(@"file1.tgv"); EdataDictionaryFileEntry a4a = new EdataDictionaryFileEntry(@"file1.tgv"); a1.AddFollowingEntry(a2a); a1.AddFollowingEntry(a2); a2.AddFollowingEntry(a3); a2a.AddFollowingEntry(a3a); a3.AddFollowingEntry(a4); a3a.AddFollowingEntry(a4a); EdataDictionaryPathEntry expected1 = a4; EdataDictionaryPathEntry value1 = a1.SelectEntryByPath(path); Assert.AreEqual(value1, expected1); String expected2 = "file1.tgv"; String value2 = a1.SelectEntryByPath(path).PathPart; Assert.AreEqual(value2, expected2); }
/// <summary> /// Reads Edata version 2 dictionary entries /// </summary> /// <param name="source"></param> /// <param name="header"></param> /// <param name="token"></param> /// <returns></returns> protected virtual EdataDictionaryRootEntry ReadDcitionaryEntries( Stream source, uint dictOffset, uint dictLength) { EdataDictionaryRootEntry dictRoot = new EdataDictionaryRootEntry(); EdataDictionaryDirEntry workingDir = null; source.Seek(dictOffset + dictRoot.Length, SeekOrigin.Begin); long dictEnd = dictOffset + dictLength; while (source.Position < dictEnd) { var buffer = new byte[4]; source.Read(buffer, 0, 4); int entrysFirstFour = BitConverter.ToInt32(buffer, 0); source.Read(buffer, 0, 4); int entrysSecondFour = BitConverter.ToInt32(buffer, 0); bool isFileEntry = (entrysFirstFour == 0); if (isFileEntry) { int entryLength = entrysSecondFour; //source.Read(buffer, 0, 4); //int relevanceLength = BitConverter.ToInt32(buffer, 0); buffer = new byte[8]; source.Read(buffer, 0, buffer.Length); long offset = BitConverter.ToInt64(buffer, 0); source.Read(buffer, 0, buffer.Length); long length = BitConverter.ToInt64(buffer, 0); var checksum = new byte[16]; source.Read(checksum, 0, checksum.Length); String pathPart = MiscUtilities.ReadString(source); if (pathPart.Length % 2 == 0) { source.Seek(1, SeekOrigin.Current); } var newFile = new EdataDictionaryFileEntry(pathPart, entryLength, offset, length, checksum); if (workingDir != null) { workingDir.AddFollowingEntry(newFile); //Usuwamy tylko jeśli pojawia się wpis pliku oznaczony jako kończący ścieżkę. if (newFile.IsEndingEntry()) { EdataDictionaryDirEntry previousEntry = null; do { previousEntry = workingDir; workingDir = workingDir.PrecedingEntry as EdataDictionaryDirEntry; }while (workingDir != null && previousEntry.IsEndingEntry()); } } else { dictRoot.AddFollowingEntry(newFile); } } else //isDirEntry { int entryLength = entrysFirstFour; int relevanceLength = entrysSecondFour; //source.Read(buffer, 0, 4); //int relevanceLength = BitConverter.ToInt32(buffer, 0); String pathPart = MiscUtilities.ReadString(source); if (pathPart.Length % 2 == 0) { source.Seek(1, SeekOrigin.Current); } var newDir = new EdataDictionaryDirEntry(pathPart, entryLength, relevanceLength); if (workingDir != null) { workingDir.AddFollowingEntry(newDir); } else { dictRoot.AddFollowingEntry(newDir); } workingDir = newDir; } } return(dictRoot); }