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 Foundation
|
|
|
|
|
import CoreData
|
|
|
|
|
import Network
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
import AltStoreCore
|
2020-03-06 17:08:35 -08:00
|
|
|
import AltSign
|
|
|
|
|
|
|
|
|
|
class OperationContext
|
|
|
|
|
{
|
|
|
|
|
var server: Server?
|
|
|
|
|
var error: Error?
|
2020-03-30 15:23:20 -07:00
|
|
|
|
2020-05-02 22:06:57 -07:00
|
|
|
var presentingViewController: UIViewController?
|
|
|
|
|
|
2020-03-30 15:23:20 -07:00
|
|
|
let operations: NSHashTable<Foundation.Operation>
|
|
|
|
|
|
|
|
|
|
init(server: Server? = nil, error: Error? = nil, operations: [Foundation.Operation] = [])
|
|
|
|
|
{
|
|
|
|
|
self.server = server
|
|
|
|
|
self.error = error
|
|
|
|
|
|
|
|
|
|
self.operations = NSHashTable<Foundation.Operation>.weakObjects()
|
|
|
|
|
for operation in operations
|
|
|
|
|
{
|
|
|
|
|
self.operations.add(operation)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
convenience init(context: OperationContext)
|
|
|
|
|
{
|
|
|
|
|
self.init(server: context.server, error: context.error, operations: context.operations.allObjects)
|
|
|
|
|
}
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AuthenticatedOperationContext: OperationContext
|
|
|
|
|
{
|
|
|
|
|
var session: ALTAppleAPISession?
|
|
|
|
|
|
|
|
|
|
var team: ALTTeam?
|
|
|
|
|
var certificate: ALTCertificate?
|
|
|
|
|
|
|
|
|
|
weak var authenticationOperation: AuthenticationOperation?
|
2020-03-30 15:23:20 -07:00
|
|
|
|
|
|
|
|
convenience init(context: AuthenticatedOperationContext)
|
|
|
|
|
{
|
|
|
|
|
self.init(server: context.server, error: context.error, operations: context.operations.allObjects)
|
|
|
|
|
|
|
|
|
|
self.session = context.session
|
|
|
|
|
self.team = context.team
|
|
|
|
|
self.certificate = context.certificate
|
|
|
|
|
self.authenticationOperation = context.authenticationOperation
|
|
|
|
|
}
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@dynamicMemberLookup
|
|
|
|
|
class AppOperationContext
|
|
|
|
|
{
|
|
|
|
|
let bundleIdentifier: String
|
2020-05-16 16:17:18 -07:00
|
|
|
let authenticatedContext: AuthenticatedOperationContext
|
2020-03-06 17:08:35 -08:00
|
|
|
|
|
|
|
|
var app: ALTApplication?
|
|
|
|
|
var provisioningProfiles: [String: ALTProvisioningProfile]?
|
|
|
|
|
|
|
|
|
|
var isFinished = false
|
|
|
|
|
|
|
|
|
|
var error: Error? {
|
|
|
|
|
get {
|
|
|
|
|
return _error ?? self.authenticatedContext.error
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
_error = newValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private var _error: Error?
|
|
|
|
|
|
|
|
|
|
init(bundleIdentifier: String, authenticatedContext: AuthenticatedOperationContext)
|
|
|
|
|
{
|
|
|
|
|
self.bundleIdentifier = bundleIdentifier
|
|
|
|
|
self.authenticatedContext = authenticatedContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
subscript<T>(dynamicMember keyPath: WritableKeyPath<AuthenticatedOperationContext, T>) -> T
|
|
|
|
|
{
|
|
|
|
|
return self.authenticatedContext[keyPath: keyPath]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class InstallAppOperationContext: AppOperationContext
|
|
|
|
|
{
|
|
|
|
|
lazy var temporaryDirectory: URL = {
|
|
|
|
|
let temporaryDirectory = FileManager.default.uniqueTemporaryURL()
|
|
|
|
|
|
|
|
|
|
do { try FileManager.default.createDirectory(at: temporaryDirectory, withIntermediateDirectories: true, attributes: nil) }
|
|
|
|
|
catch { self.error = error }
|
|
|
|
|
|
|
|
|
|
return temporaryDirectory
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
var resignedApp: ALTApplication?
|
|
|
|
|
var installationConnection: ServerConnection?
|
2020-05-15 15:11:17 -07:00
|
|
|
var installedApp: InstalledApp? {
|
|
|
|
|
didSet {
|
|
|
|
|
self.installedAppContext = self.installedApp?.managedObjectContext
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private var installedAppContext: NSManagedObjectContext?
|
2020-03-06 17:08:35 -08:00
|
|
|
|
|
|
|
|
var beginInstallationHandler: ((InstalledApp) -> Void)?
|
2020-10-01 14:09:45 -07:00
|
|
|
|
|
|
|
|
var alternateIconURL: URL?
|
2020-03-06 17:08:35 -08:00
|
|
|
}
|