/// <summary> /// Reads section keys information which can be used to match "ref lib" component names into /// usable compound storage section names. /// <para> /// Data read can be accessed through the <see cref="GetSectionKeyFromRefName"/> method. /// </para> /// </summary> private void ReadSectionKeys() { SectionKeys.Clear(); var data = Cf.TryGetStream("SectionKeys"); if (data == null) { return; } BeginContext("SectionKeys"); using (var reader = data.GetBinaryReader()) { var parameters = ReadBlock(reader, size => ReadParameters(reader, size)); var keyCount = parameters["KEYCOUNT"].AsIntOrDefault(); for (int i = 0; i < keyCount; ++i) { var libRef = parameters[$"LIBREF{i}"].AsString(); var sectionKey = parameters[$"SECTIONKEY{i}"].AsString(); SectionKeys.Add(libRef, sectionKey); } } EndContext(); }
/// <summary> /// Reads section keys information which can be used to match "ref lib" component names into /// usable compound storage section names. /// <para> /// Data read can be accessed through the <see cref="GetSectionKeyFromRefName"/> method. /// </para> /// </summary> private void ReadSectionKeys() { SectionKeys.Clear(); var data = Cf.TryGetStream("SectionKeys"); if (data == null) { return; } BeginContext("SectionKeys"); using (var reader = data.GetBinaryReader()) { var keyCount = reader.ReadInt32(); for (int i = 0; i < keyCount; ++i) { var libRef = ReadPascalString(reader); var sectionKey = ReadStringBlock(reader); SectionKeys.Add(libRef, sectionKey); } } EndContext(); }
/// <summary> /// Get the name of the section storage key to be used to read a component "ref name". /// <para> /// This allows for giving an alias for reading a component that has a name that is /// not supported by the compound file storage format because of its limitations. /// </para> /// <para> /// In case the <see cref="DoReadSectionKeys(Dictionary{string, string})"/> didn't /// properly provide a relevant list of "ref name" to section keys, we attempt the /// to guess the possible way the component name can be mangled to fit the compound /// storage format naming limitations. /// </para> /// </summary> /// <param name="refName">Component reference name.</param> /// <returns> /// A storage section key where to access the data for the given <paramref name="refName"/>. /// </returns> protected string GetSectionKeyFromRefName(string refName) { if (SectionKeys.TryGetValue(refName, out var result)) { return(result); } else { return(refName?.Substring(0, refName.Length > 31 ? 31 : refName.Length).Replace('/', '_')); } }