mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 13:55:58 +00:00
Reformatting
This commit is contained in:
1 parent
a4ddb9d6be
commit
9a3d31ce3b
1 file changed
+11
-2
@@ -107,22 +107,30 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func processFileChunk(frame: Location_Nearby_Connections_PayloadTransferFrame) throws {
|
override func processFileChunk(frame: Location_Nearby_Connections_PayloadTransferFrame) throws {
|
||||||
|
|
||||||
let id = frame.payloadHeader.id
|
let id = frame.payloadHeader.id
|
||||||
|
|
||||||
guard let fileInfo = transferredFiles[id] else { throw NearbyError.protocolError("File payload ID \(id) is not known") }
|
guard let fileInfo = transferredFiles[id] else { throw NearbyError.protocolError("File payload ID \(id) is not known") }
|
||||||
|
|
||||||
let currentOffset = fileInfo.bytesTransferred
|
let currentOffset = fileInfo.bytesTransferred
|
||||||
|
|
||||||
guard frame.payloadChunk.offset == currentOffset else { throw NearbyError.protocolError("Invalid offset into file \(frame.payloadChunk.offset), expected \(currentOffset)") }
|
guard frame.payloadChunk.offset == currentOffset else { throw NearbyError.protocolError("Invalid offset into file \(frame.payloadChunk.offset), expected \(currentOffset)") }
|
||||||
|
|
||||||
guard currentOffset + Int64(frame.payloadChunk.body.count) <= fileInfo.meta.size else { throw NearbyError.protocolError("Transferred file size exceeds previously specified value") }
|
guard currentOffset + Int64(frame.payloadChunk.body.count) <= fileInfo.meta.size else { throw NearbyError.protocolError("Transferred file size exceeds previously specified value") }
|
||||||
|
|
||||||
if frame.payloadChunk.body.count > 0 {
|
if frame.payloadChunk.body.count > 0 {
|
||||||
fileInfo.fileHandle?.write(frame.payloadChunk.body)
|
fileInfo.fileHandle?.write(frame.payloadChunk.body)
|
||||||
transferredFiles[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
transferredFiles[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||||
fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred
|
fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred
|
||||||
} else if (frame.payloadChunk.flags & 1) == 1 {
|
}
|
||||||
|
else if (frame.payloadChunk.flags & 1) == 1 {
|
||||||
try fileInfo.fileHandle?.close()
|
try fileInfo.fileHandle?.close()
|
||||||
transferredFiles[id]!.fileHandle = nil
|
transferredFiles[id]!.fileHandle = nil
|
||||||
fileInfo.progress?.unpublish()
|
fileInfo.progress?.unpublish()
|
||||||
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
||||||
|
|
||||||
transferredFiles.removeValue(forKey: id)
|
transferredFiles.removeValue(forKey: id)
|
||||||
|
|
||||||
if transferredFiles.isEmpty {
|
if transferredFiles.isEmpty {
|
||||||
try sendDisconnectionAndDisconnect()
|
try sendDisconnectionAndDisconnect()
|
||||||
}
|
}
|
||||||
@@ -148,7 +156,8 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
|
|
||||||
try sendDisconnectionAndDisconnect()
|
try sendDisconnectionAndDisconnect()
|
||||||
return true
|
return true
|
||||||
} else if let fileInfo = transferredFiles[id] {
|
}
|
||||||
|
else if let fileInfo = transferredFiles[id] {
|
||||||
fileInfo.fileHandle?.write(payload)
|
fileInfo.fileHandle?.write(payload)
|
||||||
transferredFiles[id]!.bytesTransferred += Int64(payload.count)
|
transferredFiles[id]!.bytesTransferred += Int64(payload.count)
|
||||||
fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred
|
fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred
|
||||||
|
|||||||
Reference in new issue
Block a user