public void ExtractFileAsync(STFSExplorer stfs, string fileName, out int progress) { progress = 0; byte[] file = RemoveHashBlocks(File, stfs); EndianStream embeddedStream = new EndianStream(new MemoryStream(file), Endian.BigEndian); EndianStream fileStream = new EndianStream(System.IO.File.Create(fileName), Endian.BigEndian); int buffer = 0x1000; while (fileStream.Position < embeddedStream.Length) { if (CancelTransfer) { break; } if (fileStream.Position + buffer > fileStream.Length) { buffer = (int)fileStream.Length - (int)fileStream.Position; } fileStream.WriteBlock(embeddedStream.ReadBlock(buffer)); // Update Progress progress = RandomFunctions.GetPercentage((int)fileStream.Position, (int)embeddedStream.Length); } fileStream.Close(); embeddedStream.Close(); }
private void sTFSToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { STFSExplorer stfs = new PartyBlam.STFS.STFSExplorer(ofd.FileName); stfs.FileListing[0].EmbeddedFile.ExtractFile(stfs, @"C:/Users/Alex/Desktop/usermap"); //stfs.FileListing[0].EmbeddedFile.ExtractFile(stfs, @"C:/Users/Alex/Desktop/gamestate.hdr"); //stfs.FileListing[1].EmbeddedFile.ExtractFile(stfs, @"C:/Users/Alex/Desktop/mmiof.bmf"); //stfs.FileListing[0].EmbeddedFile.ExtractFileAsync(stfs, @"C:/Users/Alex/Desktop/mmiof.bmf", out progressBar1.Value); } }
private byte[] RemoveHashBlocks(byte[] fileArray, STFSExplorer stfs) { long startOffset = StartingOffset; long endOffset = StartingOffset + Size; List <long> hashBlockOffsets = new List <long>(); foreach (xBlockEntry block in stfs._stfsBlockEntry) { if (block.IsHashBlock) { if (block.BlockOffset >= startOffset && block.BlockOffset <= endOffset) { hashBlockOffsets.Add(block.BlockOffset - (hashBlockOffsets.Count * 0x1000)); } } } if (hashBlockOffsets.Count > 0) { byte[] newFileAray = new byte[fileArray.Length - (hashBlockOffsets.Count * 0x1000)]; int newFileOffset = 0; for (int offset = 0; offset < fileArray.Length; offset++) { if (hashBlockOffsets.Count > 0 && hashBlockOffsets[0] == offset) { offset += 0x1000; hashBlockOffsets.RemoveAt(0); } else { newFileAray[newFileOffset] = fileArray[offset]; newFileOffset++; } } return(newFileAray); } else { return(fileArray); } }
public void ExtractFile(STFSExplorer stfs, string fileName) { System.IO.File.WriteAllBytes(fileName, RemoveHashBlocks(File, stfs)); }
public byte[] ExtractFile(STFSExplorer stfs) { return(RemoveHashBlocks(File, stfs)); }