Exemple #1
0
 public static M MajorRecordParse <M>(
     M record,
     MutagenFrame frame,
     RecordTypeConverter?recordTypeConverter,
     RecordStructFill <M> fillStructs,
     RecordTypeFill <M> fillTyped)
     where M : IMajorRecordCommonGetter
 {
     frame = frame.SpawnWithFinalPosition(HeaderTranslation.ParseRecord(frame.Reader));
     fillStructs(
         record: record,
         frame: frame);
     if (fillTyped == null)
     {
         return(record);
     }
     try
     {
         MutagenFrame targetFrame = frame;
         if (record.IsCompressed)
         {
             targetFrame = frame.Decompress();
         }
         Dictionary <RecordType, int>?recordParseCount = null;
         frame.MetaData.FormVersion = record.FormVersion;
         while (!targetFrame.Complete)
         {
             var         subMeta  = targetFrame.GetSubrecord();
             var         finalPos = targetFrame.Position + subMeta.TotalLength;
             ParseResult parsed;
             try
             {
                 parsed = fillTyped(
                     record: record,
                     frame: targetFrame,
                     recordParseCount: recordParseCount,
                     nextRecordType: subMeta.RecordType,
                     contentLength: subMeta.ContentLength,
                     recordTypeConverter: recordTypeConverter);
             }
             catch (Exception ex)
             {
                 throw new SubrecordException(
                           subMeta.RecordType,
                           record.FormKey,
                           modKey: frame.Reader.MetaData.ModKey,
                           edid: record.EditorID,
                           innerException: ex);
             }
             if (!parsed.KeepParsing)
             {
                 break;
             }
             if (parsed.DuplicateParseMarker != null)
             {
                 if (recordParseCount == null)
                 {
                     recordParseCount = new Dictionary <RecordType, int>();
                 }
                 recordParseCount[parsed.DuplicateParseMarker !.Value] = recordParseCount.GetOrAdd(parsed.DuplicateParseMarker !.Value) + 1;
        public static M MajorRecordParse <M>(
            M record,
            MutagenFrame frame,
            RecordTypeConverter?recordTypeConverter,
            RecordStructFill <M> fillStructs,
            RecordTypeFill <M> fillTyped)
            where M : IMajorRecordCommonGetter
        {
            frame = frame.SpawnWithFinalPosition(HeaderTranslation.ParseRecord(frame.Reader));
            fillStructs(
                record: record,
                frame: frame);
            if (fillTyped == null)
            {
                return(record);
            }
            MutagenFrame targetFrame = frame;

            if (record.IsCompressed)
            {
                targetFrame = frame.Decompress();
            }
            while (!targetFrame.Complete)
            {
                var subMeta  = targetFrame.GetSubrecord();
                var finalPos = targetFrame.Position + subMeta.TotalLength;
                var parsed   = fillTyped(
                    record: record,
                    frame: targetFrame,
                    nextRecordType: subMeta.RecordType,
                    contentLength: subMeta.ContentLength,
                    recordTypeConverter: recordTypeConverter);
                if (parsed.Failed)
                {
                    break;
                }
                if (targetFrame.Position < finalPos)
                {
                    targetFrame.Position = finalPos;
                }
            }
            frame.SetToFinalPosition();
            return(record);
        }
        public static M MajorRecordParse <M>(
            M record,
            MutagenFrame frame,
            TypedParseParams?translationParams,
            RecordStructFill <M> fillStructs,
            MajorRecordFill <M> fillTyped)
            where M : IMajorRecordGetter
        {
            frame = frame.SpawnWithFinalPosition(HeaderTranslation.ParseRecord(frame.Reader));
            fillStructs(
                record: record,
                frame: frame);
            try
            {
                MutagenFrame targetFrame = frame;
                if (record.IsCompressed)
                {
                    targetFrame = frame.Decompress();
                }

                Dictionary <RecordType, int>?recordParseCount = null;
                frame.MetaData.FormVersion = record.FormVersion;
                var lastParsed = new PreviousParse();
                while (!targetFrame.Complete)
                {
                    var         subMeta  = targetFrame.GetSubrecord();
                    var         finalPos = targetFrame.Position + subMeta.TotalLength;
                    ParseResult parsed;
                    try
                    {
                        parsed = fillTyped(
                            record: record,
                            frame: targetFrame,
                            lastParsed: lastParsed,
                            recordParseCount: recordParseCount,
                            nextRecordType: subMeta.RecordType,
                            contentLength: lastParsed.LengthOverride ?? subMeta.ContentLength,
                            translationParams: translationParams);
                    }
                    catch (Exception ex)
                    {
                        throw new SubrecordException(
                                  subMeta.RecordType,
                                  record.FormKey,
                                  majorRecordType: record.Registration.ClassType,
                                  modKey: frame.Reader.MetaData.ModKey,
                                  edid: record.EditorID,
                                  innerException: ex);
                    }

                    if (!parsed.KeepParsing)
                    {
                        break;
                    }
                    if (parsed.DuplicateParseMarker != null)
                    {
                        if (recordParseCount == null)
                        {
                            recordParseCount = new Dictionary <RecordType, int>();
                        }

                        recordParseCount[parsed.DuplicateParseMarker !.Value] =