TESVSnip.Domain.Model.Plugin.LoadPluginData C# (CSharp) Method

LoadPluginData() private method

private LoadPluginData ( BinaryReader br, bool headerOnly, bool>.Func includeFilter ) : void
br System.IO.BinaryReader
headerOnly bool
includeFilter bool>.Func
return void
        private void LoadPluginData(BinaryReader br, bool headerOnly, Func<string, bool> includeFilter)
        {
            bool oldHoldUpdates = HoldUpdates;
            try
            {
                string s;
                uint recsize;

                this.Filtered = includeFilter != null;

                HoldUpdates = true;
                Decompressor.Init();

                s = ReadRecName(br);
                if (s != this.define.HEDRType)
                {
                    throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)");
                }

                // Check for file version by checking the position of the HEDR field in the file. (ie. how big are the record header.)
                br.BaseStream.Position = define.HEDROffset;
                s = ReadRecName(br);
                if (s != "HEDR")
                    throw new Exception(string.Format("File is not a valid {0} plugin (Missing HEDR subrecord in the {1} record)",define.Name,define.HEDRType));
                br.BaseStream.Position = 4;
                recsize = br.ReadUInt32();
                try
                {
                    this.AddRecord(new Record(this.define.HEDRType, recsize, br, this.define));
                }
                catch (Exception e)
                {
                    Alerts.Show(e.Message);
                }
                //bool hasExtraFlags = Math.Abs(version - 1.0f) > float.Epsilon * 10.0f;

                if (!headerOnly)
                {
                    while (br.PeekChar() != -1)
                    {
                        s = ReadRecName(br);
                        recsize = br.ReadUInt32();
                        if (s == "GRUP")
                        {
                            try
                            {
                                this.AddRecord(new GroupRecord(recsize, br, this.define, includeFilter, false));
                            }
                            catch (Exception e)
                            {
                                Alerts.Show(e.Message);
                            }
                        }
                        else
                        {
                            bool skip = includeFilter != null && !includeFilter(s);
                            if (skip)
                            {
                                long size = recsize + define.RecSize;
                                if ((br.ReadUInt32() & 0x00040000) > 0)
                                {
                                    size += 4; // Add 4 bytes for compressed record since the decompressed size is not included in the record size.
                                }

                                br.BaseStream.Position += size; // just position past the data
                            }
                            else
                            {
                                try
                                {
                                    this.AddRecord(new Record(s, recsize, br, define));
                                }
                                catch (Exception e)
                                {
                                    Alerts.Show(e.Message);
                                }
                            }
                        }
                    }
                }
                foreach (var rec in Enumerate(x => x is IGroupRecord || x is Record))
                    rec.UpdateShortDescription();
                this.UpdateRecordCount();
            }
            finally
            {
                HoldUpdates = oldHoldUpdates;
                FireRecordListUpdate(this, this);
                Decompressor.Close();
            }
        }