2019-06-10 15:03:47 -07:00
//
// O p e r a t i o n E r r o r . s w i f t
// A l t S t o r e
//
// C r e a t e d b y R i l e y T e s t u t o n 6 / 7 / 1 9 .
// C o p y r i g h t © 2 0 1 9 R i l e y T e s t u t . A l l r i g h t s r e s e r v e d .
//
import Foundation
2019-07-25 14:04:26 -07:00
import AltSign
2019-06-10 15:03:47 -07:00
enum OperationError : LocalizedError
{
case unknown
case unknownResult
case cancelled
case notAuthenticated
case appNotFound
case unknownUDID
2019-06-21 11:20:03 -07:00
case invalidApp
case invalidParameters
2019-07-25 14:04:26 -07:00
case iOSVersionNotSupported ( ALTApplication )
2020-01-24 14:14:08 -08:00
case maximumAppIDLimitReached ( Date )
2019-07-25 14:04:26 -07:00
2019-07-30 17:00:04 -07:00
case noSources
2019-06-10 15:03:47 -07:00
var errorDescription : String ? {
switch self {
case . unknown : return NSLocalizedString ( " An unknown error occured. " , comment : " " )
case . unknownResult : return NSLocalizedString ( " The operation returned an unknown result. " , comment : " " )
case . cancelled : return NSLocalizedString ( " The operation was cancelled. " , comment : " " )
case . notAuthenticated : return NSLocalizedString ( " You are not signed in. " , comment : " " )
case . appNotFound : return NSLocalizedString ( " App not found. " , comment : " " )
case . unknownUDID : return NSLocalizedString ( " Unknown device UDID. " , comment : " " )
2019-06-21 11:20:03 -07:00
case . invalidApp : return NSLocalizedString ( " The app is invalid. " , comment : " " )
case . invalidParameters : return NSLocalizedString ( " Invalid parameters. " , comment : " " )
2019-07-30 17:00:04 -07:00
case . noSources : return NSLocalizedString ( " There are no AltStore sources. " , comment : " " )
2019-07-25 14:04:26 -07:00
case . iOSVersionNotSupported ( let app ) :
let name = app . name
var version = " iOS \( app . minimumiOSVersion . majorVersion ) . \( app . minimumiOSVersion . minorVersion ) "
if app . minimumiOSVersion . patchVersion > 0
{
version += " . \( app . minimumiOSVersion . patchVersion ) "
}
let localizedDescription = String ( format : NSLocalizedString ( " %@ requires %@. " , comment : " " ) , name , version )
return localizedDescription
2020-01-24 14:14:08 -08:00
case . maximumAppIDLimitReached : return NSLocalizedString ( " Cannot register more than 10 App IDs. " , comment : " " )
}
}
var recoverySuggestion : String ? {
switch self
{
case . maximumAppIDLimitReached ( let date ) :
let remainingTime : String
let numberOfDays = date . numberOfCalendarDays ( since : Date ( ) )
switch numberOfDays {
case 0 :
let components = Calendar . current . dateComponents ( [ . hour ] , from : Date ( ) , to : date )
let numberOfHours = components . hour !
switch numberOfHours
{
case 1 : remainingTime = NSLocalizedString ( " 1 hour " , comment : " " )
default : remainingTime = String ( format : NSLocalizedString ( " %@ hours " , comment : " " ) , NSNumber ( value : numberOfHours ) )
}
case 1 : remainingTime = NSLocalizedString ( " 1 day " , comment : " " )
default : remainingTime = String ( format : NSLocalizedString ( " %@ days " , comment : " " ) , NSNumber ( value : numberOfDays ) )
}
let message = String ( format : NSLocalizedString ( " Delete sideloaded apps to free up App ID slots. You can register another App ID in %@. " , comment : " " ) , remainingTime )
return message
default : return nil
2019-06-10 15:03:47 -07:00
}
}
}