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