mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-10 15:23:27 +01:00
* [Shared] Revises ALTLocalizedError protocol * Refactors errors to conform to revised ALTLocalizedError protocol * [Missing Commit] Remaining changes for ALTLocalizedError * [AltServer] Refactors errors to conform to revised ALTLocalizedError protocol * [Missing Commit] Declares ALTLocalizedTitleErrorKey + ALTLocalizedDescriptionKey * Updates Objective-C errors to match revised ALTLocalizedError * [Missing Commit] Unnecessary ALTLocalizedDescription logic * [Shared] Refactors NSError.withLocalizedFailure to properly support ALTLocalizedError * [Shared] Supports adding localized titles to errors via NSError.withLocalizedTitle() * Revises ErrorResponse logic to support arbitrary errors and user info values * [Missed Commit] Renames CodableServerError to CodableError * Merges ConnectionError into OperationError * [Missed Commit] Doesn’t check ALTWrappedError’s userInfo for localizedDescription * [Missed] Fixes incorrect errorDomain for ALTErrorEnums * [Missed] Removes nonexistent ALTWrappedError.h * Includes source file and line number in OperationError.unknown failureReason * Adds localizedTitle to AppManager operation errors * Fixes adding localizedTitle + localizedFailure to ALTWrappedError * Updates ToastView to use error’s localizedTitle as title * [Shared] Adds NSError.formattedDetailedDescription(with:) Returns formatted NSAttributedString containing all user info values intended for displaying to the user. * [Shared] Updates Error.localizedErrorCode to say “code” instead of “error” * Conforms ALTLocalizedError to CustomStringConvertible * Adds “View More Details” option to Error Log context menu to view detailed error description * [Shared] Fixes NSError.formattedDetailedDescription appearing black in dark mode * [AltServer] Updates error alert to match revised error logic Uses error’s localizedTitle as alert title. * [AltServer] Adds “View More Details” button to error alert to view detailed error info * [AltServer] Renames InstallError to OperationError and conforms to ALTErrorEnum * [Shared] Removes CodableError support for Date user info values Not currently used, and we don’t want to accidentally parse a non-Date as a Date in the meantime. * [Shared] Includes dynamic UserInfoValueProvider values in NSError.formattedDetailedDescription() * [Shared] Includes source file + line in NSError.formattedDetailedDescription() Automatically captures source file + line when throwing ALTErrorEnums. * [Shared] Captures source file + line for unknown errors * Removes sourceFunction from OperationError * Adds localizedTitle to AuthenticationViewController errors * [Shared] Moves nested ALTWrappedError logic to ALTWrappedError initializer * [AltServer] Removes now-redundant localized failure from JIT errors All JIT errors now have a localizedTitle which effectively says the same thing. * Makes OperationError.Code start at 1000 “Connection errors” subsection starts at 1200. * [Shared] Updates Error domains to revised [Source].[ErrorType] format * Updates ALTWrappedError.localizedDescription to prioritize using wrapped NSLocalizedDescription as failure reason * Makes ALTAppleAPIError codes start at 3000 * [AltServer] Adds relevant localizedFailures to ALTDeviceManager.installApplication() errors * Revises OperationError failureReasons and recovery suggestions All failure reasons now read correctly when preceded by a failure reason and “because”. * Revises ALTServerError error messages All failure reasons now read correctly when preceded by a failure reason and “because”. * Most failure reasons now read correctly when preceded by a failure reason and “because”. * ALTServerErrorUnderlyingError forwards all user info provider calls to underlying error. * Revises error messages for ALTAppleAPIErrorIncorrectCredentials * [Missed] Removes NSError+AltStore.swift from AltStore target * [Shared] Updates AltServerErrorDomain to revised [Source].[ErrorType] format * [Shared] Removes “code” from Error.localizedErrorCode * [Shared] Makes ALTServerError codes (appear to) start at 2000 We can’t change the actual error codes without breaking backwards compatibility, so instead we just add 2000 whenever we display ALTServerError codes to the user. * Moves VerificationError.errorFailure to VerifyAppOperation * Supports custom failure reason for OperationError.unknown * [Shared] Changes AltServerErrorDomain to “AltServer.ServerError” * [Shared] Converts ALTWrappedError to Objective-C class NSError subclasses must be written in ObjC for Swift.Error <-> NSError bridging to work correctly. # Conflicts: # AltStore.xcodeproj/project.pbxproj * Fixes decoding CodableError nested user info values
177 lines
7.9 KiB
Swift
177 lines
7.9 KiB
Swift
//
|
|
// OperationError.swift
|
|
// AltStore
|
|
//
|
|
// Created by Riley Testut on 6/7/19.
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import AltSign
|
|
import AltStoreCore
|
|
|
|
extension OperationError
|
|
{
|
|
enum Code: Int, ALTErrorCode, CaseIterable
|
|
{
|
|
typealias Error = OperationError
|
|
|
|
/* General */
|
|
case unknown = 1000
|
|
case unknownResult
|
|
case cancelled
|
|
case timedOut
|
|
case notAuthenticated
|
|
case appNotFound
|
|
case unknownUDID
|
|
case invalidApp
|
|
case invalidParameters
|
|
case maximumAppIDLimitReached
|
|
case noSources
|
|
case openAppFailed
|
|
case missingAppGroup
|
|
|
|
/* Connection */
|
|
case serverNotFound = 1200
|
|
case connectionFailed
|
|
case connectionDropped
|
|
}
|
|
|
|
static let unknownResult: OperationError = .init(code: .unknownResult)
|
|
static let cancelled: OperationError = .init(code: .cancelled)
|
|
static let timedOut: OperationError = .init(code: .timedOut)
|
|
static let notAuthenticated: OperationError = .init(code: .notAuthenticated)
|
|
static let unknownUDID: OperationError = .init(code: .unknownUDID)
|
|
static let invalidApp: OperationError = .init(code: .invalidApp)
|
|
static let invalidParameters: OperationError = .init(code: .invalidParameters)
|
|
static let noSources: OperationError = .init(code: .noSources)
|
|
static let missingAppGroup: OperationError = .init(code: .missingAppGroup)
|
|
|
|
static let serverNotFound: OperationError = .init(code: .serverNotFound)
|
|
static let connectionFailed: OperationError = .init(code: .connectionFailed)
|
|
static let connectionDropped: OperationError = .init(code: .connectionDropped)
|
|
|
|
static func unknown(failureReason: String? = nil, file: String = #fileID, line: UInt = #line) -> OperationError {
|
|
OperationError(code: .unknown, failureReason: failureReason, sourceFile: file, sourceLine: line)
|
|
}
|
|
|
|
static func appNotFound(name: String?) -> OperationError { OperationError(code: .appNotFound, appName: name) }
|
|
static func openAppFailed(name: String) -> OperationError { OperationError(code: .openAppFailed, appName: name) }
|
|
|
|
static func maximumAppIDLimitReached(appName: String, requiredAppIDs: Int, availableAppIDs: Int, expirationDate: Date) -> OperationError {
|
|
OperationError(code: .maximumAppIDLimitReached, appName: appName, requiredAppIDs: requiredAppIDs, availableAppIDs: availableAppIDs, expirationDate: expirationDate)
|
|
}
|
|
}
|
|
|
|
struct OperationError: ALTLocalizedError
|
|
{
|
|
let code: Code
|
|
|
|
var errorTitle: String?
|
|
var errorFailure: String?
|
|
|
|
var appName: String?
|
|
var requiredAppIDs: Int?
|
|
var availableAppIDs: Int?
|
|
var expirationDate: Date?
|
|
|
|
var sourceFile: String?
|
|
var sourceLine: UInt?
|
|
|
|
private init(code: Code, failureReason: String? = nil, appName: String? = nil, requiredAppIDs: Int? = nil, availableAppIDs: Int? = nil, expirationDate: Date? = nil,
|
|
sourceFile: String? = nil, sourceLine: UInt? = nil)
|
|
{
|
|
self.code = code
|
|
self._failureReason = failureReason
|
|
|
|
self.appName = appName
|
|
self.requiredAppIDs = requiredAppIDs
|
|
self.availableAppIDs = availableAppIDs
|
|
self.expirationDate = expirationDate
|
|
self.sourceFile = sourceFile
|
|
self.sourceLine = sourceLine
|
|
}
|
|
|
|
var errorFailureReason: String {
|
|
switch self.code
|
|
{
|
|
case .unknown:
|
|
var failureReason = self._failureReason ?? NSLocalizedString("An unknown error occured.", comment: "")
|
|
guard let sourceFile, let sourceLine else { return failureReason }
|
|
|
|
failureReason += " (\(sourceFile) line \(sourceLine))"
|
|
return failureReason
|
|
|
|
case .unknownResult: return NSLocalizedString("The operation returned an unknown result.", comment: "")
|
|
case .cancelled: return NSLocalizedString("The operation was cancelled.", comment: "")
|
|
case .timedOut: return NSLocalizedString("The operation timed out.", comment: "")
|
|
case .notAuthenticated: return NSLocalizedString("You are not signed in.", comment: "")
|
|
case .unknownUDID: return NSLocalizedString("AltStore could not determine this device's UDID.", comment: "")
|
|
case .invalidApp: return NSLocalizedString("The app is in an invalid format.", comment: "")
|
|
case .invalidParameters: return NSLocalizedString("Invalid parameters.", comment: "")
|
|
case .maximumAppIDLimitReached: return NSLocalizedString("You cannot register more than 10 App IDs within a 7 day period.", comment: "")
|
|
case .noSources: return NSLocalizedString("There are no AltStore sources.", comment: "")
|
|
case .missingAppGroup: return NSLocalizedString("AltStore's shared app group could not be accessed.", comment: "")
|
|
|
|
case .appNotFound:
|
|
let appName = self.appName ?? NSLocalizedString("The app", comment: "")
|
|
return String(format: NSLocalizedString("%@ could not be found.", comment: ""), appName)
|
|
|
|
case .openAppFailed:
|
|
let appName = self.appName ?? NSLocalizedString("the app", comment: "")
|
|
return String(format: NSLocalizedString("AltStore was denied permission to launch %@.", comment: ""), appName)
|
|
|
|
case .serverNotFound: return NSLocalizedString("AltServer could not be found.", comment: "")
|
|
case .connectionFailed: return NSLocalizedString("A connection to AltServer could not be established.", comment: "")
|
|
case .connectionDropped: return NSLocalizedString("The connection to AltServer was dropped.", comment: "")
|
|
}
|
|
}
|
|
private var _failureReason: String?
|
|
|
|
var recoverySuggestion: String? {
|
|
switch self.code
|
|
{
|
|
case .serverNotFound: return NSLocalizedString("Make sure you're on the same WiFi network as a computer running AltServer, or try connecting this device to your computer via USB.", comment: "")
|
|
case .maximumAppIDLimitReached:
|
|
let baseMessage = NSLocalizedString("Delete sideloaded apps to free up App ID slots.", comment: "")
|
|
guard let appName = self.appName, let requiredAppIDs = self.requiredAppIDs, let availableAppIDs = self.availableAppIDs, let date = self.expirationDate else { return baseMessage }
|
|
|
|
var message: String = ""
|
|
|
|
if requiredAppIDs > 1
|
|
{
|
|
let availableText: String
|
|
|
|
switch availableAppIDs
|
|
{
|
|
case 0: availableText = NSLocalizedString("none are available", comment: "")
|
|
case 1: availableText = NSLocalizedString("only 1 is available", comment: "")
|
|
default: availableText = String(format: NSLocalizedString("only %@ are available", comment: ""), NSNumber(value: availableAppIDs))
|
|
}
|
|
|
|
let prefixMessage = String(format: NSLocalizedString("%@ requires %@ App IDs, but %@.", comment: ""), appName, NSNumber(value: requiredAppIDs), availableText)
|
|
message = prefixMessage + " " + baseMessage + "\n\n"
|
|
}
|
|
else
|
|
{
|
|
message = baseMessage + " "
|
|
}
|
|
|
|
let dateComponents = Calendar.current.dateComponents([.day, .hour, .minute], from: Date(), to: date)
|
|
|
|
let dateComponentsFormatter = DateComponentsFormatter()
|
|
dateComponentsFormatter.maximumUnitCount = 1
|
|
dateComponentsFormatter.unitsStyle = .full
|
|
|
|
let remainingTime = dateComponentsFormatter.string(from: dateComponents)!
|
|
|
|
let remainingTimeMessage = String(format: NSLocalizedString("You can register another App ID in %@.", comment: ""), remainingTime)
|
|
message += remainingTimeMessage
|
|
|
|
return message
|
|
|
|
default: return nil
|
|
}
|
|
}
|
|
}
|