From fffb072dcd736a061186f44511d2a10cb41e8b42 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Sun, 14 Jan 2024 19:52:32 -0800 Subject: Add support for downloading files with resource forks! Also properly set HFS creator code and type on downloaded files when specified by the server. --- Hotline/Models/Hotline.swift | 37 +++++++++++++++++++++++++++++++++++++ Hotline/Models/TransferInfo.swift | 1 + 2 files changed, 38 insertions(+) (limited to 'Hotline/Models') diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index f15bbb6..814ade5 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -473,6 +473,42 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { } } + @MainActor func downloadFileTo(url fileURL: URL, fileName: String, path: [String], progress progressCallback: ((TransferInfo, Double) -> Void)? = nil, complete callback: ((TransferInfo, URL) -> Void)? = nil) { + var fullPath: [String] = [] + if path.count > 1 { + fullPath = Array(path[0.. Void)? = nil) { var fullPath: [String] = [] if path.count > 1 { @@ -748,6 +784,7 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { if let transfer = self.transfers.first(where: { $0.id == reference }) { transfer.progress = progress transfer.timeRemaining = timeRemaining + transfer.progressCallback?(transfer, progress) } case .failed(_): if let i = self.downloads.firstIndex(where: { $0.referenceNumber == reference }) { diff --git a/Hotline/Models/TransferInfo.swift b/Hotline/Models/TransferInfo.swift index 546efd3..8b8d97a 100644 --- a/Hotline/Models/TransferInfo.swift +++ b/Hotline/Models/TransferInfo.swift @@ -14,6 +14,7 @@ class TransferInfo: Identifiable, Equatable, Hashable { // For file based transfers (i.e. not previews) var fileURL: URL? = nil + var progressCallback: ((TransferInfo, Double) -> Void)? = nil var downloadCallback: ((TransferInfo, URL) -> Void)? = nil var previewCallback: ((TransferInfo, Data) -> Void)? = nil -- cgit