Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
feat(download): show speed, time left and a Pause button on every download
raymondchins3e7a83930039
diff --git a/app/Sources/BridgeplayApp/Model/SetupChecks.swift b/app/Sources/BridgeplayApp/Model/SetupChecks.swiftindex 9a13733..6904694 100644--- a/app/Sources/BridgeplayApp/Model/SetupChecks.swift+++ b/app/Sources/BridgeplayApp/Model/SetupChecks.swift@@ -72,7 +72,12 @@ enum SetupChecks {// Downloads Valve's installer image and copies Steam.app into /Applications.static func installSteam(to app: URL = SupportPaths.Steam.defaultApp, report: @Sendable (String) -> Void) async throws {report(String(localized: "Downloading Steam"))- let (download, response) = try await URLSession.shared.download(from: steamInstaller)+ let host = steamInstaller.host() ?? "Valve"+ let (download, response) = try await withoutActuallyEscaping(report) { report in+ let relay = ProgressRelay(host: host) { report($0.label) }+ defer { relay.finish(); Task { @MainActor in DownloadMeter.shared.clear() } }+ return try await URLSession.shared.download(from: steamInstaller, delegate: relay)+ }defer { try? FileManager.default.removeItem(at: download) }if let http = response as? HTTPURLResponse, http.statusCode != 200 {throw StepFailure(step: step, detail: "Valve answered \(http.statusCode).")diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstringsindex f9cdec7..6c75c99 100644--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings@@ -6114,6 +6114,38 @@}}},+ "Pause" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Pausa"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "暂停"+ }+ }+ }+ },+ "Paused" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "In pausa"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "已暂停"+ }+ }+ }+ },"Please run CrossOver and try again." : {"localizations" : {"it" : {@@ -7266,6 +7298,22 @@}}},+ "Resume" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Riprendi"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "继续"+ }+ }+ }+ },"Reveal Log in Finder" : {"localizations" : {"it" : {@@ -10315,6 +10363,22 @@}}},+ "about %@ left" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "circa %@ rimanenti"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "大约还剩 %@"+ }+ }+ }+ },"another version of CrossOver" : {"localizations" : {"it" : {diff --git a/app/Sources/BridgeplayApp/SetupAssistant.swift b/app/Sources/BridgeplayApp/SetupAssistant.swiftindex 37f25b5..785ae10 100644--- a/app/Sources/BridgeplayApp/SetupAssistant.swift+++ b/app/Sources/BridgeplayApp/SetupAssistant.swift@@ -34,6 +34,8 @@ final class SetupAssistant {var step: Step = .macvar isWorking = false+ // "Downloading from …: 3 MB / 5 MB · 1.2 MB/s" while Steam downloads.+ var steamProgress: String?var message: String?// Mac@@ -119,6 +121,22 @@ final class SetupAssistant {try? await Task.sleep(for: .seconds(seconds))}+ // Preview only: runs a download's bar from empty to done in about eight seconds; Pause holds it.+ private func pretendDownload(host: String, total: Int64, _ show: (String?) -> Void) async {+ let meter = DownloadMeter.shared+ for step in 0...40 {+ while meter.paused { await pretend(0.2) }+ let received = total * Int64(step) / 40+ let speed = step > 4 ? Double(total) / 8 : nil+ show(PinnedDownload.Progress.fetching(host: host).label)+ meter.update(host: host, received: received, total: total, speed: speed,+ remaining: speed.map { Double(total - received) / $0 })+ await pretend(0.2)+ }+ show(nil)+ meter.clear()+ }+var macReady: Bool { appleSilicon && macOSSupported && rosettaInstalled && hasSpace }var hasSpace: Bool { (freeBytes ?? .max) >= SetupChecks.requiredBytes }@@ -184,11 +202,15 @@ final class SetupAssistant {func installSteam() async {isWorking = true- defer { isWorking = false }- if isPreview { await pretend(); steamInstalled = true; return }+ defer { isWorking = false; steamProgress = nil }+ if isPreview {+ await pretendDownload(host: "cdn.cloudflare.steamstatic.com", total: 4_404_019) { steamProgress = $0 }+ steamInstalled = true+ return+ }message = nildo {- try await SetupChecks.installSteam { _ in }+ try await SetupChecks.installSteam { label in Task { @MainActor in self.steamProgress = label } }} catch {message = String(localized: "Steam wasn't installed. \(error.localizedDescription)")}@@ -253,7 +275,11 @@ final class SetupAssistant {if isPreview {for task in Self.plannedTasks {set(task.id, .running)- await pretend(1.2)+ if task.id == "engine" {+ await pretendDownload(host: "github.com", total: 461_373_440) { status.activity = $0 }+ } else {+ await pretend(1.2)+ }set(task.id, .done)}step = .donediff --git a/app/Sources/BridgeplayApp/Support/PinnedDownload.swift b/app/Sources/BridgeplayApp/Support/PinnedDownload.swiftindex da60c31..9d3b4d5 100644--- a/app/Sources/BridgeplayApp/Support/PinnedDownload.swift+++ b/app/Sources/BridgeplayApp/Support/PinnedDownload.swift@@ -1,36 +1,41 @@// Download one hash pinned file from a list of CDN hosts+import BridgeplayUIimport Foundation+import Observationenum PinnedDownload {enum Progress: Sendable {case reusingcase fetching(host: String)- case receiving(host: String, received: Int64, total: Int64, remaining: TimeInterval?)+ case receiving(host: String, received: Int64, total: Int64, remaining: TimeInterval?, speed: Double? = nil)var label: String {switch self {case .reusing: String(localized: "Preparing")case .fetching(let host): String(localized: "Downloading from \(host)")- case .receiving(let host, let received, let total, let remaining):- Self.label(host: host, received: received, total: total, remaining: remaining)+ case .receiving(let host, let received, let total, let remaining, let speed):+ Self.label(host: host, received: received, total: total, remaining: remaining, speed: speed)}}- static func label(host: String, received: Int64, total: Int64, remaining: TimeInterval?) -> String {- let amount = ByteCountFormatter.string(fromByteCount: received, countStyle: .file) + " / "- + ByteCountFormatter.string(fromByteCount: total, countStyle: .file)+ static func label(host: String, received: Int64, total: Int64, remaining: TimeInterval?, speed: Double? = nil) -> String {+ let amount = DownloadRate.amount(received: received, total: total, speed: speed)+ guard let left = remaining.flatMap(duration) else {+ return String(localized: "Downloading from \(host): \(amount)")+ }+ return String(localized: "Downloading from \(host): \(amount), about \(left) left")+ }++ // "2 minutes"; seconds only near the end, so the estimate doesn't tick every second.+ static func duration(_ remaining: TimeInterval) -> String? {let time = DateComponentsFormatter()time.unitsStyle = .fulltime.maximumUnitCount = 1time.allowedUnits = [.hour, .minute, .second]- // Seconds only near the end, so the estimate doesn't tick every second.- let rounded = remaining.map { $0 < 60 ? $0 : ($0 / 60).rounded(.up) * 60 }- guard let rounded, let left = time.string(from: max(rounded, 1)) else {- return String(localized: "Downloading from \(host): \(amount)")- }- return String(localized: "Downloading from \(host): \(amount), about \(left) left")+ let rounded = remaining < 60 ? remaining : (remaining / 60).rounded(.up) * 60+ return time.string(from: max(rounded, 1))}}@@ -69,9 +74,22 @@ enum PinnedDownload {let body: URL, response: URLResponsedo {(body, response) = try await withoutActuallyEscaping(report) { report in- let relay = ProgressRelay(host: host, report: report)- defer { relay.finish() }- return try await session.download(from: base.appending(path: file), delegate: relay)+ // A dropped connection (or one the server closed during a pause) resumes+ // where it stopped rather than starting the 440 MB over.+ defer { Task { @MainActor in DownloadMeter.shared.clear() } }+ var resumeData: Data?+ for attempt in 1... {+ let relay = ProgressRelay(host: host, report: report)+ defer { relay.finish() }+ do {+ if let resumeData { return try await session.download(resumeFrom: resumeData, delegate: relay) }+ return try await session.download(from: base.appending(path: file), delegate: relay)+ } catch let error as URLError where attempt < 4 && error.downloadTaskResumeData != nil {+ resumeData = error.downloadTaskResumeData+ AppLog.note("\(file) from \(host) interrupted (\(error.localizedDescription)), resuming")+ }+ }+ fatalError("unreachable")}} catch {refusals.append("\(host): \(error.localizedDescription)")@@ -80,7 +98,8 @@ enum PinnedDownload {}defer { try? FileManager.default.removeItem(at: body) }- if let http = response as? HTTPURLResponse, http.statusCode != 200 {+ // 206: resumed after a dropped connection.+ if let http = response as? HTTPURLResponse, ![200, 206].contains(http.statusCode) {refusals.append("\(host) answered \(http.statusCode)")kinds.insert(.answered)continue@@ -130,15 +149,54 @@ enum PinnedDownload {}}-// Turns the task's byte count into .receiving reports, once per percent.-private final class ProgressRelay: NSObject, URLSessionTaskDelegate, @unchecked Sendable {+/// The running download, for the bar with its amount, speed and Pause button. Downloads run one at a time.+@MainActor @Observable+final class DownloadMeter {+ static let shared = DownloadMeter()+ private(set) var host: String?+ private(set) var received: Int64 = 0+ private(set) var total: Int64 = 0+ private(set) var speed: Double?+ private(set) var remaining: TimeInterval?+ private(set) var paused = false+ @ObservationIgnored fileprivate weak var relay: ProgressRelay?++ var fraction: Double? { host != nil && total > 0 ? Double(received) / Double(total) : nil }+ // "Downloading from github.com", for the row above the bar.+ var title: String? { host.map { PinnedDownload.Progress.fetching(host: $0).label } }++ func update(host: String, received: Int64, total: Int64, speed: Double?, remaining: TimeInterval?) {+ self.host = host+ self.received = received+ self.total = total+ self.speed = speed+ self.remaining = remaining+ }++ func clear() {+ host = nil+ paused = false+ relay = nil+ }++ func togglePause() {+ guard host != nil else { return }+ paused.toggle()+ paused ? relay?.suspend() : relay?.resume()+ AppLog.note("download \(paused ? "paused" : "resumed") at \(received) of \(total) bytes")+ }+}++// Turns the task's byte count into .receiving reports, once per percent, and DownloadMeter's bar.+final class ProgressRelay: NSObject, URLSessionTaskDelegate, @unchecked Sendable {private let host: String// Dropped by finish(): the caller's closure only lives as long as the download.private var report: (@Sendable (PinnedDownload.Progress) -> Void)?- private let started = Date()private let lock = NSLock()private var observation: NSKeyValueObservation?+ private var task: URLSessionTask?private var shown = -1+ private var rate = DownloadRate()init(host: String, report: @escaping @Sendable (PinnedDownload.Progress) -> Void) {self.host = host@@ -149,28 +207,42 @@ private final class ProgressRelay: NSObject, URLSessionTaskDelegate, @uncheckedlet observation = task.progress.observe(\.completedUnitCount) { [weak self] progress, _ inself?.update(received: progress.completedUnitCount, total: progress.totalUnitCount)}- lock.withLock { self.observation = observation }+ lock.withLock { self.observation = observation; self.task = task }+ Task { @MainActor in+ let meter = DownloadMeter.shared+ meter.relay = self+ // Paused between a dropped connection and its resume: stay paused.+ if meter.paused { self.suspend() }+ }}+ func suspend() { lock.withLock { task?.suspend() } }+ func resume() { lock.withLock { task?.resume() } }+func finish() {lock.withLock {observation?.invalidate()observation = nilreport = nil+ task = nil}}private func update(received: Int64, total: Int64) {guard total > 0, received <= total else { return }let percent = Int(received * 100 / total)- let elapsed = Date().timeIntervalSince(started)- // A few seconds in, so the first estimate isn't wild.- let remaining = received > 0 && elapsed > 3 ? elapsed * Double(total - received) / Double(received) : nil// Reported under the lock, so finish() can't drop the closure mid-call.lock.withLock {guard percent != shown, let report else { return }shown = percent- report(.receiving(host: host, received: received, total: total, remaining: remaining))+ let speed = rate.add(received)+ // From the recent speed, so a pause doesn't stretch the estimate.+ let remaining = speed.flatMap { $0 > 0 ? Double(total - received) / $0 : nil }+ report(.receiving(host: host, received: received, total: total, remaining: remaining, speed: speed))+ let host = host+ Task { @MainActor in+ DownloadMeter.shared.update(host: host, received: received, total: total, speed: speed, remaining: remaining)+ }}}}diff --git a/app/Sources/BridgeplayApp/Support/SetupPreview.swift b/app/Sources/BridgeplayApp/Support/SetupPreview.swiftindex 9b3e3b5..5b2d3f0 100644--- a/app/Sources/BridgeplayApp/Support/SetupPreview.swift+++ b/app/Sources/BridgeplayApp/Support/SetupPreview.swift@@ -5,7 +5,8 @@ import SwiftUI// Debug builds only: `.build/debug/BridgeplayApp --setup-preview [--fresh]` opens the Setup// Assistant by itself for design review, then the main window once it closes. The assistant// reads this Mac's state and only pretends to act (--fresh shows a Mac that still needs-// setup; --main skips straight to the main window). The main window is the real one: its+// setup; --main skips straight to the main window; --run presses the step's button, so its+// progress can be captured; --pause then pauses its download after three seconds). The main window is the real one: its// buttons do what they do in the app.struct SetupPreviewApp: App {static let flag = "--setup-preview"@@ -53,16 +54,33 @@ struct SetupPreviewApp: App {}private struct PreviewWizard: View {- let preview: SetupAssistant.Preview- let start: SetupAssistant.Step+ @State private var model: SetupAssistant+ private let start: SetupAssistant.Step+ @Environment(SystemStatus.self) private var status@Environment(\.openWindow) private var openWindow@Environment(\.dismissWindow) private var dismissWindow+ init(preview: SetupAssistant.Preview, start: SetupAssistant.Step) {+ _model = State(initialValue: SetupAssistant(preview: preview, startAt: start))+ self.start = start+ }+var body: some View {- SetupAssistantView(model: SetupAssistant(preview: preview, startAt: start)) {+ SetupAssistantView(model: model) {openWindow(id: "main-preview")dismissWindow(id: "setup-preview")}+ .task {+ guard CommandLine.arguments.contains("--run") else { return }+ if CommandLine.arguments.contains("--pause") {+ Task { try? await Task.sleep(for: .seconds(3)); DownloadMeter.shared.togglePause() }+ }+ switch start {+ case .steam: model.steamInstalled = false; await model.installSteam()+ case .finish: await model.finish(with: status)+ default: break+ }+ }}}#endifdiff --git a/app/Sources/BridgeplayApp/SystemStatus.swift b/app/Sources/BridgeplayApp/SystemStatus.swiftindex 28fea5a..69266b9 100644--- a/app/Sources/BridgeplayApp/SystemStatus.swift+++ b/app/Sources/BridgeplayApp/SystemStatus.swift@@ -175,6 +175,7 @@ final class SystemStatus {func endRun() {generation += 1activity = nil+ DownloadMeter.shared.clear()AppLog.note("run end\(failure == nil ? "" : " (failed)")")}diff --git a/app/Sources/BridgeplayApp/Views/DownloadStrip.swift b/app/Sources/BridgeplayApp/Views/DownloadStrip.swiftnew file mode 100644index 0000000..80938fa--- /dev/null+++ b/app/Sources/BridgeplayApp/Views/DownloadStrip.swift@@ -0,0 +1,37 @@+import BridgeplayUI+import SwiftUI++/// The running download's bar, with its amount, speed, time left and a Pause button beside it.+struct DownloadStrip: View {+ private let meter = DownloadMeter.shared++ var body: some View {+ if let fraction = meter.fraction {+ VStack(alignment: .leading, spacing: 8) {+ HStack(spacing: 12) {+ VStack(alignment: .leading, spacing: 2) {+ if let title = meter.title {+ Text(title).font(BP.sans(13, .semibold)).lineLimit(1)+ }+ Text(details)+ .font(BP.sans(12))+ .monospacedDigit()+ .foregroundStyle(BP.fg2)+ .lineLimit(1)+ }+ Spacer(minLength: 8)+ Button(meter.paused ? String(localized: "Resume") : String(localized: "Pause")) { meter.togglePause() }+ .buttonStyle(.pillSecondary)+ }+ GradientProgress(fraction: fraction)+ }+ }+ }++ private var details: String {+ let amount = DownloadRate.amount(received: meter.received, total: meter.total, speed: meter.paused ? nil : meter.speed)+ if meter.paused { return amount + " · " + String(localized: "Paused") }+ guard let left = meter.remaining.flatMap(PinnedDownload.Progress.duration) else { return amount }+ return amount + " · " + String(localized: "about \(left) left")+ }+}diff --git a/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift b/app/Sources/BridgeplayApp/Views/SetupAssistantView.swiftindex 16e0498..5a3d081 100644--- a/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift+++ b/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift@@ -90,6 +90,11 @@ struct SetupAssistantView: View {.transition(pageTransition)}.clipped()+ // Pinned above the footer, so it stays in view however long the step's content is.+ if DownloadMeter.shared.fraction != nil {+ Rectangle().fill(BP.line).frame(height: 1)+ DownloadStrip().padding(.horizontal, 28).padding(.vertical, 12)+ }Rectangle().fill(BP.line).frame(height: 1)footer.padding(.horizontal, 24)@@ -230,7 +235,8 @@ struct SetupAssistantView: View {detail: "Sign in with your account in Steam. Bridgeplay continues on its own once you're in.")SetupCard {checked(0, StatusRow(title: String(localized: "Steam"),- value: model.steamInstalled ? SupportPaths.Steam.app.path(percentEncoded: false) : String(localized: "Not installed."),+ value: model.steamInstalled ? SupportPaths.Steam.app.path(percentEncoded: false)+ : DownloadMeter.shared.title ?? model.steamProgress ?? String(localized: "Not installed."),tone: model.steamInstalled ? .ok : .warning,action: model.steamInstalled ? nil : StatusAction(label: String(localized: "Install Steam"), isProminent: true, isEnabled: !model.isWorking@@ -372,7 +378,7 @@ struct SetupAssistantView: View {private func value(of task: SetupAssistant.SetupTask) -> String? {switch task.state {case .waiting: nil- case .running: status.activity ?? String(localized: "Working…")+ case .running: DownloadMeter.shared.title ?? status.activity ?? String(localized: "Working…")case .done: String(localized: "Done.")case .failed(let reason): reason}@@ -657,7 +663,7 @@ private struct ToneBadge: View {}}-private struct GradientProgress: View {+struct GradientProgress: View {let fraction: Doublevar body: some View {diff --git a/app/Sources/BridgeplayApp/Views/StatusView.swift b/app/Sources/BridgeplayApp/Views/StatusView.swiftindex 8e10286..2446923 100644--- a/app/Sources/BridgeplayApp/Views/StatusView.swift+++ b/app/Sources/BridgeplayApp/Views/StatusView.swift@@ -319,9 +319,10 @@ struct StatusView: View {HStack(spacing: 10) {ProgressView().controlSize(.small)- Text(activity)+ Text(DownloadMeter.shared.title ?? activity).foregroundStyle(.secondary)}+ DownloadStrip()}Section("Steam") {diff --git a/app/Sources/BridgeplayInstaller/InstallerModel.swift b/app/Sources/BridgeplayInstaller/InstallerModel.swiftindex 3e0064d..57705ef 100644--- a/app/Sources/BridgeplayInstaller/InstallerModel.swift+++ b/app/Sources/BridgeplayInstaller/InstallerModel.swift@@ -2,6 +2,7 @@ import AppKitimport Foundationimport Observationimport BridgeplayInstallerCore+import BridgeplayUI@MainActor@Observable@@ -14,6 +15,12 @@ final class InstallerModel {var progress: Double?var received: Int64 = 0var total: Int64?+ var speed: Double?+ var paused = false+ @ObservationIgnored private var control = InstallerDownloadControl()+ @ObservationIgnored private var rate = DownloadRate()+ // Steam downloading inside Install.command, from curl's meter.+ var scriptDownload: InstallerDownloadProgress?var failure: String?var openBridgeplay = truevar removeInstaller = true@@ -59,8 +66,13 @@ final class InstallerModel {switch preview {case "update": installedVersion = "3.3.0"; stage = .reviewcase "current": installedVersion = version; isCurrent = true; stage = .done- case "download": stage = .downloading; received = 31_659_404; total = 79_148_511; progress = 0.4+ case "download": stage = .downloading; received = 31_659_404; total = 79_148_511; progress = 0.4; speed = 2_412_000+ case "paused": stage = .downloading; received = 31_659_404; total = 79_148_511; progress = 0.4; paused = true+ case "components": stage = .downloading; settingUp = true; received = 214_958_080; total = 504_399_923; progress = 0.43; speed = 6_815_744case "install": stage = .installing+ case "steam":+ stage = .installing; settingUp = true; componentStatus = tr("Installing Steam from Valve")+ scriptDownload = InstallerDownloadProgress(received: 2_202_009, total: 4_404_019, speed: 1_310_720)case "done": stage = .donecase "error": stage = .failed; failure = tr("The download could not be verified. Your installed application has been kept.")default: stage = .review@@ -116,6 +128,11 @@ final class InstallerModel {received = 0downloadedBefore = 0progress = nil+ speed = nil+ rate = DownloadRate()+ paused = false+ control = InstallerDownloadControl()+ let control = self.controllet work = FileManager.default.temporaryDirectory.appendingPathComponent("bridgeplay-install-\(UUID().uuidString)")defer { try? FileManager.default.removeItem(at: work) }do {@@ -124,11 +141,12 @@ final class InstallerModel {Task { @MainActor inguard let self, self.stage == .downloading else { return }self.received = self.downloadedBefore + value.received+ if !self.paused { self.speed = self.rate.add(self.received) ?? self.speed }self.progress = self.total.flatMap { $0 > 0 ? Double(self.received) / Double($0) : nil }}}if !isCurrent {- let archive = try await release.download(to: work, progress: report)+ let archive = try await release.download(to: work, control: control, progress: report)try Task.checkCancellation()stage = .installingprogress = nil@@ -141,16 +159,18 @@ final class InstallerModel {settingUp = truedownloadedBefore = isCurrent ? 0 : release.archiveLengthstage = .downloading- let archive = try await components.download(to: work, progress: report)+ let archive = try await components.downloadAcrossRelease(to: work, control: control, progress: report)try Task.checkCancellation()stage = .installingprogress = nilcomponentStatus = niltry await Task.detached(priority: .userInitiated) {- try InstallerComponents.install(archive: archive, work: work) { line in+ try InstallerComponents.install(archive: archive, work: work, status: { line inInstallerLog.write("Install.command: \(line)")- Task { @MainActor [weak self] in self?.componentStatus = Self.status(line) }- }+ Task { @MainActor [weak self] in self?.componentStatus = Self.status(line); self?.scriptDownload = nil }+ }, download: { meter in+ Task { @MainActor [weak self] in self?.scriptDownload = meter }+ })}.valueself.components = nil}@@ -163,6 +183,21 @@ final class InstallerModel {}}+ func togglePause() {+ guard stage == .downloading, preview == nil else { paused.toggle(); return }+ if paused {+ control.resume()+ // Count the speed afresh rather than averaging in the pause.+ rate = DownloadRate()+ speed = nil+ InstallerLog.write("Download resumed")+ } else {+ control.pause()+ InstallerLog.write("Download paused at \(received) bytes")+ }+ paused = control.isPaused+ }+func cancel() {guard stage != .installing else { return }operation?.cancel()diff --git a/app/Sources/BridgeplayInstaller/InstallerView.swift b/app/Sources/BridgeplayInstaller/InstallerView.swiftindex 72b7807..cb9caa7 100644--- a/app/Sources/BridgeplayInstaller/InstallerView.swift+++ b/app/Sources/BridgeplayInstaller/InstallerView.swift@@ -148,15 +148,28 @@ struct InstallerView: View {SetupCard {VStack(alignment: .leading, spacing: 14) {HStack(spacing: 10) {- ProgressView().controlSize(.small)- Text(model.stage == .downloading ? tr("Downloading") : model.componentStatus ?? tr("Verifying and installing"))+ if model.paused { Image(systemName: "pause.circle.fill").foregroundStyle(BP.fg2) }+ else { ProgressView().controlSize(.small) }+ Text(model.stage == .downloading ? (model.paused ? tr("Paused") : tr("Downloading"))+ : model.componentStatus ?? tr("Verifying and installing")).font(BP.sans(13, .semibold))}if model.stage == .downloading {if let value = model.progress {ProgressView(value: min(max(value, 0), 1)).tint(BP.blue)} else { ProgressView().progressViewStyle(.linear).tint(BP.blue) }- Text(model.total.map { "\(bytes(model.received)) / \(bytes($0))" } ?? bytes(model.received))+ HStack(spacing: 12) {+ Text(DownloadRate.amount(received: model.received, total: model.total, speed: model.paused ? nil : model.speed))+ .font(BP.sans(12)).monospacedDigit().foregroundStyle(BP.fg2)+ Spacer(minLength: 8)+ Button(model.paused ? tr("Resume") : tr("Pause")) { model.togglePause() }+ .buttonStyle(.pillSecondary)+ }+ } else if let meter = model.scriptDownload {+ if let total = meter.total {+ ProgressView(value: min(max(Double(meter.received) / Double(total), 0), 1)).tint(BP.blue)+ } else { ProgressView().progressViewStyle(.linear).tint(BP.blue) }+ Text(DownloadRate.amount(received: meter.received, total: meter.total, speed: meter.speed)).font(BP.sans(12)).monospacedDigit().foregroundStyle(BP.fg2)}}diff --git a/app/Sources/BridgeplayInstaller/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayInstaller/Resources/Localization/Localizable.xcstringsindex 417c55a..eaa4326 100644--- a/app/Sources/BridgeplayInstaller/Resources/Localization/Localizable.xcstrings+++ b/app/Sources/BridgeplayInstaller/Resources/Localization/Localizable.xcstrings@@ -649,6 +649,38 @@}}},+ "Pause" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Pausa"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "暂停"+ }+ }+ }+ },+ "Paused" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "In pausa"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "已暂停"+ }+ }+ }+ },"Quit Bridgeplay and its updater, then try again." : {"localizations" : {"en" : {@@ -687,6 +719,22 @@}}},+ "Resume" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Riprendi"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "继续"+ }+ }+ }+ },"Review" : {"localizations" : {"it" : {diff --git a/app/Sources/BridgeplayInstallerCore/InstallerComponents.swift b/app/Sources/BridgeplayInstallerCore/InstallerComponents.swiftindex 82e5b4e..2d9558f 100644--- a/app/Sources/BridgeplayInstallerCore/InstallerComponents.swift+++ b/app/Sources/BridgeplayInstallerCore/InstallerComponents.swift@@ -69,17 +69,17 @@ public struct InstallerComponents: Sendable, Equatable {}/// Download to a file in `directory` and verify it. Throws without leaving the file on failure.- public func download(to directory: URL, session: URLSession = .shared,+ public func download(to directory: URL, session: URLSession = .shared, control: InstallerDownloadControl? = nil,progress: @escaping @Sendable (InstallerDownloadProgress) -> Void = { _ in }) async throws -> URL {var request = URLRequest(url: archiveURL)request.timeoutInterval = 60let temporary: URL, response: URLResponse- do { (temporary, response) = try await InstallerFileDownload.run(request, total: length, progress: progress) }+ do { (temporary, response) = try await InstallerFileDownload.run(request, total: length, control: control, progress: progress) }catch is CancellationError { throw CancellationError() }catch { throw InstallerError.networkFailure(error.localizedDescription) }let archive = directory.appending(path: "Bridgeplay-Installer.zip")do {- guard archiveURL.isFileURL || (response as? HTTPURLResponse)?.statusCode == 200 else { throw InstallerError.invalidRelease }+ guard archiveURL.isFileURL || [200, 206].contains((response as? HTTPURLResponse)?.statusCode) else { throw InstallerError.invalidRelease }try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)try? FileManager.default.removeItem(at: archive)try FileManager.default.moveItem(at: temporary, to: archive)@@ -92,6 +92,22 @@ public struct InstallerComponents: Sendable, Equatable {return archive}+ /// A release replaces the archive, then its .sig, a few seconds apart (release-local.sh+ /// swap_asset). A download in that gap 404s or fails its check: fetch the .sig again and retry.+ public func downloadAcrossRelease(to directory: URL, attempts: Int = 3, control: InstallerDownloadControl? = nil,+ progress: @escaping @Sendable (InstallerDownloadProgress) -> Void = { _ in }) async throws -> URL {+ var components = self+ for attempt in 1... {+ do { return try await components.download(to: directory, control: control, progress: progress) }+ catch let error as InstallerError where attempt < attempts && error.mayBeReleaseSwap {+ InstallerLog.write("Components \(error), fetching the signature again, try \(attempt + 1) of \(attempts)")+ try await Task.sleep(for: .seconds(10))+ components = try await Self.latest()+ }+ }+ fatalError("unreachable")+ }+// CEILING: Ed25519 signs the whole file, so it is mapped and checked at once (~0.5 GB of// address space); a streamed check would need a different signature scheme.func verify(_ archive: URL) throws {@@ -103,7 +119,8 @@ public struct InstallerComponents: Sendable, Equatable {/// Unpack the verified archive and run its Install.command for Steam, GPTK, the engine and/// the configs. `status` gets each "==>" step the script announces.- public static func install(archive: URL, work: URL, status: @escaping @Sendable (String) -> Void = { _ in }) throws {+ public static func install(archive: URL, work: URL, status: @escaping @Sendable (String) -> Void = { _ in },+ download: @escaping @Sendable (InstallerDownloadProgress) -> Void = { _ in }) throws {let unpacked = work.appending(path: "components")try? FileManager.default.removeItem(at: unpacked)try FileManager.default.createDirectory(at: unpacked, withIntermediateDirectories: true)@@ -117,6 +134,7 @@ public struct InstallerComponents: Sendable, Equatable {environment["BRIDGEPLAY_NONINTERACTIVE"] = "1"try run("/bin/bash", [script.path], environment: environment) { line inif line.hasPrefix("==> ") { status(String(line.dropFirst(4))) }+ else if let meter = InstallerDownloadProgress(curlMeter: line) { download(meter) }}}@@ -154,6 +172,44 @@ public struct InstallerComponents: Sendable, Equatable {}}+/// Pauses and resumes the installer's running download. A suspended task sends nothing and+/// times nothing out; if the server drops the idle connection, the resume picks it up again.+public final class InstallerDownloadControl: @unchecked Sendable {+ private let lock = NSLock()+ private var task: URLSessionTask?+ private var paused = false++ public init() {}++ public var isPaused: Bool { lock.withLock { paused } }++ public func pause() {+ lock.withLock {+ guard !paused else { return }+ paused = true+ task?.suspend()+ }+ }++ public func resume() {+ lock.withLock {+ guard paused else { return }+ paused = false+ task?.resume()+ }+ }++ /// Starts the task, or holds it suspended while paused.+ func start(_ task: URLSessionTask) {+ lock.withLock {+ self.task = task+ if !paused { task.resume() }+ }+ }++ func detach() { lock.withLock { task = nil } }+}+/// Downloads to a file with progress. A task delegate passed to `URLSession.download(for:delegate:)`/// gets no progress callbacks, so each download gets its own session with this delegate./// The file is moved out of URLSession's temporary location before the callback returns.@@ -169,16 +225,46 @@ final class InstallerFileDownload: NSObject, URLSessionDownloadDelegate, @unchecself.progress = progress}- static func run(_ request: URLRequest, total: Int64,+ static let resumableErrors: Set<URLError.Code> = [+ .networkConnectionLost, .timedOut, .notConnectedToInternet, .cannotConnectToHost, .cannotFindHost, .dnsLookupFailed,+ ]++ /// A dropped connection resumes where it stopped (#143: 500 MB restarted from zero on each+ /// try). A resume the server refuses (an expired download link) starts over.+ static func run(_ request: URLRequest, total: Int64, attempts: Int = 4, control: InstallerDownloadControl? = nil,progress: @escaping @Sendable (InstallerDownloadProgress) -> Void) async throws -> (URL, URLResponse) {+ var resumeData: Data?+ for attempt in 1... {+ do {+ let (file, response) = try await once(request, resumeData: resumeData, total: total, control: control, progress: progress)+ let status = (response as? HTTPURLResponse)?.statusCode+ if resumeData != nil, status != 200, status != 206, attempt < attempts {+ try? FileManager.default.removeItem(at: file)+ InstallerLog.write("Resume refused (\(status ?? 0)), downloading \(request.url?.lastPathComponent ?? "") again")+ resumeData = nil+ continue+ }+ return (file, response)+ } catch let error as URLError where attempt < attempts && resumableErrors.contains(error.code) {+ resumeData = error.downloadTaskResumeData+ InstallerLog.write("Download interrupted (\(error.localizedDescription)), \(resumeData == nil ? "restarting" : "resuming"), try \(attempt + 1) of \(attempts)")+ try await Task.sleep(for: .seconds(2 * attempt))+ }+ }+ fatalError("unreachable")+ }++ private static func once(_ request: URLRequest, resumeData: Data?, total: Int64, control: InstallerDownloadControl?,+ progress: @escaping @Sendable (InstallerDownloadProgress) -> Void) async throws -> (URL, URLResponse) {let delegate = InstallerFileDownload(total: total, progress: progress)let session = URLSession(configuration: .ephemeral, delegate: delegate, delegateQueue: nil)defer { session.finishTasksAndInvalidate() }- let task = session.downloadTask(with: request)+ defer { control?.detach() }+ let task = resumeData.map { session.downloadTask(withResumeData: $0) } ?? session.downloadTask(with: request)return try await withTaskCancellationHandler {try await withCheckedThrowingContinuation { continuation indelegate.lock.withLock { delegate.continuation = continuation }- task.resume()+ control?.start(task) ?? task.resume()}} onCancel: { task.cancel() }}diff --git a/app/Sources/BridgeplayInstallerCore/InstallerRelease.swift b/app/Sources/BridgeplayInstallerCore/InstallerRelease.swiftindex a92b132..cd0e18c 100644--- a/app/Sources/BridgeplayInstallerCore/InstallerRelease.swift+++ b/app/Sources/BridgeplayInstallerCore/InstallerRelease.swift@@ -4,10 +4,28 @@ import Foundationpublic struct InstallerDownloadProgress: Sendable, Equatable {public let received: Int64public let total: Int64?+ /// Bytes per second, when the source reports it (curl's meter).+ public let speed: Double?- public init(received: Int64, total: Int64?) {+ public init(received: Int64, total: Int64?, speed: Double? = nil) {self.received = receivedself.total = total+ self.speed = speed+ }++ /// One line of curl's progress meter, which Install.command shows while it downloads Steam:+ /// " 45 4200k 45 1890k 0 0 2105k 0 0:00:01 0:00:00 0:00:01 2105k"+ public init?(curlMeter line: String) {+ let fields = line.split(separator: " ")+ guard fields.count == 12, Int(fields[0]) != nil, let total = Self.curlBytes(fields[1]),+ let received = Self.curlBytes(fields[3]), let speed = Self.curlBytes(fields[11]) else { return nil }+ self.init(received: received, total: total > 0 ? total : nil, speed: Double(speed))+ }++ private static func curlBytes(_ text: Substring) -> Int64? {+ let units: [Character: Double] = ["k": 1024, "M": 1_048_576, "G": 1_073_741_824]+ if let unit = text.last.flatMap({ units[$0] }), let value = Double(text.dropLast()) { return Int64(value * unit) }+ return Int64(text)}}@@ -134,6 +152,7 @@ public struct InstallerRelease: Sendable, Equatable {public func download(to destination: URL,session: URLSession = .shared,+ control: InstallerDownloadControl? = nil,progress: @escaping @Sendable (InstallerDownloadProgress) -> Void = { _ in }) async throws -> URL {guard destination.isFileURL else { throw InstallerError.invalidDestination }@@ -144,7 +163,7 @@ public struct InstallerRelease: Sendable, Equatable {let temporary: URLlet response: URLResponsedo {- (temporary, response) = try await InstallerFileDownload.run(request, total: archiveLength, progress: progress)+ (temporary, response) = try await InstallerFileDownload.run(request, total: archiveLength, control: control, progress: progress)} catch is CancellationError {throw CancellationError()} catch {@@ -152,7 +171,8 @@ public struct InstallerRelease: Sendable, Equatable {}defer { try? FileManager.default.removeItem(at: temporary) }- guard let http = response as? HTTPURLResponse, http.statusCode == 200,+ // 206: a resumed download (InstallerFileDownload).+ guard let http = response as? HTTPURLResponse, [200, 206].contains(http.statusCode),let finalURL = http.url, Self.isArchiveResponseURL(finalURL) else {throw InstallerError.invalidRelease}@@ -323,6 +343,14 @@ public enum InstallerError: LocalizedError, Sendable {case replacementFailure(String)case componentsFailure(String)+ /// What a download caught between a release's archive and .sig swaps fails with.+ var mayBeReleaseSwap: Bool {+ switch self {+ case .invalidRelease, .invalidArchiveLength, .signatureMismatch: true+ default: false+ }+ }+public var errorDescription: String? {switch self {case .invalidRelease: "The Bridgeplay release information could not be verified."diff --git a/app/Sources/BridgeplayUI/DownloadRate.swift b/app/Sources/BridgeplayUI/DownloadRate.swiftnew file mode 100644index 0000000..3b88be2--- /dev/null+++ b/app/Sources/BridgeplayUI/DownloadRate.swift@@ -0,0 +1,27 @@+import Foundation++/// Download speed over the last few seconds, shown beside every download's progress.+public struct DownloadRate: Sendable {+ private var samples: [(time: TimeInterval, bytes: Int64)] = []++ public init() {}++ /// Bytes per second, once a second of samples is in.+ public mutating func add(_ bytes: Int64, at time: TimeInterval = ProcessInfo.processInfo.systemUptime) -> Double? {+ // Fewer bytes than before: the download started over.+ if let last = samples.last, bytes < last.bytes { samples.removeAll() }+ samples.append((time, bytes))+ // The last five seconds, but always two samples, so sparse reports still give a rate.+ while samples.count > 2, time - samples[0].time > 5 { samples.removeFirst() }+ guard let first = samples.first, time - first.time >= 1 else { return nil }+ return Double(bytes - first.bytes) / (time - first.time)+ }++ /// "31.7 MB / 79.1 MB · 2.4 MB/s"+ public static func amount(received: Int64, total: Int64?, speed: Double?) -> String {+ var text = ByteCountFormatter.string(fromByteCount: received, countStyle: .file)+ if let total { text += " / " + ByteCountFormatter.string(fromByteCount: total, countStyle: .file) }+ if let speed { text += " · " + ByteCountFormatter.string(fromByteCount: Int64(max(speed, 0)), countStyle: .file) + "/s" }+ return text+ }+}diff --git a/app/Tests/BridgeplayAppTests/DownloadProgressLabelTests.swift b/app/Tests/BridgeplayAppTests/DownloadProgressLabelTests.swiftindex 1d0a47d..e3c858b 100644--- a/app/Tests/BridgeplayAppTests/DownloadProgressLabelTests.swift+++ b/app/Tests/BridgeplayAppTests/DownloadProgressLabelTests.swift@@ -1,4 +1,6 @@+import Foundationimport Testing+import BridgeplayUI@testable import BridgeplayApp@Suite("Download progress label")@@ -13,4 +15,22 @@ struct DownloadProgressLabelTests {let label = PinnedDownload.Progress.label(host: "github.com", received: 0, total: 400_000_000, remaining: nil)#expect(label == "Downloading from github.com: Zero KB / 400 MB")}++ @Test func showsTheSpeed() {+ let label = PinnedDownload.Progress.label(host: "github.com", received: 100_000_000, total: 400_000_000, remaining: nil, speed: 2_400_000)+ let speed = ByteCountFormatter.string(fromByteCount: 2_400_000, countStyle: .file)+ #expect(label == "Downloading from github.com: 100 MB / 400 MB · \(speed)/s")+ }++ @Test func speedCoversTheLastFewSeconds() {+ var rate = DownloadRate()+ #expect(rate.add(0, at: 0) == nil)+ #expect(rate.add(500_000, at: 0.5) == nil)+ #expect(rate.add(1_000_000, at: 1) == 1_000_000)+ // A stall then a burst: only the last five seconds or so count.+ _ = rate.add(1_000_000, at: 10)+ #expect(rate.add(5_000_000, at: 12) == 2_000_000)+ // Started over: no speed until a second has passed again.+ #expect(rate.add(0, at: 13) == nil)+ }}diff --git a/app/Tests/BridgeplayInstallerCoreTests/InstallerFileDownloadTests.swift b/app/Tests/BridgeplayInstallerCoreTests/InstallerFileDownloadTests.swiftnew file mode 100644index 0000000..05aa828--- /dev/null+++ b/app/Tests/BridgeplayInstallerCoreTests/InstallerFileDownloadTests.swift@@ -0,0 +1,123 @@+import Foundation+import Network+import Testing+@testable import BridgeplayInstallerCore++@Suite("Installer file download")+struct InstallerFileDownloadTests {+ /// Serves `body` over HTTP on localhost. The first request gets half the body and the+ /// connection drops; later ones honour `Range: bytes=N-`.+ final class DroppingServer: @unchecked Sendable {+ let body: Data+ let listener: NWListener+ let lock = NSLock()+ var requests: [String] = []++ init(body: Data) throws {+ self.body = body+ listener = try NWListener(using: .tcp, on: .any)+ listener.newConnectionHandler = { [self] connection in+ connection.start(queue: .global())+ connection.receive(minimumIncompleteLength: 1, maximumLength: 65_536) { data, _, _, _ in+ self.answer(String(decoding: data ?? Data(), as: UTF8.self), on: connection)+ }+ }+ }++ func start() async throws -> Int {+ let ready = AsyncStream<UInt16> { continuation in+ listener.stateUpdateHandler = { [listener] state in+ if case .ready = state { continuation.yield(listener.port?.rawValue ?? 0); continuation.finish() }+ }+ }+ listener.start(queue: .global())+ for await port in ready { return Int(port) }+ throw URLError(.cannotConnectToHost)+ }++ private func answer(_ request: String, on connection: NWConnection) {+ let first = lock.withLock { requests.append(request); return requests.count == 1 }+ let range = request.split(separator: "\r\n")+ .first { $0.lowercased().hasPrefix("range: bytes=") }+ .flatMap { Int($0.dropFirst("range: bytes=".count).split(separator: "-").first ?? "") }+ let from = range ?? 0+ var head = range == nil ? "HTTP/1.1 200 OK\r\n" : "HTTP/1.1 206 Partial Content\r\n"+ if range != nil { head += "Content-Range: bytes \(from)-\(body.count - 1)/\(body.count)\r\n" }+ head += "Content-Length: \(body.count - from)\r\nAccept-Ranges: bytes\r\nETag: \"fixed\"\r\n"+ head += "Last-Modified: Wed, 21 Oct 2026 07:28:00 GMT\r\nConnection: close\r\n\r\n"+ let rest = body[from...]+ let sent = first ? rest.prefix(rest.count / 2) : rest+ connection.send(content: Data(head.utf8) + sent, completion: .contentProcessed { _ in+ if first {+ // Give the client time to write the first half before the connection drops.+ DispatchQueue.global().asyncAfter(deadline: .now() + 0.5) { connection.cancel() }+ } else {+ connection.cancel()+ }+ })+ }+ }++ final class Seen: @unchecked Sendable {+ let lock = NSLock()+ var values: [Int64] = []+ }++ @Test("A dropped download resumes from where it stopped")+ func resumes() async throws {+ let body = Data((0..<4_000_000).map { UInt8(truncatingIfNeeded: $0 &* 31) })+ let server = try DroppingServer(body: body)+ defer { server.listener.cancel() }+ let port = try await server.start()+ let request = URLRequest(url: URL(string: "http://127.0.0.1:\(port)/Bridgeplay-Installer.zip")!)+ let seen = Seen()+ let (file, response) = try await InstallerFileDownload.run(request, total: Int64(body.count)) { value in+ seen.lock.withLock { seen.values.append(value.received) }+ }+ defer { try? FileManager.default.removeItem(at: file) }+ #expect(try Data(contentsOf: file) == body)+ #expect([200, 206].contains((response as? HTTPURLResponse)?.statusCode))+ let requests = server.lock.withLock { server.requests }+ #expect(requests.count == 2)+ #expect(requests.last?.lowercased().contains("range: bytes=") == true)+ // The progress bar carries on from the resumed offset instead of starting over.+ let values = seen.lock.withLock { seen.values }+ #expect(values.last == Int64(body.count))+ #expect(zip(values, values.dropFirst()).allSatisfy { $0 <= $1 })+ }++ @Test("A paused download sends nothing until it is resumed")+ func pauses() async throws {+ let body = Data((0..<1_000_000).map { UInt8(truncatingIfNeeded: $0 &* 7) })+ let server = try DroppingServer(body: body)+ defer { server.listener.cancel() }+ let port = try await server.start()+ let request = URLRequest(url: URL(string: "http://127.0.0.1:\(port)/Bridgeplay-Installer.zip")!)+ let control = InstallerDownloadControl()+ control.pause()+ let download = Task { try await InstallerFileDownload.run(request, total: Int64(body.count), control: control) { _ in } }+ try await Task.sleep(for: .seconds(1))+ #expect(server.lock.withLock { server.requests.isEmpty })+ control.resume()+ let (file, _) = try await download.value+ defer { try? FileManager.default.removeItem(at: file) }+ #expect(try Data(contentsOf: file) == body)+ #expect(!control.isPaused)+ }++ @Test("Only failures a release swap can cause are retried")+ func releaseSwap() {+ #expect(InstallerError.signatureMismatch.mayBeReleaseSwap)+ #expect(InstallerError.invalidRelease.mayBeReleaseSwap)+ #expect(!InstallerError.networkFailure("x").mayBeReleaseSwap)+ }++ @Test("curl's progress meter reads as bytes, total and speed")+ func curlMeter() throws {+ let meter = try #require(InstallerDownloadProgress(curlMeter: "45 4200k 45 1890k 0 0 2105k 0 0:00:01 0:00:00 0:00:01 1.5M"))+ #expect(meter.received == 1890 * 1024 && meter.total == 4200 * 1024 && meter.speed == 1.5 * 1_048_576)+ #expect(InstallerDownloadProgress(curlMeter: "0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0")?.total == nil)+ #expect(InstallerDownloadProgress(curlMeter: "% Total % Received % Xferd Average Speed Time Time Time Current") == nil)+ #expect(InstallerDownloadProgress(curlMeter: "Dload Upload Total Spent Left Speed") == nil)+ }+}diff --git a/installer/Install.command b/installer/Install.commandindex 277a7c2..a119e07 100755--- a/installer/Install.command+++ b/installer/Install.command@@ -71,7 +71,7 @@ app_src="$here/Bridgeplay.app"if [ "$install_app" = 1 ] && [ ! -d "$app_src" ]; thensay "Mengunduh Bridgeplay versi terbaru..."app_tmp="$(mktemp -d)"- curl -fL --retry 3 --connect-timeout 20 --progress-bar -o "$app_tmp/Bridgeplay.zip" "$app_url" \+ curl -fL --retry 3 --connect-timeout 20 -o "$app_tmp/Bridgeplay.zip" "$app_url" \|| die "Bridgeplay gagal diunduh. Cek koneksi internet, lalu jalankan Install.command lagi."ditto -x -k "$app_tmp/Bridgeplay.zip" "$app_tmp" || die "File Bridgeplay yang diunduh rusak. Jalankan Install.command lagi."app_src="$app_tmp/Bridgeplay.app"@@ -101,7 +101,7 @@ if [ ! -d /Applications/Steam.app ]; thensay "Steam belum terpasang. Mengunduh installer Steam resmi dari Valve..."steam_tmp="$(mktemp -d)" || die "Folder sementara tidak bisa dibuat."dmg="$steam_tmp/steam.dmg"- curl -fL --retry 3 --connect-timeout 20 --progress-bar -o "$dmg" "$steam_url" \+ curl -fL --retry 3 --connect-timeout 20 -o "$dmg" "$steam_url" \|| die "Steam gagal diunduh. Pastikan Mac tersambung ke internet, lalu jalankan Install.command lagi."# A UDIF disk image ends with a 512-byte trailer that starts with "koly".[ "$(tail -c 512 "$dmg" | head -c 4)" = "koly" ] \