public UnprocessedChunkController(NSFController nsfcontroller,UnprocessedChunk unprocessedchunk) : base(nsfcontroller,unprocessedchunk) { this.unprocessedchunk = unprocessedchunk; Node.Text = string.Format("Unprocessed Chunk (T{0})",unprocessedchunk.Type); Node.ImageKey = "unprocessedchunk"; Node.SelectedImageKey = "unprocessedchunk"; }
public static NSF Load(byte[] data) { if (data == null) { throw new ArgumentNullException("data"); } int offset = 0; int?firstid = null; List <UnprocessedChunk> prelude = null; List <Chunk> chunks = new List <Chunk>(); List <bool> preludecompression = null; List <bool> chunkcompression = new List <bool>(); while (offset < data.Length) { bool compressed; byte[] chunkdata = ReadChunk(data, ref offset, out compressed); UnprocessedChunk chunk = Chunk.Load(chunkdata); if (firstid == null) { firstid = chunk.ID; } else if (firstid == chunk.ID) { if (prelude != null) { ErrorManager.SignalError("NSF: Double prelude"); } prelude = new List <UnprocessedChunk>(); foreach (UnprocessedChunk unprocessedchunk in chunks) { prelude.Add(unprocessedchunk); } chunks.Clear(); preludecompression = chunkcompression; chunkcompression = new List <bool>(); } chunkcompression.Add(compressed); if (prelude != null && chunks.Count < prelude.Count) { for (int i = 0; i < Chunk.Length; i++) { if (prelude[chunks.Count].Data[i] != chunk.Data[i]) { ErrorManager.SignalIgnorableError("NSF: Prelude data mismatch"); break; } } } chunks.Add(chunk); } if (prelude != null && chunks.Count < prelude.Count) { ErrorManager.SignalIgnorableError("NSF: Prelude is longer than actual data"); } if (prelude != null) { ErrorManager.SignalIgnorableError("NSF: Prelude saving is not yet implemented"); } foreach (bool compressed in chunkcompression) { if (compressed) { ErrorManager.SignalIgnorableError("NSF: Non-prelude chunk was compressed"); } } return(new NSF(chunks)); }