private void AddEntryToDictionary( EdataDictionaryPathEntry entry, ContentPathSplitInfo entryPathSplitInfo, EdataDictionaryRootEntry dictionaryRoot) { if (entryPathSplitInfo.SplitIndex == 0) { dictionaryRoot.AddFollowingEntry(entry); //entry.PrecedingEntry = dictionaryRoot; } else { var precedingPath = entryPathSplitInfo.GetPathToSplitIndex(); EdataDictionaryPathEntry precedingPathEntry = dictionaryRoot.SelectEntryByPath(precedingPath); var pp = precedingPathEntry as EdataDictionaryDirEntry; if (precedingPathEntry != null) { pp.AddFollowingEntry(entry); //entry.PrecedingEntry = pp; } else { throw new Exception(String.Format( "Cannot find a following precedding entry: {0}", precedingPath)); } } }
/// <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); }