mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-08 22:33:26 +01:00
clean-checkpoint-1
This commit is contained in:
@@ -25,6 +25,7 @@ public extension ALTServerError
|
||||
// because it'll still be accessible via error.underlyingError.underlyingError.
|
||||
var userInfo = error.userInfo
|
||||
userInfo[NSUnderlyingErrorKey] = error
|
||||
|
||||
self = ALTServerError(.underlyingError, userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public extension Bundle
|
||||
public static let certificateID = "ALTCertificateID"
|
||||
public static let appGroups = "ALTAppGroups"
|
||||
public static let altBundleID = "ALTBundleIdentifier"
|
||||
|
||||
public static let orgbundleIdentifier = "com.SideStore"
|
||||
public static let appbundleIdentifier = orgbundleIdentifier + ".SideStore"
|
||||
public static let devicePairingString = "ALTPairingFile"
|
||||
|
||||
@@ -34,7 +34,8 @@ public extension NSError
|
||||
|
||||
@objc(alt_localizedTitle)
|
||||
var localizedTitle: String? {
|
||||
return self.userInfo[ALTLocalizedTitleErrorKey] as? String
|
||||
let localizedTitle = self.userInfo[ALTLocalizedTitleErrorKey] as? String
|
||||
return localizedTitle
|
||||
}
|
||||
|
||||
@objc(alt_errorWithLocalizedFailure:)
|
||||
@@ -48,14 +49,17 @@ public extension NSError
|
||||
|
||||
default:
|
||||
var userInfo = self.userInfo
|
||||
userInfo[NSLocalizedFailureReasonErrorKey] = failure
|
||||
userInfo[NSLocalizedFailureErrorKey] = failure
|
||||
|
||||
return ALTWrappedError(error: self, userInfo: userInfo)
|
||||
let error = ALTWrappedError(error: self, userInfo: userInfo)
|
||||
return error
|
||||
}
|
||||
}
|
||||
|
||||
@objc(alt_errorWithLocalizedTitle:)
|
||||
func withLocalizedTitle(_ title: String) -> NSError {
|
||||
switch self
|
||||
func withLocalizedTitle(_ title: String) -> NSError
|
||||
{
|
||||
switch self
|
||||
{
|
||||
case var error as any ALTLocalizedError:
|
||||
error.errorTitle = title
|
||||
@@ -64,8 +68,9 @@ public extension NSError
|
||||
default:
|
||||
var userInfo = self.userInfo
|
||||
userInfo[ALTLocalizedTitleErrorKey] = title
|
||||
return ALTWrappedError(error: self, userInfo: userInfo)
|
||||
|
||||
let error = ALTWrappedError(error: self, userInfo: userInfo)
|
||||
return error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +82,7 @@ public extension NSError
|
||||
userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason
|
||||
userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion
|
||||
userInfo[NSDebugDescriptionErrorKey] = self.localizedDebugDescription
|
||||
|
||||
// Remove userInfo values that don't conform to NSSecureEncoding.
|
||||
userInfo = userInfo.filter { (key, value) in
|
||||
guard let secureCodable = value as? NSSecureCoding else { return false }
|
||||
@@ -111,13 +117,16 @@ public extension NSError
|
||||
let error = NSError(domain: self.domain, code: self.code, userInfo: userInfo)
|
||||
return error
|
||||
}
|
||||
func formattedDetailedDescription(with font: ALTFont) -> NSAttributedString {
|
||||
#if canImport(UIKit)
|
||||
|
||||
func formattedDetailedDescription(with font: ALTFont) -> NSAttributedString
|
||||
{
|
||||
#if canImport(UIKit)
|
||||
let boldFontDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold) ?? font.fontDescriptor
|
||||
#else
|
||||
let boldFont = ALTFont(descriptor: boldFontDescriptor, size: font.pointSize)
|
||||
#else
|
||||
let boldFontDescriptor = font.fontDescriptor.withSymbolicTraits(.bold)
|
||||
#endif
|
||||
let boldFont = ALTFont(descriptor: boldFontDescriptor, size: font.pointSize) ?? font
|
||||
#endif
|
||||
|
||||
var preferredKeyOrder = [
|
||||
NSDebugDescriptionErrorKey,
|
||||
@@ -126,12 +135,13 @@ public extension NSError
|
||||
NSLocalizedFailureReasonErrorKey,
|
||||
NSLocalizedRecoverySuggestionErrorKey,
|
||||
ALTLocalizedTitleErrorKey,
|
||||
// ALTSourceFileErrorKey,
|
||||
// ALTSourceLineErrorKey,
|
||||
ALTSourceFileErrorKey,
|
||||
ALTSourceLineErrorKey,
|
||||
NSUnderlyingErrorKey
|
||||
]
|
||||
|
||||
if #available(iOS 14.5, macOS 11.3, *) {
|
||||
if #available(iOS 14.5, macOS 11.3, *)
|
||||
{
|
||||
preferredKeyOrder.append(NSMultipleUnderlyingErrorsKey)
|
||||
}
|
||||
|
||||
@@ -142,14 +152,16 @@ public extension NSError
|
||||
userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason
|
||||
userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion
|
||||
|
||||
let sortedUserInfo = userInfo.sorted { a, b in
|
||||
let sortedUserInfo = userInfo.sorted { (a, b) in
|
||||
let indexA = preferredKeyOrder.firstIndex(of: a.key)
|
||||
let indexB = preferredKeyOrder.firstIndex(of: b.key)
|
||||
switch (indexA, indexB) {
|
||||
|
||||
switch (indexA, indexB)
|
||||
{
|
||||
case (let indexA?, let indexB?): return indexA < indexB
|
||||
case (_?, nil): return true // indexA exists, indexB is nil, indexA should come first
|
||||
case (nil, _?): return false // indexB exists, indexB is nil, indexB should come first
|
||||
case (nil, nil): return a.key < b.key // both nil, so sort alphabetically
|
||||
case (_?, nil): return true // indexA exists, indexB is nil, so A should come first.
|
||||
case (nil, _?): return false // indexA is nil, indexB exists, so B should come first.
|
||||
case (nil, nil): return a.key < b.key // both indexes are nil, so sort alphabetically.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +178,8 @@ public extension NSError
|
||||
case NSLocalizedFailureReasonErrorKey: keyName = NSLocalizedString("Failure Reason", comment: "")
|
||||
case NSLocalizedRecoverySuggestionErrorKey: keyName = NSLocalizedString("Recovery Suggestion", comment: "")
|
||||
case ALTLocalizedTitleErrorKey: keyName = NSLocalizedString("Title", comment: "")
|
||||
// case ALTSourceFileErrorKey: keyName = NSLocalizedString("Source File", comment: "")
|
||||
// case ALTSourceLineErrorKey: keyName = NSLocalizedString("Source Line", comment: "")
|
||||
case ALTSourceFileErrorKey: keyName = NSLocalizedString("Source File", comment: "")
|
||||
case ALTSourceLineErrorKey: keyName = NSLocalizedString("Source Line", comment: "")
|
||||
case NSUnderlyingErrorKey: keyName = NSLocalizedString("Underlying Error", comment: "")
|
||||
default:
|
||||
if #available(iOS 14.5, macOS 11.3, *), key == NSMultipleUnderlyingErrorsKey
|
||||
@@ -214,27 +226,32 @@ public extension NSError
|
||||
typealias UserInfoProvider = (Error, String) -> Any?
|
||||
|
||||
@objc
|
||||
class func alt_setUserInfoValueProvider(forDomain domain: String, provider: UserInfoProvider?) {
|
||||
NSError.setUserInfoValueProvider(forDomain: domain) { error, key in
|
||||
class func alt_setUserInfoValueProvider(forDomain domain: String, provider: UserInfoProvider?)
|
||||
{
|
||||
NSError.setUserInfoValueProvider(forDomain: domain) { (error, key) in
|
||||
let nsError = error as NSError
|
||||
|
||||
switch key{
|
||||
switch key
|
||||
{
|
||||
case NSLocalizedDescriptionKey:
|
||||
if nsError.localizedFailure != nil {
|
||||
// Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason
|
||||
if nsError.localizedFailure != nil
|
||||
{
|
||||
// Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason.
|
||||
return nil
|
||||
} else if let localizedDescription = provider?(error, NSLocalizedDescriptionKey) as? String {
|
||||
// Only call provider() if there is no localizedFailure
|
||||
}
|
||||
else if let localizedDescription = provider?(error, NSLocalizedDescriptionKey) as? String
|
||||
{
|
||||
// Only call provider() if there is no localizedFailure.
|
||||
return localizedDescription
|
||||
}
|
||||
|
||||
/* Otherwise return failureReason for localizedDescription to avoid system prepending "Operation Failed" message
|
||||
Do NOT return provider(NSLocalizedFailureReason) which might be unexpectedly nil if unrecognized error code. */
|
||||
|
||||
// Otherwise, return failureReason for localizedDescription to avoid system prepending "Operation Failed" message.
|
||||
// Do NOT return provider(NSLocalizedFailureReason), which might be unexpectedly nil if unrecognized error code.
|
||||
return nsError.localizedFailureReason
|
||||
|
||||
default:
|
||||
return provider?(error, key)
|
||||
let value = provider?(error, key)
|
||||
return value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,21 +260,27 @@ public extension NSError
|
||||
public extension Error
|
||||
{
|
||||
var underlyingError: Error? {
|
||||
return (self as NSError).userInfo[NSUnderlyingErrorKey] as? Error
|
||||
let underlyingError = (self as NSError).userInfo[NSUnderlyingErrorKey] as? Error
|
||||
return underlyingError
|
||||
}
|
||||
|
||||
var localizedErrorCode: String {
|
||||
return String(format: NSLocalizedString("%@ %@", comment: ""), (self as NSError).domain, self.displayCode as NSNumber)
|
||||
let nsError = self as NSError
|
||||
let localizedErrorCode = String(format: NSLocalizedString("%@ %@", comment: ""), nsError.domain, self.displayCode as NSNumber)
|
||||
return localizedErrorCode
|
||||
}
|
||||
|
||||
var displayCode: Int {
|
||||
guard let serverError = self as? ALTServerError else {
|
||||
// Not ALTServerError, so display regular code.
|
||||
return (self as NSError).code
|
||||
}
|
||||
|
||||
/* We want AltServerError codes to start at 2000, but we can't change them without breaking AltServer compatibility.
|
||||
Instead we just add 2000 when displaying code to the user to make it appear as if the codes start at 2000 anyway.
|
||||
*/
|
||||
return 2000 + serverError.code.rawValue
|
||||
// We want ALTServerError codes to start at 2000,
|
||||
// but we can't change them without breaking AltServer compatibility.
|
||||
// Instead, we just add 2000 when displaying code to user
|
||||
// to make it appear as if codes start at 2000 normally.
|
||||
let code = 2000 + serverError.code.rawValue
|
||||
return code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,21 @@
|
||||
// OperatingSystemVersion+Comparable.swift
|
||||
// AltStoreCore
|
||||
//
|
||||
// Created by nythepegasus on 5/9/24.
|
||||
// Created by Riley Testut on 11/15/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension OperatingSystemVersion: Comparable {
|
||||
public static func ==(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool {
|
||||
extension OperatingSystemVersion: Comparable
|
||||
{
|
||||
public static func ==(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool
|
||||
{
|
||||
return lhs.majorVersion == rhs.majorVersion && lhs.minorVersion == rhs.minorVersion && lhs.patchVersion == rhs.patchVersion
|
||||
}
|
||||
|
||||
public static func <(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool {
|
||||
public static func <(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool
|
||||
{
|
||||
return lhs.stringValue.compare(rhs.stringValue, options: .numeric) == .orderedAscending
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user