mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-14 17:23:25 +01:00
Create swift package
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// InstalledAppPolicy.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 1/24/20.
|
||||
// Copyright © 2020 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import AltSign
|
||||
import CoreData
|
||||
|
||||
@objc(InstalledAppToInstalledAppMigrationPolicy)
|
||||
class InstalledAppToInstalledAppMigrationPolicy: NSEntityMigrationPolicy {
|
||||
override func createRelationships(forDestination dInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
||||
try super.createRelationships(forDestination: dInstance, in: mapping, manager: manager)
|
||||
|
||||
// Entity must be in manager.destinationContext.
|
||||
let entity = NSEntityDescription.entity(forEntityName: "Team", in: manager.destinationContext)
|
||||
|
||||
let fetchRequest = NSFetchRequest<NSManagedObject>()
|
||||
fetchRequest.entity = entity
|
||||
fetchRequest.predicate = NSPredicate(format: "%K == YES", #keyPath(Team.isActiveTeam))
|
||||
|
||||
let teams = try manager.destinationContext.fetch(fetchRequest)
|
||||
|
||||
// Cannot use NSManagedObject subclasses during migration, so fallback to using KVC instead.
|
||||
dInstance.setValue(teams.first, forKey: #keyPath(InstalledApp.team))
|
||||
}
|
||||
|
||||
@objc(defaultIsActiveForBundleID:team:)
|
||||
func defaultIsActive(for bundleID: String, team: NSManagedObject?) -> NSNumber {
|
||||
let isActive: Bool
|
||||
|
||||
let activeAppsMinimumVersion = OperatingSystemVersion(majorVersion: 13, minorVersion: 3, patchVersion: 1)
|
||||
if !ProcessInfo.processInfo.isOperatingSystemAtLeast(activeAppsMinimumVersion) {
|
||||
isActive = true
|
||||
} else if let team = team, let type = team.value(forKey: #keyPath(Team.type)) as? Int16, type != ALTTeamType.free.rawValue {
|
||||
isActive = true
|
||||
} else {
|
||||
// AltStore should always be active, but deactivate all other apps.
|
||||
isActive = (bundleID == StoreApp.altstoreAppID)
|
||||
|
||||
// We can assume there is an active app limit,
|
||||
// but will confirm next time user authenticates.
|
||||
UserDefaults.standard.activeAppsLimit = ALTActiveAppsLimit
|
||||
}
|
||||
|
||||
return NSNumber(value: isActive)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// StoreApp10ToStoreApp11Policy.swift
|
||||
// AltStoreCore
|
||||
//
|
||||
// Created by Riley Testut on 9/13/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
|
||||
// Can't use NSManagedObject subclasses, so add convenience accessors for KVC.
|
||||
private extension NSManagedObject {
|
||||
var storeAppBundleID: String? {
|
||||
let bundleID = value(forKey: #keyPath(StoreApp.bundleIdentifier)) as? String
|
||||
return bundleID
|
||||
}
|
||||
|
||||
var storeAppSourceID: String? {
|
||||
let sourceID = value(forKey: #keyPath(StoreApp.sourceIdentifier)) as? String
|
||||
return sourceID
|
||||
}
|
||||
|
||||
var storeAppVersion: String? {
|
||||
let version = value(forKey: #keyPath(StoreApp._version)) as? String
|
||||
return version
|
||||
}
|
||||
|
||||
var storeAppVersionDate: Date? {
|
||||
let versionDate = value(forKey: #keyPath(StoreApp._versionDate)) as? Date
|
||||
return versionDate
|
||||
}
|
||||
|
||||
var storeAppVersionDescription: String? {
|
||||
let versionDescription = value(forKey: #keyPath(StoreApp._versionDescription)) as? String
|
||||
return versionDescription
|
||||
}
|
||||
|
||||
var storeAppSize: NSNumber? {
|
||||
let size = value(forKey: #keyPath(StoreApp._size)) as? NSNumber
|
||||
return size
|
||||
}
|
||||
|
||||
var storeAppDownloadURL: URL? {
|
||||
let downloadURL = value(forKey: #keyPath(StoreApp._downloadURL)) as? URL
|
||||
return downloadURL
|
||||
}
|
||||
|
||||
func setStoreAppLatestVersion(_ appVersion: NSManagedObject) {
|
||||
setValue(appVersion, forKey: #keyPath(StoreApp.latestVersion))
|
||||
|
||||
let versions = NSOrderedSet(array: [appVersion])
|
||||
setValue(versions, forKey: #keyPath(StoreApp._versions))
|
||||
}
|
||||
|
||||
class func makeAppVersion(version: String,
|
||||
date: Date,
|
||||
localizedDescription: String?,
|
||||
downloadURL: URL,
|
||||
size: Int64,
|
||||
appBundleID: String,
|
||||
sourceID: String,
|
||||
in context: NSManagedObjectContext) -> NSManagedObject {
|
||||
let appVersion = NSEntityDescription.insertNewObject(forEntityName: AppVersion.entity().name!, into: context)
|
||||
appVersion.setValue(version, forKey: #keyPath(AppVersion.version))
|
||||
appVersion.setValue(date, forKey: #keyPath(AppVersion.date))
|
||||
appVersion.setValue(localizedDescription, forKey: #keyPath(AppVersion.localizedDescription))
|
||||
appVersion.setValue(downloadURL, forKey: #keyPath(AppVersion.downloadURL))
|
||||
appVersion.setValue(size, forKey: #keyPath(AppVersion.size))
|
||||
appVersion.setValue(appBundleID, forKey: #keyPath(AppVersion.appBundleID))
|
||||
appVersion.setValue(sourceID, forKey: #keyPath(AppVersion.sourceID))
|
||||
return appVersion
|
||||
}
|
||||
}
|
||||
|
||||
@objc(StoreApp10ToStoreApp11Policy)
|
||||
class StoreApp10ToStoreApp11Policy: NSEntityMigrationPolicy {
|
||||
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
|
||||
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
|
||||
|
||||
guard let appBundleID = sInstance.storeAppBundleID,
|
||||
let sourceID = sInstance.storeAppSourceID,
|
||||
let version = sInstance.storeAppVersion,
|
||||
let versionDate = sInstance.storeAppVersionDate,
|
||||
// let versionDescription = sInstance.storeAppVersionDescription, // Optional
|
||||
let downloadURL = sInstance.storeAppDownloadURL,
|
||||
let size = sInstance.storeAppSize as? Int64
|
||||
else { return }
|
||||
|
||||
guard
|
||||
let destinationStoreApp = manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]).first,
|
||||
let context = destinationStoreApp.managedObjectContext
|
||||
else { fatalError("A destination StoreApp and its managedObjectContext must exist.") }
|
||||
|
||||
let appVersion = NSManagedObject.makeAppVersion(
|
||||
version: version,
|
||||
date: versionDate,
|
||||
localizedDescription: sInstance.storeAppVersionDescription,
|
||||
downloadURL: downloadURL,
|
||||
size: Int64(size),
|
||||
appBundleID: appBundleID,
|
||||
sourceID: sourceID,
|
||||
in: context
|
||||
)
|
||||
|
||||
destinationStoreApp.setStoreAppLatestVersion(appVersion)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// StoreAppPolicy.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 9/14/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
|
||||
@objc(StoreAppToStoreAppMigrationPolicy)
|
||||
class StoreAppToStoreAppMigrationPolicy: NSEntityMigrationPolicy {
|
||||
@objc(migrateIconURL)
|
||||
func migrateIconURL() -> URL {
|
||||
URL(string: "https://via.placeholder.com/150")!
|
||||
}
|
||||
|
||||
@objc(migrateScreenshotURLs)
|
||||
func migrateScreenshotURLs() -> NSCopying {
|
||||
[] as NSArray
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user