private void LoadEntries(PblNod nod) { reader.Seek(nod.offset, SeekOrigin.Begin); string hdr = reader.ReadBlockName(); if (hdr != PblFile105.BLOCK_NAME_NOD) { throw new PblFileException("Chyba v souboru PBL knihovny. Nebyla nalezena NOD sekce."); } reader.Seek(OFFSET_FIRST_ENT, SeekOrigin.Current); for (int i = 0; i < nod.entCount; i++) { long offset = reader.Position; hdr = reader.ReadBlockName(); if (hdr != PblFile105.BLOCK_NAME_ENT) { throw new PblFileException("Chyba v souboru PBL knihovny. Nebyla nalezena ENT sekce."); } string unknown = reader.ReadUnicodeString(4); long dat_offset = reader.ReadInt32(); int entry_size = reader.ReadInt32(); DateTime dt = reader.ReadDateTime(); short comments_length = reader.ReadInt16(); short name_length = reader.ReadInt16(); string name = reader.ReadUnicodeString(name_length / 2); PblEntry ent = new PblEntry(); ent.offset = offset; ent.dataOffset = dat_offset; ent.size = entry_size; ent.time = dt; ent.commentsLength = comments_length; ent.name = name; nod.entries[i] = ent; this.entries.Add(ent.name, ent); } }
public override byte[] LoadEntry(string name) { PblEntry entry = this.entries[name] as PblEntry; if (entry == null) { throw new PblFileException("Položka " + name + " nebyla nalezena."); } if (entry.data != null) { return(entry.data); } int objsize = entry.size - entry.commentsLength * 2; entry.data = new byte[objsize]; long offset = entry.dataOffset; int size = 0; int index = 0; byte[] buff = new byte[512]; // prvni blok muze obsahovat komentar if (entry.commentsLength > 0) { offset = LoadBlockData(buff, index, offset, ref size); entry.comments = Encoding.Unicode.GetString(buff, 0, entry.commentsLength * 2); Array.Copy(buff, entry.commentsLength * 2, entry.data, 0, size - entry.commentsLength * 2); index += (size - entry.commentsLength * 2); } while (offset != 0) { offset = LoadBlockData(entry.data, index, offset, ref size); index += size; } return(entry.data); }
public override byte[] LoadEntry(string name) { PblEntry entry = this.entries[name] as PblEntry; if (entry == null) { throw new PblFileException("Entry " + name + " was not found."); } if (entry.data != null) { return(entry.data); } int objsize = entry.size - entry.commentsLength * 2; entry.data = new byte[objsize]; long offset = entry.dataOffset; int size = 0; int index = 0; byte[] buff = new byte[512]; // the first block may contain a remark if (entry.commentsLength > 0) { offset = LoadBlockData(buff, index, offset, ref size); entry.comments = Encoding.Unicode.GetString(buff, 0, entry.commentsLength * 2); Array.Copy(buff, entry.commentsLength * 2, entry.data, 0, size - entry.commentsLength * 2); index += (size - entry.commentsLength * 2); } while (offset != 0) { offset = LoadBlockData(entry.data, index, offset, ref size); index += size; } return(entry.data); }