From d2ed5bff57fcd9c7c6f55277ee58219a2812afb6 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 15 Feb 2024 18:39:27 -0600 Subject: [PATCH] Throws error if marketplace app is missing buildVersion --- AltStoreCore/Model/AppVersion.swift | 2 +- AltStoreCore/Model/StoreApp.swift | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/AltStoreCore/Model/AppVersion.swift b/AltStoreCore/Model/AppVersion.swift index ddd4eece..36c6c850 100644 --- a/AltStoreCore/Model/AppVersion.swift +++ b/AltStoreCore/Model/AppVersion.swift @@ -56,7 +56,7 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable super.init(entity: entity, insertInto: context) } - private enum CodingKeys: String, CodingKey + internal enum CodingKeys: String, CodingKey { case version case buildVersion diff --git a/AltStoreCore/Model/StoreApp.swift b/AltStoreCore/Model/StoreApp.swift index 005b271b..9f9cbdd2 100644 --- a/AltStoreCore/Model/StoreApp.swift +++ b/AltStoreCore/Model/StoreApp.swift @@ -424,6 +424,33 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable for version in versions { version.appBundleID = self.bundleIdentifier + + if self.marketplaceID != nil + { + struct IndexCodingKey: CodingKey + { + var stringValue: String { self.intValue?.description ?? "" } + var intValue: Int? + + init?(stringValue: String) + { + fatalError() + } + + init(intValue: Int) + { + self.intValue = intValue + } + } + + // Marketplace apps must provide build version. + guard version.buildVersion != nil else { + let codingPath = container.codingPath + [CodingKeys.versions as CodingKey] + [IndexCodingKey(intValue: index) as CodingKey] + let context = DecodingError.Context(codingPath: codingPath, debugDescription: "Notarized apps must provide a build version.") + throw DecodingError.keyNotFound(AppVersion.CodingKeys.buildVersion, context) + } + } + } try self.setVersions(versions)