diff --git a/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift b/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift index 5e91dc8f..206cb45f 100644 --- a/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift +++ b/Supersign/DeveloperServices/DeveloperServicesProvisioningOperation.swift @@ -23,18 +23,24 @@ public struct DeveloperServicesProvisioningOperation: DeveloperServicesOperation public let context: SigningContext public let app: URL - public init(context: SigningContext, app: URL) { + public let progress: (Double) -> Void + public init(context: SigningContext, app: URL, progress: @escaping (Double) -> Void) { self.context = context self.app = app + self.progress = progress } public func perform(completion: @escaping (Result) -> Void) { + progress(0/3) DeveloperServicesFetchDeviceOperation(context: context).perform { result in guard result.get(withErrorHandler: completion) != nil else { return } + self.progress(1/3) DeveloperServicesFetchCertificateOperation(context: self.context).perform { result in guard let signingInfo = result.get(withErrorHandler: completion) else { return } + self.progress(2/3) DeveloperServicesAddAppOperation(context: self.context, root: self.app).perform { result in guard let provisioningDict = result.get(withErrorHandler: completion) else { return } + self.progress(3/3) completion(.success(.init(signingInfo: signingInfo, provisioningDict: provisioningDict))) } } diff --git a/Supersign/GrandSlam/GrandSlamClient.swift b/Supersign/GrandSlam/GrandSlamClient.swift index 76ddd225..b8d37aae 100644 --- a/Supersign/GrandSlam/GrandSlamClient.swift +++ b/Supersign/GrandSlam/GrandSlamClient.swift @@ -32,8 +32,6 @@ class GrandSlamClient { url: URL, completion: @escaping (Result) -> Void ) { - print("Sending: \(request) to \(url)") - var urlRequest = URLRequest(url: url) urlRequest.setValue("text/x-xml-plist", forHTTPHeaderField: "Content-Type") urlRequest.setValue(deviceInfo.clientInfo.clientString, forHTTPHeaderField: DeviceInfo.clientInfoKey) diff --git a/Supersign/Installation/AppInstaller.swift b/Supersign/Installation/AppInstaller.swift index ac17b93b..4415100c 100644 --- a/Supersign/Installation/AppInstaller.swift +++ b/Supersign/Installation/AppInstaller.swift @@ -79,7 +79,7 @@ public class AppInstaller { ipa: URL, bundleID: String, udid: String, - pairingKeys: URL, + pairingKeys: Data, progress: @escaping (Stage) -> Void ) throws { let connection = try Connection(udid: udid, pairingKeys: pairingKeys) { @@ -109,7 +109,7 @@ public class AppInstaller { ipa: URL, bundleID: String, udid: String, - pairingKeys: URL, + pairingKeys: Data, progress: @escaping (Stage) -> Void, completion: @escaping (Result<(), Swift.Error>) -> Void ) { diff --git a/Supersign/Installation/Connection.swift b/Supersign/Installation/Connection.swift index 9d56fcc6..a1995bd0 100644 --- a/Supersign/Installation/Connection.swift +++ b/Supersign/Installation/Connection.swift @@ -20,10 +20,10 @@ public class Connection { public let client: LockdownClient private let heartbeatHandler: HeartbeatHandler - public init(udid: String, pairingKeys: URL, progress: (Double) -> Void) throws { + public init(udid: String, pairingKeys: Data, progress: (Double) -> Void) throws { progress(0/4) - usbmuxHandler = USBMuxHandler(udid: udid, pairingKeys: pairingKeys) + usbmuxHandler = try USBMuxHandler(udid: udid, pairingKeys: pairingKeys) progress(1/4) device = try Device(udid: udid) diff --git a/Supersign/Installation/IPAUploader.swift b/Supersign/Installation/IPAUploader.swift index 6c9f6e87..de50822a 100644 --- a/Supersign/Installation/IPAUploader.swift +++ b/Supersign/Installation/IPAUploader.swift @@ -9,9 +9,10 @@ import Foundation import SwiftyMobileDevice -public class IPAUploader { +public final class IPAUploader { private static let packagePath = URL(fileURLWithPath: "PublicStaging") + private static let bufferSize = 1 << 20 // 1 MB public class UploadedIPA { public let uploader: IPAUploader @@ -36,25 +37,26 @@ public class IPAUploader { } private func upload(_ src: URL, to dest: URL, progress: (Double) -> Void) throws { - let srcHandle = try FileHandle(forReadingFrom: src) - let size = srcHandle.seekToEndOfFile() - srcHandle.seek(toFileOffset: 0) - + let srcData = try Data(contentsOf: src) + let size = srcData.count + let sizeDouble = Double(size) let destFile = try client.open(dest, mode: .writeOnly) + let bufferSize = Self.bufferSize + var totalWritten = 0 - var buf: Data - repeat { - buf = srcHandle.readData(ofLength: 1 << 20) // 1 MB + while totalWritten != size { + let buf = srcData.dropFirst(totalWritten).prefix(bufferSize) + let bufSize = buf.count var bufWritten = 0 - while bufWritten < buf.count { + while bufWritten < bufSize { // not sure if rewriting the same buf is a bug but ideviceinstaller does it this way let written = try destFile.write(buf) bufWritten += written totalWritten += written - progress(Double(totalWritten) / Double(size)) + progress(Double(totalWritten) / sizeDouble) } - } while !buf.isEmpty + } } public func upload(ipa: URL, withBundleID bundleID: String, progress: (Double) -> Void) throws -> UploadedIPA { diff --git a/Supersign/Signer/Signer.swift b/Supersign/Signer/Signer.swift index cedcd339..ad889f6d 100644 --- a/Supersign/Signer/Signer.swift +++ b/Supersign/Signer/Signer.swift @@ -70,6 +70,8 @@ public struct Signer { } let entitlements = provisioningDict.mapValues { $0.entitlements } + + status(NSLocalizedString("signer.signing", value: "Signing", comment: "")) context.signerImpl.sign( app: app, certificate: signingInfo.certificate, @@ -86,8 +88,8 @@ public struct Signer { progress: @escaping (Double) -> Void, completion: @escaping (Result<(), Swift.Error>) -> Void ) { - status(NSLocalizedString("signer.signing", value: "Signing", comment: "")) - DeveloperServicesProvisioningOperation(context: context, app: app).perform { result in + status(NSLocalizedString("signer.provisioning", value: "Provisioning", comment: "")) + DeveloperServicesProvisioningOperation(context: context, app: app, progress: progress).perform { result in guard let response = result.get(withErrorHandler: completion) else { return } self.sign( app: app,