/// <summary> /// Will read the very top head of the TPS file. /// It will also fill in the block info list /// </summary> /// <returns></returns> private bool ReadTPSHeaderInfo() { _tpsHeader = new TPSHeader(); _tpsHeader.Process(); //fill in our blocks _tpsBlocks = new List <TPSBlock>(); long tpsFilelength = RandomAccess.GetInstance().fileSize; for (int t = 0; t < _tpsHeader.PageStart.Length; t++) { int ofs = _tpsHeader.PageStart[t]; int end = _tpsHeader.PageEnd[t]; // Skips the first entry (0 length) and any blocks that are beyond // the file size. if (((ofs == 0x0200) && (end == 0x200)) || (ofs >= tpsFilelength)) { continue; } else { _tpsBlocks.Add(new TPSBlock(ofs, end)); } } return(true); }
/// <summary> /// Gets data from the page /// If the page is compressed, it will uncompress it and return it. /// </summary> /// <returns></returns> private byte[] GetData() { //set our Randomaccess to the start of this page RandomAccess ra = RandomAccess.GetInstance(); byte[] pageData; ra.jumpAbs(addr); ra.jumpRelative(13); //skip the header //pull the page data //This really shouldn't be very big.. on my files it was about 8kb //If the file is using compression... uncompress it if ((pageSize != pageSizeUncompressed) && (flags == 0)) { try { pageData = ra.deRle(pageSize - 13); } catch (Exception ex) { throw new Exception("Bad RLE DataBlock ( compressed: " + pageSize + " uncompressed: " + pageSizeUncompressed + " Page Address: " + addr + "Record Count: " + recordCount.ToString() + "): ", ex); } } else { pageData = ra.leBytes(pageSize - 13); } return(pageData); }
public void Open() { RandomAccess ra = RandomAccess.GetInstance(); ra.OpenFile(_filename); _log += "INFO: Opened File: " + _filename; }
public void Process() { RandomAccess ra = RandomAccess.GetInstance(); addr = ra.leLong(); pageSize = ra.leShort(); pageSizeUncompressed = ra.leShort(); pageSizeUncompressedWithoutHeader = ra.leShort(); recordCount = ra.leShort(); flags = (int)ra.leByte(); ra.jumpRelative(pageSize - 13); //burn these bytes. This will leave the RandomAccess at the very end of the page }
public override string ToString() { RandomAccess ra = RandomAccess.GetInstance(); string str = ""; str += "TpsHeader(" + ra.toHex8(Addr) + "," + ra.toHex4(HeaderSize) + "," + ra.toHex8(FileLength1) + "," + ra.toHex8(FileLength2) + "," + TopSpeed + "," + ra.toHex4(Zeros) + "," + ra.toHex8(LastIssuedRow) + "," + ra.toHex8(Changes) + "," + ra.toHex8(ManagementPageRef) + ")\n"; for (int t = 0; t < PageStart.Length; t++) { str += ra.toHex8(PageStart[t]) + ".." + ra.toHex8(PageEnd[t]) + "\n"; } return(str); }
/// <summary> /// Will return a list of all pages in the block /// </summary> /// <returns></returns> public List <TPSPage> getPages() { RandomAccess ra = RandomAccess.GetInstance(); List <TPSPage> pages = new List <TPSPage>(); ra.jumpAbs(_start); //jump to the start of the block try{ while (ra.position < _end) //while we have not fallen off the end of the file { TPSPage page = new TPSPage(); page.Process(); pages.Add(page); //pages always start on the position % 100 = 0 //So let's jump forward to find the next start if ((ra.position & 0xFF) != 0x00) { ra.jumpAbs((ra.position & 0xFFFFFF00L) + 0x0100); } //we can find the next page because the address of the page will be in the data int addr = 0; if (!ra.isAtEnd()) { do { addr = ra.leLong(); ra.jumpRelative(-4); //backup 4 bytes if (addr != ra.position) { ra.jumpRelative(0x0100); } }while ((addr != ra.position) && !ra.isAtEnd()); } } }catch (Exception ex) { ; } return(pages); }
public void Process() { RandomAccess ra = RandomAccess.GetInstance(); ra.position = 0; Addr = ra.leLong(); if (Addr != 0) { throw new Exception("File doesn't start with 0x00000000 - it's not a TPS databse"); } HeaderSize = ra.leShort(); FileLength1 = ra.leLong(); FileLength2 = ra.leLong(); TopSpeed = ra.fixedLengthString(4); Zeros = ra.leShort(); LastIssuedRow = ra.beLong(); Changes = ra.leLong(); ManagementPageRef = ra.toFileOffset(ra.leLong()); PageStart = ra.toFileOffset(ra.leLongArray((0x110 - 0x20) / 4)); PageEnd = ra.toFileOffset(ra.leLongArray((0x200 - 0x110) / 4)); }
public override string ToString() { RandomAccess ra = RandomAccess.GetInstance(); return(string.Format("[TPSPage Addr={0}, PageSize={1}, PageSizeUncompressed={2}, PageSizeUncompressedWithoutHeader={3}, RecordCount={4}, Flags={5}]", ra.toHex8(addr), ra.toHex4(pageSize), ra.toHex4(pageSizeUncompressed), ra.toHex4(pageSizeUncompressedWithoutHeader), ra.toHex4(recordCount), ra.toHex2(flags))); }
public void Close() { RandomAccess.GetInstance().CloseFile(); }