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
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 02:20:44 -07:00
|
|
|
override func main() {
|
2019-06-21 11:20:03 -07:00
|
|
|
super.main()
|
2025-04-01 02:20:44 -07:00
|
|
|
|
|
|
|
|
if let error = self.context.error {
|
2023-07-11 01:44:11 -04:00
|
|
|
return self.finish(.failure(error))
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
2025-04-01 02:20:44 -07:00
|
|
|
|
2024-11-09 14:35:18 +05:30
|
|
|
guard let resignedApp = self.context.resignedApp else {
|
|
|
|
|
return self.finish(.failure(OperationError.invalidParameters("SendAppOperation.main: self.resignedApp is nil")))
|
|
|
|
|
}
|
2025-04-01 02:20:44 -07:00
|
|
|
|
2025-03-31 22:36:55 -07:00
|
|
|
let shortcutURLoff = URL(string: "shortcuts://run-shortcut?name=TurnOffData")!
|
|
|
|
|
let shortcutURLon = URL(string: "shortcuts://run-shortcut?name=TurnOnData")!
|
|
|
|
|
|
2023-11-29 15:15:36 -06:00
|
|
|
let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL, storeApp: nil)
|
2019-07-28 15:08:13 -07:00
|
|
|
let fileURL = InstalledApp.refreshedIPAURL(for: app)
|
2022-12-03 17:25:15 -05:00
|
|
|
print("AFC App `fileURL`: \(fileURL.absoluteString)")
|
2025-04-01 02:20:44 -07:00
|
|
|
|
|
|
|
|
// Wait for Shortcut to Finish Before Proceeding
|
|
|
|
|
UIApplication.shared.open(shortcutURLoff, options: [:]) { _ in
|
|
|
|
|
print("Shortcut finished execution. Proceeding with file transfer.")
|
|
|
|
|
|
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
|
self.processFile(at: fileURL, for: app.bundleIdentifier)
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
2025-04-01 02:20:44 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func processFile(at fileURL: URL, for bundleIdentifier: String) {
|
|
|
|
|
guard let data = NSData(contentsOf: fileURL) else {
|
2023-04-01 16:02:12 -07:00
|
|
|
print("IPA doesn't exist????")
|
2025-04-01 02:20:44 -07:00
|
|
|
return self.finish(.failure(OperationError(.appNotFound(name: bundleIdentifier))))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
let bytes = Data(data).toRustByteSlice()
|
|
|
|
|
try yeet_app_afc(bundleIdentifier, bytes.forRust())
|
|
|
|
|
self.progress.completedUnitCount += 1
|
|
|
|
|
self.finish(.success(()))
|
|
|
|
|
} catch {
|
|
|
|
|
self.finish(.failure(MinimuxerError.RwAfc))
|
|
|
|
|
self.progress.completedUnitCount += 1
|
|
|
|
|
self.finish(.success(()))
|
2019-06-21 11:20:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|