public static Stream EnsureUnpacked(Stream s) { var reader = new StructReader(s, System.Text.Encoding.ASCII, true); var streamStart = s.Position; var version = reader.ReadSingle(); //read just version s.Position = streamStart; //back to start for further processing if (version >= 1.44f) { var header = reader.ReadStruct <DLF_IO_HEADER>(); //read full header MemoryStream ms = new MemoryStream(); StructWriter writer = new StructWriter(ms, System.Text.Encoding.ASCII, true); writer.WriteStruct(header); //write header byte[] restOfFile = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); byte[] unpacked = ArxIO.Unpack(restOfFile); writer.Write(unpacked); //write unpacked rest s.Dispose(); //close old stream ms.Position = 0; return(ms); } return(s); //no need to unpack, return input stream }
public static Stream EnsurePacked(Stream s) { s.Position = 0; StructReader reader = new StructReader(s); MemoryStream ms = new MemoryStream(); StructWriter writer = new StructWriter(ms, System.Text.Encoding.ASCII, true); var header = reader.ReadStruct <FTS_IO_UNIQUE_HEADER>(); writer.WriteStruct(header); for (int i = 0; i < header.count; i++) { writer.WriteStruct(reader.ReadStruct <FTS_IO_UNIQUE_HEADER2>()); } byte[] restOfFile = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); byte[] packed = ArxIO.Pack(restOfFile); ms.Write(packed, 0, packed.Length); ms.Position = 0; s.Dispose(); return(ms); }
public static Stream EnsurePacked(Stream s) { byte[] unpacked = new byte[s.Length]; s.Read(unpacked, 0, unpacked.Length); byte[] packed = ArxIO.Pack(unpacked); MemoryStream ms = new MemoryStream(); ms.Write(packed, 0, packed.Length); ms.Position = 0; s.Dispose(); //close old stream return(ms); }
public void TestImplode() { System.Random r = new System.Random(); byte[] bytes = new byte[512]; r.NextBytes(bytes); var imploded = Implode.DoImplode(bytes); var exploded = ArxIO.Unpack(imploded); compare("imploded exploded", bytes, exploded); Debug.Log("test done"); }
public static Stream EnsurePacked(Stream s) { s.Position = 0; MemoryStream ms = new MemoryStream(); BinaryReader reader = new BinaryReader(s); byte[] header = reader.ReadBytes(Marshal.SizeOf(typeof(DLF_IO_HEADER))); byte[] restOfFile = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); byte[] packed = ArxIO.Pack(restOfFile); ms.Write(header, 0, header.Length); ms.Write(packed, 0, packed.Length); ms.Position = 0; s.Dispose(); return(ms); }
public static Stream EnsurePacked(Stream s) { //TODO: i should pack stuff depending on version, but for now ill just assume version 1.44 by default MemoryStream ms = new MemoryStream(); BinaryReader reader = new BinaryReader(s); byte[] header = reader.ReadBytes(Marshal.SizeOf(typeof(DLF_IO_HEADER))); byte[] restOfFile = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); byte[] packed = ArxIO.Pack(restOfFile); ms.Write(header, 0, header.Length); ms.Write(packed, 0, packed.Length); ms.Position = 0; s.Dispose(); return(ms); }
public static Stream EnsureUnpacked(Stream s) { s.Position = 0; byte[] first3 = new byte[3]; s.Read(first3, 0, first3.Length); s.Position = 0; if (first3[0] == 'F' && first3[1] == 'T' && first3[2] == 'L') { //uncomressed return(s); } byte[] packed = new byte[s.Length]; s.Read(packed, 0, packed.Length); byte[] unpacked = ArxIO.Unpack(packed); MemoryStream ms = new MemoryStream(); ms.Write(unpacked, 0, unpacked.Length); ms.Position = 0; s.Dispose(); //close old stream return(ms); }