internal bool ExtractFileInternal(File f, FATX_Browser.FATX.IOWriter outIO, ref long sizeWritten, ref long maxVal) { //Create our binaryreader FATX_Browser.FATX.IOReader br; try { //Create our new misc class Misc m = new Misc(); //Create our blocks occupied list to speed some things up if the //blocks haven't been loaded yet System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch(); s.Start(); List<uint> BlocksOccupied = f.BlocksOccupied.ToList<uint>(); maxVal = BlocksOccupied.Count; if (BlocksOccupied.Count >= 1) { //Get our IO... br = xDrive.GetIO(); //For each loop increase our sizewritten, and keep looping //until we've reached the block BEFORE the final (size may not //be 0x4000 bytes) for (int i = 0; i < BlocksOccupied.Count - 1; i++, sizeWritten++) { //Get and set our reader position long position = m.GetBlockOffset(BlocksOccupied.ToArray()[i], f.PartInfo); br.BaseStream.Position = position; //Write to our output file what we just read outIO.Write(br.ReadBytes((int)f.PartInfo.ClusterSize)); br.BaseStream.Flush(); outIO.BaseStream.Flush(); } //KAY, now we've reached the final block in the series br.BaseStream.Position = m.GetBlockOffset(BlocksOccupied.ToArray()[BlocksOccupied.Count - 1], f); //Right here, we read the remaining data, and write it all //in one swoop outIO.Write(m.ReadBytes(ref br, m.RemainingData(f))); br.BaseStream.Flush(); outIO.BaseStream.Flush(); //Close our IO's br.Close(); outIO.Close(); sizeWritten++; return true; } return false; } catch (Exception e) { outIO.Close(); throw e; } }
/// <summary> /// Returns an array of EntryData for a specified block /// </summary> /// <param name="block">The block to read from</param> public EntryData[] GetEntries(uint block) { FATX_Browser.FATX.IOReader br = xDrive.GetIO(); //Get the block offset Misc r = new Misc(); br.BaseStream.Position = r.GetBlockOffset(block, Holder.PartInfo); long position = br.BaseStream.Position; //Create another binary reader that will hold our 0x200 bytes to read //(we can not seek to something that's not a multiple of 0x200) long OOFFSET = br.BaseStream.Position; byte[] buffer = br.ReadBytes(0x200); //Our placeholder for the bytes in the buffer read int bufferRead = 0; List<EntryData> l = new List<EntryData>(); for (uint i = 1; i <= 100; i++) { //If we've reached the end of the buffer if (bufferRead == 0x200) { OOFFSET = br.BaseStream.Position; //Read the next 0x200 bytes buffer = br.ReadBytes(0x200); bufferRead = 0; } //Create our stream for the reader FATX_Browser.FATX.IOReader mem = new FATX_Browser.FATX.IOReader(new System.IO.MemoryStream(buffer)); mem.BaseStream.Position = bufferRead; //Make sure that we're not at the end of the block byte[] end = mem.ReadBytes(2); if (EOF(end, true)) { break; } //We have to reset the reader back to the beginning of the block mem.BaseStream.Position -= 0x2; l.Add(GetEData(OOFFSET, mem, i, block)); position += 0x40; bufferRead += 0x40; br.BaseStream.Position = position; mem.Close(); } br.Close(); return l.ToArray(); }