2020-03-06 17:08:35 -08:00
|
|
|
//
|
|
|
|
|
// Contexts.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 6/20/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import CoreData
|
2023-03-01 00:48:36 -05:00
|
|
|
import Foundation
|
2020-03-06 17:08:35 -08:00
|
|
|
import Network
|
|
|
|
|
|
|
|
|
|
import AltSign
|
2023-03-01 00:48:36 -05:00
|
|
|
import SideStoreCore
|
2020-03-06 17:08:35 -08:00
|
|
|
|
2023-03-01 19:09:33 -05:00
|
|
|
public class OperationContext {
|
2020-03-06 17:08:35 -08:00
|
|
|
var error: Error?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-05-02 22:06:57 -07:00
|
|
|
var presentingViewController: UIViewController?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-30 15:23:20 -07:00
|
|
|
let operations: NSHashTable<Foundation.Operation>
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2023-03-01 19:09:33 -05:00
|
|
|
public init(error: Error? = nil, operations: [Foundation.Operation] = []) {
|
2020-03-30 15:23:20 -07:00
|
|
|
self.error = error
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-30 15:23:20 -07:00
|
|
|
self.operations = NSHashTable<Foundation.Operation>.weakObjects()
|
2023-03-01 00:48:36 -05:00
|
|
|
for operation in operations {
|
2020-03-30 15:23:20 -07:00
|
|
|
self.operations.add(operation)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2023-03-01 19:09:33 -05:00
|
|
|
public convenience init(context: OperationContext) {
|
2022-11-02 17:58:59 -07:00
|
|
|
self.init(error: context.error, operations: context.operations.allObjects)
|
2020-03-30 15:23:20 -07:00
|
|
|
}
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|
|
|
|
|
|
2023-03-01 19:09:33 -05:00
|
|
|
public final class AuthenticatedOperationContext: OperationContext {
|
2020-03-06 17:08:35 -08:00
|
|
|
var session: ALTAppleAPISession?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
var team: ALTTeam?
|
|
|
|
|
var certificate: ALTCertificate?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
weak var authenticationOperation: AuthenticationOperation?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2023-03-01 19:09:33 -05:00
|
|
|
public convenience init(context: AuthenticatedOperationContext) {
|
2022-11-02 17:58:59 -07:00
|
|
|
self.init(error: context.error, operations: context.operations.allObjects)
|
2023-03-01 00:48:36 -05:00
|
|
|
|
|
|
|
|
session = context.session
|
|
|
|
|
team = context.team
|
|
|
|
|
certificate = context.certificate
|
|
|
|
|
authenticationOperation = context.authenticationOperation
|
2020-03-30 15:23:20 -07:00
|
|
|
}
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@dynamicMemberLookup
|
2023-03-01 00:48:36 -05:00
|
|
|
class AppOperationContext {
|
2020-03-06 17:08:35 -08:00
|
|
|
let bundleIdentifier: String
|
2020-05-16 16:17:18 -07:00
|
|
|
let authenticatedContext: AuthenticatedOperationContext
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
var app: ALTApplication?
|
|
|
|
|
var provisioningProfiles: [String: ALTProvisioningProfile]?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
var isFinished = false
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
var error: Error? {
|
|
|
|
|
get {
|
2023-03-01 00:48:36 -05:00
|
|
|
_error ?? self.authenticatedContext.error
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
_error = newValue
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
private var _error: Error?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
|
|
|
|
init(bundleIdentifier: String, authenticatedContext: AuthenticatedOperationContext) {
|
2020-03-06 17:08:35 -08:00
|
|
|
self.bundleIdentifier = bundleIdentifier
|
|
|
|
|
self.authenticatedContext = authenticatedContext
|
|
|
|
|
}
|
2023-03-01 00:48:36 -05:00
|
|
|
|
|
|
|
|
subscript<T>(dynamicMember keyPath: WritableKeyPath<AuthenticatedOperationContext, T>) -> T {
|
|
|
|
|
self.authenticatedContext[keyPath: keyPath]
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 00:48:36 -05:00
|
|
|
class InstallAppOperationContext: AppOperationContext {
|
2020-03-06 17:08:35 -08:00
|
|
|
lazy var temporaryDirectory: URL = {
|
|
|
|
|
let temporaryDirectory = FileManager.default.uniqueTemporaryURL()
|
2023-03-01 00:48:36 -05:00
|
|
|
|
|
|
|
|
do { try FileManager.default.createDirectory(at: temporaryDirectory, withIntermediateDirectories: true, attributes: nil) } catch { self.error = error }
|
|
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
return temporaryDirectory
|
|
|
|
|
}()
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
var resignedApp: ALTApplication?
|
2020-05-15 15:11:17 -07:00
|
|
|
var installedApp: InstalledApp? {
|
|
|
|
|
didSet {
|
2023-03-01 00:48:36 -05:00
|
|
|
installedAppContext = installedApp?.managedObjectContext
|
2020-05-15 15:11:17 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-05-15 15:11:17 -07:00
|
|
|
private var installedAppContext: NSManagedObjectContext?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-03-06 17:08:35 -08:00
|
|
|
var beginInstallationHandler: ((InstalledApp) -> Void)?
|
2023-03-01 00:48:36 -05:00
|
|
|
|
2020-10-01 14:09:45 -07:00
|
|
|
var alternateIconURL: URL?
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|