Throws error when adding marketplace source to non-marketplace AltStore (and vice versa)

This commit is contained in:
Riley Testut
2024-02-15 15:34:28 -06:00
committed by Magesh K
parent 6ee90f6c2a
commit 2899e3ea5f
4 changed files with 36 additions and 0 deletions

View File

@@ -24,6 +24,9 @@ extension SourceError
case missingPermissionUsageDescription
case missingScreenshotSize
case marketplaceAppsNotSupported = 101
case marketplaceAppsRequired
}
static func unsupported(_ source: Source) -> SourceError { SourceError(code: .unsupported, source: source) }
@@ -41,6 +44,14 @@ extension SourceError
static func missingScreenshotSize(for screenshot: AppScreenshot, source: Source) -> SourceError {
SourceError(code: .missingScreenshotSize, source: source, app: screenshot.app, screenshotURL: screenshot.imageURL)
}
static func marketplaceAppsNotSupported(source: Source) -> SourceError {
return SourceError(code: .marketplaceAppsNotSupported, source: source)
}
static func marketplaceAppsRequired(source: Source) -> SourceError {
return SourceError(code: .marketplaceAppsRequired, source: source)
}
}
struct SourceError: ALTLocalizedError
@@ -128,6 +139,14 @@ struct SourceError: ALTLocalizedError
let failureReason = baseMessage + ": \(screenshotURL.absoluteString)"
return failureReason
case .marketplaceAppsNotSupported:
let failureReason = String(format: NSLocalizedString("The source “%@” contains notarized apps, which are not supported by this version of AltStore.", comment: ""), self.$source.name)
return failureReason
case .marketplaceAppsRequired:
let failureReason = String(format: NSLocalizedString("The source “%@” contains non-marketplace apps, which are not supported by this version of AltStore.", comment: ""), self.$source.name)
return failureReason
}
}
@@ -166,6 +185,10 @@ struct SourceError: ALTLocalizedError
let recoverySuggestion = NSLocalizedString("Please remove the existing source in order to add this one.", comment: "")
return recoverySuggestion
case .marketplaceAppsRequired:
let failureReason = String(format: NSLocalizedString("AltStore can only install marketplace apps that have been notarized by Apple.", comment: ""), self.$source.name)
return failureReason
default: return nil
}
}

View File

@@ -226,6 +226,12 @@ private extension FetchSourceOperation
// All iPad screenshots MUST have an explicit size.
guard screenshot.size != nil else { throw SourceError.missingScreenshotSize(for: screenshot, source: source) }
}
#if MARKETPLACE
guard app.marketplaceID != nil else { throw SourceError.marketplaceAppsRequired(source: source) }
#else
guard app.marketplaceID == nil else { throw SourceError.marketplaceAppsNotSupported(source: source) }
#endif
}
if let previousSourceID = self.$source.identifier

View File

@@ -250,6 +250,7 @@
<attribute name="isPledged" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isPledgeRequired" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="localizedDescription" attributeType="String"/>
<attribute name="marketplaceID" optional="YES" attributeType="String"/>
<attribute name="name" attributeType="String"/>
<attribute name="pledgeAmount" optional="YES" attributeType="Decimal"/>
<attribute name="pledgeCurrency" optional="YES" attributeType="String"/>

View File

@@ -152,6 +152,9 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
@NSManaged public private(set) var tintColor: UIColor?
@NSManaged public private(set) var isBeta: Bool
// Required for Marketplace apps.
@NSManaged public private(set) var marketplaceID: String?
@NSManaged public var isPledged: Bool
@NSManaged public private(set) var isPledgeRequired: Bool
@NSManaged public private(set) var isHiddenWithoutPledge: Bool
@@ -275,6 +278,7 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
{
case name
case bundleIdentifier
case marketplaceID
case developerName
case localizedDescription
case iconURL
@@ -345,6 +349,8 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
} else {
throw DecodingError.dataCorruptedError(forKey: .downloadURL, in: container, debugDescription: "E downloadURL:String or downloadURLs:[[Platform:URL]] key required.")
}
// Required for Marketplace apps, but we'll verify later.
self.marketplaceID = try container.decodeIfPresent(String.self, forKey: .marketplaceID)
// else {
// throw DecodingError.dataCorruptedError(forKey: .downloadURL, in: container, debugDescription: "E downloadURL:String or downloadURLs:[[Platform:URL]] key required.")