private void ProcessFileReceive(AsynchronousSocket socket, byte[] encryptedMessage) { socket.WriteFileReceive(encryptedMessage); BytesReceived += Socket.ReceiveBufferSize; if (ReceivedFileBlock != null) { ReceivedFileBlock.Invoke(this, new EventArgs()); } if (socket.FileBytesReceived >= encryptedFileSize) { isReceivingUpdate = false; byte[] encryptedData = receiveStream.ToArray(); byte[] decryptedData = srpClient.Decrypt(encryptedData); FileStream fileStream; if (!File.Exists(UpdateFileLocation)) { fileStream = new FileStream(UpdateFileLocation, FileMode.CreateNew, FileAccess.Write); } else { fileStream = new FileStream(UpdateFileLocation, FileMode.Truncate, FileAccess.Write); } fileStream.Write(decryptedData, 0, decryptedData.Length); fileStream.Flush(); fileStream.Close(); socket.EndFileReceive(); FileInfo fileInfo = new FileInfo(UpdateFileLocation); if (fileInfo.Length == UpdateFileSize) { wasUpdateCompleted = true; } socket.Disconnect(); } }
private static void Client_ReceivedFileBlock(object sender, EventArgs e) { if (ReceivedFileBlock != null) { ReceivedFileBlock.Invoke(sender, e); } }