2019-06-21 11:20:03 -07:00
|
|
|
//
|
|
|
|
|
// SendAppOperation.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 6/7/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
import Foundation
|
|
|
|
|
import Network
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
import AltStoreCore
|
2023-04-01 16:02:12 -07:00
|
|
|
import minimuxer
|
2020-09-03 16:39:08 -07:00
|
|
|
|
2019-06-21 11:20:03 -07:00
|
|
|
@objc(SendAppOperation)
|
2023-01-04 09:52:12 -05:00
|
|
|
final class SendAppOperation: ResultOperation<()>
|
2019-06-21 11:20:03 -07:00
|
|
|
{
|
2021-10-25 22:27:30 -07:00
|
|
|
let context: InstallAppOperationContext
|
2019-06-21 11:20:03 -07:00
|
|
|
|
2022-11-02 17:58:59 -07:00
|
|
|
private let dispatchQueue = DispatchQueue(label: "com.sidestore.SendAppOperation")
|
2019-06-21 11:20:03 -07:00
|
|
|
|
2021-10-25 22:27:30 -07:00
|
|
|
init(context: InstallAppOperationContext)
|
2019-06-21 11:20:03 -07:00
|
|
|
{
|
|
|
|
|
self.context = context
|
|
|
|
|
|
|
|
|
|
super.init()
|
|
|
|
|
|
|
|
|
|
self.progress.totalUnitCount = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func main()
|
|
|
|
|
{
|
|
|
|
|
super.main()
|
|
|
|
|
|
|
|
|
|
if let error = self.context.error
|
|
|
|
|
{
|
|
|
|
|
self.finish(.failure(error))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:58:59 -07:00
|
|
|
guard let resignedApp = self.context.resignedApp else { return self.finish(.failure(OperationError.invalidParameters)) }
|
2019-07-28 15:08:13 -07:00
|
|
|
|
|
|
|
|
// self.context.resignedApp.fileURL points to the app bundle, but we want the .ipa.
|
2022-09-08 15:59:24 -05:00
|
|
|
let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL)
|
2019-07-28 15:08:13 -07:00
|
|
|
let fileURL = InstalledApp.refreshedIPAURL(for: app)
|
2019-06-21 11:20:03 -07:00
|
|
|
|
2022-12-03 17:25:15 -05:00
|
|
|
print("AFC App `fileURL`: \(fileURL.absoluteString)")
|
2022-11-02 17:58:59 -07:00
|
|
|
|
|
|
|
|
if let data = NSData(contentsOf: fileURL) {
|
2023-04-01 16:02:12 -07:00
|
|
|
do {
|
|
|
|
|
let bytes = Data(data).toRustByteSlice()
|
|
|
|
|
try yeet_app_afc(app.bundleIdentifier, bytes.forRust())
|
|
|
|
|
} catch {
|
2023-04-11 21:04:07 -07:00
|
|
|
return self.finish(.failure(error))
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
2022-11-02 17:58:59 -07:00
|
|
|
|
2023-04-01 16:02:12 -07:00
|
|
|
self.progress.completedUnitCount += 1
|
|
|
|
|
self.finish(.success(()))
|
2022-11-02 17:58:59 -07:00
|
|
|
} else {
|
2023-04-01 16:02:12 -07:00
|
|
|
print("IPA doesn't exist????")
|
2022-11-02 17:58:59 -07:00
|
|
|
self.finish(.failure(ALTServerError(.underlyingError)))
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|