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
|
|
|
|
|
|
2019-06-21 11:20:03 -07:00
|
|
|
@objc(SendAppOperation)
|
2022-11-02 17:58:59 -07:00
|
|
|
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.
|
2021-10-25 22:27:30 -07:00
|
|
|
let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.url)
|
2019-07-28 15:08:13 -07:00
|
|
|
let fileURL = InstalledApp.refreshedIPAURL(for: app)
|
2019-06-21 11:20:03 -07:00
|
|
|
|
2022-11-02 17:58:59 -07:00
|
|
|
|
|
|
|
|
let ns_bundle = NSString(string: app.bundleIdentifier)
|
|
|
|
|
let ns_bundle_ptr = UnsafeMutablePointer<CChar>(mutating: ns_bundle.utf8String)
|
2019-06-21 11:20:03 -07:00
|
|
|
|
2022-11-02 17:58:59 -07:00
|
|
|
if let data = NSData(contentsOf: fileURL) {
|
|
|
|
|
let pls = UnsafeMutablePointer<UInt8>.allocate(capacity: data.length)
|
|
|
|
|
for (index, data) in data.enumerated() {
|
|
|
|
|
pls[index] = data
|
2020-06-04 19:53:10 -07:00
|
|
|
}
|
2022-11-02 17:58:59 -07:00
|
|
|
let res = minimuxer_yeet_app_afc(ns_bundle_ptr, pls, UInt(data.length))
|
|
|
|
|
if res == 0 {
|
|
|
|
|
self.progress.completedUnitCount += 1
|
|
|
|
|
self.finish(.success(()))
|
|
|
|
|
} else {
|
|
|
|
|
self.finish(.failure(minimuxer_to_operation(code: res)))
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
2022-11-02 17:58:59 -07:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
self.finish(.failure(ALTServerError(.underlyingError)))
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|