mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-11 19:11:10 +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") }
|
||||
|
||||
if frame.payloadChunk.body.count > 0 {
|
||||
if !frame.payloadChunk.body.isEmpty {
|
||||
do {
|
||||
try fileInfo.fileHandle?.write(contentsOf: frame.payloadChunk.body)
|
||||
filesToBeReceived[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||
fileInfo.progress?.completedUnitCount = filesToBeReceived[id]!.bytesTransferred
|
||||
|
||||
// only for logging
|
||||
self.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: Double(self.bytesTransferred) / Double(self.bytesToBeTransferred))
|
||||
} catch {
|
||||
@@ -178,6 +177,9 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
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)
|
||||
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
||||
|
||||
log("[InboundNearbyConnection \(self.id)] Received file payload. Disconnecting...")
|
||||
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: 1)
|
||||
try sendDisconnectionAndDisconnect()
|
||||
if filesToBeReceived.isEmpty {
|
||||
log("[InboundNearbyConnection \(self.id)] Received file payload. Disconnecting...")
|
||||
NearbyConnectionManager.shared.updatedTransferProgress(connection: self, progress: 1)
|
||||
try sendDisconnectionAndDisconnect()
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -23,7 +23,6 @@ class OutboundNearbyConnection: NearbyConnection {
|
||||
private var queue: [OutgoingFileTransfer] = []
|
||||
private var currentTransfer: OutgoingFileTransfer?
|
||||
private var totalBytesToSend: Int64 = 0
|
||||
private var totalBytesSent: Int64 = 0
|
||||
private var textPayloadID: Int64 = 0
|
||||
|
||||
public var qrCodePrivateKey: ECPrivateKey?
|
||||
@@ -462,13 +461,11 @@ class OutboundNearbyConnection: NearbyConnection {
|
||||
self.protocolError()
|
||||
}
|
||||
})
|
||||
totalBytesSent += Int64(fileBuffer.count)
|
||||
|
||||
// only for logging
|
||||
self.bytesTransferred += Int64(fileBuffer.count)
|
||||
|
||||
startAndResetHeartbeatTimer()
|
||||
delegate?.updatedTransferProgress(connection: self, progress: Double(totalBytesSent) / Double(totalBytesToSend))
|
||||
delegate?.updatedTransferProgress(connection: self, progress: Double(bytesTransferred) / Double(totalBytesToSend))
|
||||
|
||||
if currentTransfer!.currentOffset == currentTransfer!.totalBytes {
|
||||
// Signal end of file (yes, all this for one bit)
|
||||
|
||||
Reference in new issue
Block a user