mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-24 23:36:05 +00:00
Refactoring
This commit is contained in:
1 parent
c7b47eba6f
commit
78df7fe227
2 files changed
+10
-9
No files matched your search
@@ -147,13 +147,12 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
|
|
||||||
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.isEmpty {
|
||||||
do {
|
do {
|
||||||
try fileInfo.fileHandle?.write(contentsOf: frame.payloadChunk.body)
|
try fileInfo.fileHandle?.write(contentsOf: frame.payloadChunk.body)
|
||||||
filesToBeReceived[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
filesToBeReceived[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||||
fileInfo.progress?.completedUnitCount = filesToBeReceived[id]!.bytesTransferred
|
fileInfo.progress?.completedUnitCount = filesToBeReceived[id]!.bytesTransferred
|
||||||
|
|
||||||
// only for logging
|
|
||||||
self.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
self.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||||
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: Double(self.bytesTransferred) / Double(self.bytesToBeTransferred))
|
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: Double(self.bytesTransferred) / Double(self.bytesToBeTransferred))
|
||||||
} catch {
|
} catch {
|
||||||
@@ -178,6 +177,9 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
try sendDisconnectionAndDisconnect()
|
try sendDisconnectionAndDisconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
log("[InboundNearbyConnection \(self.id)] Received file chunk with no body and no flags, ignoring it.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -220,9 +222,11 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
filesToBeReceived.removeValue(forKey: id)
|
filesToBeReceived.removeValue(forKey: id)
|
||||||
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
||||||
|
|
||||||
log("[InboundNearbyConnection \(self.id)] Received file payload. Disconnecting...")
|
if filesToBeReceived.isEmpty {
|
||||||
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: 1)
|
log("[InboundNearbyConnection \(self.id)] Received file payload. Disconnecting...")
|
||||||
try sendDisconnectionAndDisconnect()
|
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: 1)
|
||||||
|
try sendDisconnectionAndDisconnect()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
private var queue: [OutgoingFileTransfer] = []
|
private var queue: [OutgoingFileTransfer] = []
|
||||||
private var currentTransfer: OutgoingFileTransfer?
|
private var currentTransfer: OutgoingFileTransfer?
|
||||||
private var totalBytesToSend: Int64 = 0
|
private var totalBytesToSend: Int64 = 0
|
||||||
private var totalBytesSent: Int64 = 0
|
|
||||||
private var textPayloadID: Int64 = 0
|
private var textPayloadID: Int64 = 0
|
||||||
|
|
||||||
public var qrCodePrivateKey: ECPrivateKey?
|
public var qrCodePrivateKey: ECPrivateKey?
|
||||||
@@ -462,13 +461,11 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
self.protocolError()
|
self.protocolError()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
totalBytesSent += Int64(fileBuffer.count)
|
|
||||||
|
|
||||||
// only for logging
|
|
||||||
self.bytesTransferred += Int64(fileBuffer.count)
|
self.bytesTransferred += Int64(fileBuffer.count)
|
||||||
|
|
||||||
startAndResetHeartbeatTimer()
|
startAndResetHeartbeatTimer()
|
||||||
delegate?.updatedTransferProgress(connection: self, progress: Double(totalBytesSent) / Double(totalBytesToSend))
|
delegate?.updatedTransferProgress(connection: self, progress: Double(bytesTransferred) / Double(totalBytesToSend))
|
||||||
|
|
||||||
if currentTransfer!.currentOffset == currentTransfer!.totalBytes {
|
if currentTransfer!.currentOffset == currentTransfer!.totalBytes {
|
||||||
// Signal end of file (yes, all this for one bit)
|
// Signal end of file (yes, all this for one bit)
|
||||||
|
|||||||
Reference in new issue
Block a user