2019-05-09 15:29:54 -07:00
|
|
|
//
|
|
|
|
|
// App.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
2019-05-20 21:24:53 +02:00
|
|
|
// Created by Riley Testut on 5/20/19.
|
2019-05-09 15:29:54 -07:00
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2019-05-20 21:24:53 +02:00
|
|
|
import CoreData
|
2019-05-09 15:29:54 -07:00
|
|
|
|
2019-05-30 17:10:50 -07:00
|
|
|
import Roxas
|
|
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
@objc(App)
|
|
|
|
|
class App: NSManagedObject, Decodable
|
2019-05-09 15:29:54 -07:00
|
|
|
{
|
2019-05-20 21:24:53 +02:00
|
|
|
/* Properties */
|
|
|
|
|
@NSManaged private(set) var name: String
|
|
|
|
|
@NSManaged private(set) var identifier: String
|
2019-05-09 17:21:55 -07:00
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
@NSManaged private(set) var developerName: String
|
|
|
|
|
@NSManaged private(set) var localizedDescription: String
|
2019-05-09 15:29:54 -07:00
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
@NSManaged private(set) var iconName: String
|
|
|
|
|
@NSManaged private(set) var screenshotNames: [String]
|
|
|
|
|
|
2019-05-20 22:24:16 +02:00
|
|
|
@NSManaged private(set) var version: String
|
|
|
|
|
@NSManaged private(set) var versionDate: Date
|
|
|
|
|
@NSManaged private(set) var versionDescription: String?
|
|
|
|
|
|
2019-05-20 21:26:01 +02:00
|
|
|
/* Relationships */
|
|
|
|
|
@NSManaged private(set) var installedApp: InstalledApp?
|
|
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
private override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?)
|
|
|
|
|
{
|
|
|
|
|
super.init(entity: entity, insertInto: context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum CodingKeys: String, CodingKey
|
|
|
|
|
{
|
|
|
|
|
case name
|
|
|
|
|
case identifier
|
|
|
|
|
case developerName
|
|
|
|
|
case localizedDescription
|
2019-05-20 22:24:16 +02:00
|
|
|
case version
|
|
|
|
|
case versionDescription
|
|
|
|
|
case versionDate
|
2019-05-20 21:24:53 +02:00
|
|
|
case iconName
|
|
|
|
|
case screenshotNames
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init(from decoder: Decoder) throws
|
|
|
|
|
{
|
|
|
|
|
guard let context = decoder.managedObjectContext else { preconditionFailure("Decoder must have non-nil NSManagedObjectContext.") }
|
|
|
|
|
|
|
|
|
|
super.init(entity: App.entity(), insertInto: nil)
|
|
|
|
|
|
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
self.name = try container.decode(String.self, forKey: .name)
|
|
|
|
|
self.identifier = try container.decode(String.self, forKey: .identifier)
|
|
|
|
|
self.developerName = try container.decode(String.self, forKey: .developerName)
|
|
|
|
|
self.localizedDescription = try container.decode(String.self, forKey: .localizedDescription)
|
|
|
|
|
|
2019-05-20 22:24:16 +02:00
|
|
|
self.version = try container.decode(String.self, forKey: .version)
|
|
|
|
|
self.versionDate = try container.decode(Date.self, forKey: .versionDate)
|
|
|
|
|
self.versionDescription = try container.decodeIfPresent(String.self, forKey: .versionDescription)
|
|
|
|
|
|
2019-05-20 21:24:53 +02:00
|
|
|
self.iconName = try container.decode(String.self, forKey: .iconName)
|
|
|
|
|
self.screenshotNames = try container.decodeIfPresent([String].self, forKey: .screenshotNames) ?? []
|
|
|
|
|
|
|
|
|
|
context.insert(self)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension App
|
|
|
|
|
{
|
|
|
|
|
@nonobjc class func fetchRequest() -> NSFetchRequest<App>
|
|
|
|
|
{
|
|
|
|
|
return NSFetchRequest<App>(entityName: "App")
|
|
|
|
|
}
|
2019-05-09 15:29:54 -07:00
|
|
|
}
|
2019-05-30 17:10:50 -07:00
|
|
|
|
|
|
|
|
extension App
|
|
|
|
|
{
|
|
|
|
|
class var appsDirectoryURL: URL {
|
|
|
|
|
let appsDirectoryURL = FileManager.default.applicationSupportDirectory.appendingPathComponent("Apps")
|
|
|
|
|
|
|
|
|
|
do { try FileManager.default.createDirectory(at: appsDirectoryURL, withIntermediateDirectories: true, attributes: nil) }
|
|
|
|
|
catch { print(error) }
|
|
|
|
|
|
|
|
|
|
return appsDirectoryURL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var directoryURL: URL {
|
|
|
|
|
let directoryURL = App.appsDirectoryURL.appendingPathComponent(self.identifier)
|
|
|
|
|
|
|
|
|
|
do { try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil) }
|
|
|
|
|
catch { print(error) }
|
|
|
|
|
|
|
|
|
|
return directoryURL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ipaURL: URL {
|
|
|
|
|
let ipaURL = self.directoryURL.appendingPathComponent("App.ipa")
|
|
|
|
|
return ipaURL
|
|
|
|
|
}
|
|
|
|
|
}
|