public bool EnterPlugin(int baseSize) { // Read the tag data in based off the base size _reader.SeekTo(_tag.MetaLocation.AsOffset()); var data = _reader.ReadBlock(baseSize); // Create a block for it and push it onto the block stack uint cont = _cacheFile.PointerExpander.Contract(_tag.MetaLocation.AsPointer()); var block = new DataBlock(cont, 1, 4, false, data); DataBlocks.Add(block); var blockList = new List <DataBlock> { block }; _blockStack.Push(blockList); if (_tag.Group.Magic == SoundGroup) { ReadSound(block, 0); } return(true); }
/// <summary> /// Reads in the content of the TZX file so that it can be played /// </summary> /// <returns>True, if read was successful; otherwise, false</returns> public override bool ReadContent() { var success = base.ReadContent(); var blocks = DataBlocks.Cast <ISupportsTapeBlockPlayback>() .ToList(); _player = new TapeBlockSetPlayer(blocks); return(success); }
public DataReplacementPlanViewModel ToSummary() { return(new DataReplacementPlanViewModel( DataBlocks.Select(block => block.ToSummary()), Footnotes.Select(footnote => footnote.ToSummary()), OriginalSubjectId, ReplacementSubjectId )); }
private DataBlock ReadDataBlock(uint pointer, int entrySize, int entryCount, int align) { _reader.SeekTo(_cacheFile.MetaArea.PointerToOffset(pointer)); byte[] data = _reader.ReadBlock(entrySize * entryCount); var block = new DataBlock(pointer, entryCount, align, data); DataBlocks.Add(block); return(block); }
private DataBlock ReadDataBlock(long pointer, int entrySize, int entryCount, int align, bool sort) { _reader.SeekTo(_cacheFile.MetaArea.PointerToOffset(pointer)); var data = _reader.ReadBlock(entrySize * entryCount); uint cont = _cacheFile.PointerExpander.Contract(pointer); var block = new DataBlock(cont, entryCount, align, sort, data); DataBlocks.Add(block); return(block); }
/// <summary> /// Reads in the content of the TZX file so that it can be played /// </summary> /// <returns>True, if read was successful; otherwise, false</returns> public virtual bool ReadContent() { var header = new TzxHeader(); try { header.ReadFrom(_reader); if (!header.IsValid) { throw new TzxException("Invalid TZX header"); } MajorVersion = header.MajorVersion; MinorVersion = header.MinorVersion; while (_reader.BaseStream.Position != _reader.BaseStream.Length) { var blockType = _reader.ReadByte(); if (!DataBlockTypes.TryGetValue(blockType, out var type)) { throw new TzxException($"Unkonwn TZX block type: {blockType}"); } try { var block = Activator.CreateInstance(type) as TzxDataBlockBase; if (block is TzxDeprecatedDataBlockBase deprecated) { deprecated.ReadThrough(_reader); } else { block?.ReadFrom(_reader); } DataBlocks.Add(block); } catch (Exception ex) { throw new TzxException($"Cannot read TZX data block {type}.", ex); } } return(true); } catch { // --- This exception is intentionally ignored return(false); } }
public int GetSectionOffset(int section) { if (section < 0 || section >= SectionCount) { throw new ArgumentOutOfRangeException(nameof(section)); } //treat 0 as being the header if (section == 0) { return(0); } var totalPrevious = DataBlocks.Where(b => b.Section < section).Sum(b => b.Size); return(Header.HeaderSize + totalPrevious); }
public bool EnterPlugin(int baseSize) { // Read the tag data in based off the base size _reader.SeekTo(_tagLocation.AsOffset()); byte[] data = _reader.ReadBlock(baseSize); // Create a block for it and push it onto the block stack var block = new DataBlock(_tagLocation.AsPointer(), 1, 4, data); DataBlocks.Add(block); var blockList = new List <DataBlock>(); blockList.Add(block); _blockStack.Push(blockList); return(true); }
protected virtual void InitBlocks(int totalBlocks, int entriesPerBlock) { Size blockSize = new Block(new Point(0, 0), 1, entriesPerBlock).GetSize(); int blockHeight = blockSize.Height; int blockCenterX = this.Center.X; int initBlockCenterY = this.Center.Y - (blockHeight / 2) * (totalBlocks - 1) + labelHeight - 3 * padding / 2; for (int blockNumber = 0; blockNumber < totalBlocks; blockNumber++) { int offsetY = blockNumber * blockHeight; int blockCenterY = initBlockCenterY + offsetY; Point blockCenter = new Point(blockCenterX, blockCenterY); Block blockToAdd = new Block(blockCenter, blockNumber, entriesPerBlock); DataBlocks.Add(blockToAdd); } SetBlockSelection(this.CurrentBlock, true); }
public override Size GetSize() { Size size = new Size(40, 20); int totalBlocks = DataBlocks.Count; if (totalBlocks == 0) { return(size); } Size blockSize = DataBlocks.First().GetSize(); int width = blockSize.Width + 2 * padding; int height = totalBlocks * blockSize.Height + 2 * padding + labelHeight; size.Width = width; size.Height = height; return(size); }
public override BaseGadgetControl AddControl(BaseGadgetControl control) { base.AddControl(control); if (control is ModulePrefs) { this.ModulePrefs = (ModulePrefs)control; } else if (control is ContentBlock) { this.AddContentBlock((ContentBlock)control); } else if (control is DataBlock) { ((DataBlock)control).ConfirmDataItemsRegistered(); DataBlocks.Add((DataBlock)control); } else if (control is TemplatesRoot) { MyCustomTagFactory.RegisterCustomTags(((TemplatesRoot)control).CustomTags); } return(control); }
private void ReadBlock(MemoryStream ms, BinaryReader br, DataBlocks block) { int count = allEntries.Length; int start = -1; switch (block) { case DataBlocks.IDs: start = START_IDS + 2 * 8; break; case DataBlocks.Names: start = START_NAMES + 2 * LENGTH_NAME; break; case DataBlocks.Meta: start = START_META + 2 * 2; break; case DataBlocks.RunData: start = START_RUNDATA + 2 * 8; break; case DataBlocks.Scores: start = START_SCORES + 2 * 8; break; case DataBlocks.Block7: start = START_BLOCK7 + 2 * 4; break; case DataBlocks.Block8: start = START_BLOCK8 + 2 * 4; break; } ms.Seek(start, SeekOrigin.Begin); for (int i = 0; i < count; i++) { switch (block) { case DataBlocks.IDs: allEntries[i].id = br.ReadUInt64(); break; case DataBlocks.Names: { byte[] nameBuffer = new byte[LENGTH_NAME]; ms.Read(nameBuffer, 0, LENGTH_NAME); allEntries[i].name = Encoding.UTF8.GetString(nameBuffer).TrimEnd(new char[] { '\0' }); break; } case DataBlocks.Meta: { allEntries[i].platform = (Platform)br.ReadByte(); allEntries[i].character = (Character)br.ReadByte(); break; } case DataBlocks.RunData: { allEntries[i].runframes = br.ReadInt32(); allEntries[i].runend = (RunEndCause)br.ReadInt32(); } break; case DataBlocks.Scores: { allEntries[i].score = br.ReadInt32(); allEntries[i].level = br.ReadInt32(); break; } case DataBlocks.Block7: allEntries[i].unknown1 = br.ReadUInt32(); break; case DataBlocks.Block8: allEntries[i].unknown2 = br.ReadUInt32(); break; } } }