public void GetMagicPackets() { int readsize = (int)Math.Min((long)10485760, fileInfo.Length); byte[] bytes = ReadBytes(readsize); int index = 0; do { index = ToolKit.IndexOf(bytes, packet_magic, index); if (index < 0) { break; } Console.WriteLine(index); index++; } while (index >= 0); }
public Par2RecoverySet ReadRecoverySet() { //int readsize = (int)Math.Min((long)buffer_size, fileInfo.Length); int readsize = (int)fileInfo.Length; byte[] bytes = ReadBytes(readsize); int index = 0; int file_offset = 0; //while (BaseStream.Position < BaseStream.Length) { do { index = ToolKit.IndexOf(bytes, packet_magic, index); if (index < 0) { break; } PacketHeader header = PacketHeader.Create(bytes, index); switch (GetPacketType(header.type)) { case PacketType.CreatorPacket: CreatorPacket createPacket = CreatorPacket.Create(header, bytes, index + header.GetSize()); par2RecoverySet.AddCreatorPacket(createPacket); index += createPacket.GetSize() - header.GetSize(); break; case PacketType.DescriptionPacket: FileDescriptionPacket descPacket = FileDescriptionPacket.Create(header, bytes, index + header.GetSize()); par2RecoverySet.AddDescriptionPacket(descPacket); index += descPacket.GetSize() - header.GetSize(); break; case PacketType.MainPacket: MainPacket mainPacket = MainPacket.Create(header, bytes, index + header.GetSize()); par2RecoverySet.AddMainPacket(mainPacket); index += mainPacket.GetSize() - header.GetSize(); break; case PacketType.RecoveryPacket: RecoveryPacket recoveryPacket = RecoveryPacket.Create(header, bytes, index + header.GetSize(), fileInfo.FullName, file_offset); par2RecoverySet.AddRecoveryPacket(recoveryPacket); index += recoveryPacket.GetSize() - header.GetSize(); break; case PacketType.VerificationPacket: FileVerificationPacket verPacket = FileVerificationPacket.Create(header, bytes, index + header.GetSize()); par2RecoverySet.AddVerificationPacket(verPacket); index += verPacket.GetSize() - header.GetSize(); break; case PacketType.Unknown: // Unknown packettype break; } } while (index >= 0); index = 0; readsize = (int)Math.Min((long)buffer_size, BaseStream.Length - BaseStream.Position); file_offset += bytes.Length; bytes = ReadBytes(readsize); } return(par2RecoverySet); }