/// <summary> /// Does nothing if lack of bytes in the reader's underlying stream needed to read a value should /// not be treated as error; or throws the <see cref="NotEnoughBytesException"/> if this is /// unallowable. /// </summary> /// <param name="policy">The policy according to which the method should operate.</param> /// <param name="exception">Initial exception.</param> /// <exception cref="NotEnoughBytesException">Lack of bytes in the reader's underlying stream needed to /// read a value is unallowable due to the <paramref name="policy"/>.</exception> private static void ReactOnNotEnoughBytes(NotEnoughBytesPolicy policy, Exception exception) { if (policy == NotEnoughBytesPolicy.Abort) { throw new NotEnoughBytesException("MIDI file cannot be read since the reader's underlying stream doesn't have enough bytes.", exception); } }
// Token: 0x06003410 RID: 13328 RVA: 0x00148C28 File Offset: 0x00146E28 private static MidiChunk ReadChunk(MidiReader reader, ReadingSettings settings, int actualTrackChunksCount, int?expectedTrackChunksCount) { MidiChunk midiChunk = null; try { string text = reader.ReadString(4); if (text.Length < 4) { NotEnoughBytesPolicy notEnoughBytesPolicy = settings.NotEnoughBytesPolicy; if (notEnoughBytesPolicy == NotEnoughBytesPolicy.Abort) { throw new NotEnoughBytesException("Chunk ID cannot be read since the reader's underlying stream doesn't have enough bytes.", 4L, (long)text.Length); } if (notEnoughBytesPolicy == NotEnoughBytesPolicy.Ignore) { return(null); } } if (!(text == "MThd")) { if (!(text == "MTrk")) { midiChunk = MidiFile.TryCreateChunk(text, settings.CustomChunkTypes); } else { midiChunk = new TrackChunk(); } } else { midiChunk = new HeaderChunk(); } if (midiChunk == null) { switch (settings.UnknownChunkIdPolicy) { case UnknownChunkIdPolicy.ReadAsUnknownChunk: midiChunk = new UnknownChunk(text); break; case UnknownChunkIdPolicy.Skip: { uint num = reader.ReadDword(); reader.Position += (long)((ulong)num); return(null); } case UnknownChunkIdPolicy.Abort: throw new UnknownChunkException("'" + text + "' chunk ID is unknown.", text); } } if (midiChunk is TrackChunk && expectedTrackChunksCount != null) { int?num2 = expectedTrackChunksCount; if (actualTrackChunksCount >= num2.GetValueOrDefault() & num2 != null) { MidiFile.ReactOnUnexpectedTrackChunksCount(settings.UnexpectedTrackChunksCountPolicy, actualTrackChunksCount, expectedTrackChunksCount.Value); ExtraTrackChunkPolicy extraTrackChunkPolicy = settings.ExtraTrackChunkPolicy; if (extraTrackChunkPolicy != ExtraTrackChunkPolicy.Read && extraTrackChunkPolicy == ExtraTrackChunkPolicy.Skip) { uint num3 = reader.ReadDword(); reader.Position += (long)((ulong)num3); return(null); } } } midiChunk.Read(reader, settings); } catch (NotEnoughBytesException exception) { MidiFile.ReactOnNotEnoughBytes(settings.NotEnoughBytesPolicy, exception); } catch (EndOfStreamException exception2) { MidiFile.ReactOnNotEnoughBytes(settings.NotEnoughBytesPolicy, exception2); } return(midiChunk); }