/// <summary> /// Parses a string to a HFA dictionary. /// </summary> /// <param name="dictionary">The dictionary string.</param> /// <returns>The produced dictionary.</returns> /// <exception cref="ArgumentNullException">The dictionary string is null.</exception> public static HfaDictionary Parse(String dictionary) { if (dictionary == null) { throw new ArgumentNullException(nameof(dictionary), "The dictionary string is null."); } HfaDictionary result = new HfaDictionary(); Int32 startIndex = 0; while (startIndex < dictionary.Length && !dictionary[startIndex].Equals('.')) { Int32 length = GetObjectLength(dictionary, startIndex); EhfaStructureType structureType = EhfaStructureType.FromObjectDefinition(dictionary, startIndex, length, result); if (structureType == null) { continue; } result.Add(structureType.ItemName, structureType); startIndex += length; } return(result); }
/// <summary> /// Reads the file header. /// </summary> private void ReadHeader() { EhfaStructure header = new EhfaStructure(EhfaStructureType.EhfaHeaderTagType); header.Read(BaseStream); Int32 headerLocation = header.GetValue <Int32>("headerPtr"); BaseStream.Seek(headerLocation, SeekOrigin.Begin); EhfaStructure rootFile = new EhfaStructure(EhfaStructureType.EhfaFileType); rootFile.Read(BaseStream); Int32 dictionaryLocation = rootFile.GetValue <Int32>("dictionaryPtr"); Int32 rootEntryLocation = rootFile.GetValue <Int32>("rootEntryPtr"); BaseStream.Seek(dictionaryLocation, SeekOrigin.Begin); _dictionary = HfaDictionary.Parse(ReadDictionaryString()); BaseStream.Seek(rootEntryLocation, SeekOrigin.Begin); _rootEntry = new EhfaEntry(_dictionary["Ehfa_Entry"], _dictionary); _rootEntry.Read(BaseStream); }