Ejemplo n.º 1
0
 public void Load(TES4FileLoadScheme scheme)
 {
     this.BuildExpandTables();
     foreach (var file in this.files)
     {
         foreach (TES4Record loadedRecord in file.Load(scheme))
         {
             //no FORMID class encapsulation due to memory budgeting ;)
             int formid = loadedRecord.FormID;
             //TODO resolve conflicts
             this.records.Add(formid, loadedRecord);
             TES4SubrecordData?edid = loadedRecord.TryGetSubrecord("EDID");
             if (edid != null)
             {
                 this.edidIndex.Add(edid.ToStringTrimLower(), loadedRecord);
             }
             Nullable <int> scri = loadedRecord.TryGetSubrecordAsFormID("SCRI");
             if (scri != null)
             {
                 List <TES4Record> scriReferences = this.scriIndex.GetOrAdd(scri.Value, () => new List <TES4Record>(), out _);
                 scriReferences.Add(loadedRecord);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public IEnumerable <TES4Record> Load(TES4FileLoadScheme scheme)
        {
            Console.Write("Processing " + nameof(TES4File) + " Data...");
            Stopwatch stopwatch = Stopwatch.StartNew();

            using (FileStream contents = GetFile())
            {
                this.FetchTES4(contents);
                while (true)
                {
                    byte[] headerBytes = new byte[TES4Grup.GRUP_HEADER_SIZE];
                    int    read        = contents.Read(headerBytes);
                    if (read == 0)
                    {
                        break;
                    }
                    string headerString = ISO_8859_1.Value.GetString(headerBytes);
                    if (headerString.Substring(0, 4) != "GRUP")
                    {
                        throw new InvalidESFileException("Invalid GRUP magic, found " + headerString.Substring(0, 4));
                    }
                    contents.Seek(-TES4Grup.GRUP_HEADER_SIZE, SeekOrigin.Current);

                    int            grupSize = PHPFunction.UnpackV(headerBytes.Skip(4).Take(4).ToArray());
                    TES4RecordType grupType = TES4RecordType.First(headerString.Substring(8, 4));
                    if (scheme.ShouldLoad(grupType))
                    {
                        TES4GrupLoadScheme?rules = scheme.GetRulesFor(grupType);
                        if (rules == null)
                        {
                            throw new InvalidOperationException(nameof(rules) + " was null for " + nameof(grupType) + " " + grupType.Name + ".");
                        }
                        TES4Grup grup = new TES4Grup();
                        foreach (var loadedRecord in grup.Load(contents, this, rules, true))
                        {
                            yield return(loadedRecord);
                        }
                        if (grup.Type == null)
                        {
                            throw new InvalidOperationException(nameof(grup.Type) + " was null.");
                        }
                        this.grups.Add(grup.Type, grup);
                    }
                    else
                    {
                        contents.Seek(grupSize, SeekOrigin.Current);
                    }
                }
            }
            stopwatch.Stop();
            Console.WriteLine("\rProcessing " + nameof(TES4File) + " Complete (" + stopwatch.ElapsedMilliseconds + " ms)");
        }
 public void Load(TES4FileLoadScheme scheme)
 {
     this.BuildExpandTables();
     foreach (var file in this.files)
     {
         foreach (TES4LoadedRecord loadedRecord in file.Load(scheme))
         {
             //no FORMID class encapsulation due to memory budgeting ;)
             int formid = loadedRecord.GetFormId();
             //TODO resolve conflicts
             this.records.Add(formid, loadedRecord);
             string edid = loadedRecord.GetSubrecordTrimLower("EDID");
             if (edid != null)
             {
                 this.edidIndex.Add(edid, loadedRecord);
             }
         }
     }
 }