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
2023-04-01 16:02:12 -07:00
import minimuxer
2019-06-10 15:03:47 -07:00
enum OperationError : LocalizedError
{
2022-09-09 17:44:15 -05:00
static let domain = OperationError . unknown . _domain
2019-06-10 15:03:47 -07:00
case unknown
case unknownResult
case cancelled
2020-05-15 15:11:17 -07:00
case timedOut
2019-06-10 15:03:47 -07:00
case notAuthenticated
case appNotFound
case unknownUDID
2019-06-21 11:20:03 -07:00
case invalidApp
case invalidParameters
2020-02-10 16:30:54 -08:00
case maximumAppIDLimitReached ( application : ALTApplication , requiredAppIDs : Int , availableAppIDs : Int , nextExpirationDate : Date )
2019-07-25 14:04:26 -07:00
2019-07-30 17:00:04 -07:00
case noSources
2020-05-15 15:11:17 -07:00
case openAppFailed ( name : String )
case missingAppGroup
2022-11-02 17:58:59 -07:00
case noDevice
case createService ( name : String )
case getFromDevice ( name : String )
case setArgument ( name : String )
case afc
case install
case uninstall
case lookupApps
case detach
2023-04-01 16:02:12 -07:00
case attach
2022-11-02 17:58:59 -07:00
case functionArguments
2023-04-01 16:02:12 -07:00
case profileManage
2022-11-02 17:58:59 -07:00
case noConnection
2023-04-01 16:02:12 -07:00
case invalidPairingFile
2022-11-02 17:58:59 -07:00
2020-03-30 13:56:40 -07:00
var failureReason : String ? {
2019-06-10 15:03:47 -07:00
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 : " " )
2020-05-15 15:11:17 -07:00
case . timedOut : return NSLocalizedString ( " The operation timed out. " , comment : " " )
2019-06-10 15:03:47 -07:00
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 : " " )
2022-11-05 23:50:07 -07:00
case . noSources : return NSLocalizedString ( " There are no SideStore sources. " , comment : " " )
case . openAppFailed ( let name ) : return String ( format : NSLocalizedString ( " SideStore was denied permission to launch %@. " , comment : " " ) , name )
case . missingAppGroup : return NSLocalizedString ( " SideStore's shared app group could not be found. " , comment : " " )
2020-01-24 14:14:08 -08:00
case . maximumAppIDLimitReached : return NSLocalizedString ( " Cannot register more than 10 App IDs. " , comment : " " )
2022-11-02 17:58:59 -07:00
case . noDevice : return NSLocalizedString ( " Cannot fetch the device from the muxer " , comment : " " )
case . createService ( let name ) : return String ( format : NSLocalizedString ( " Cannot start a %@ server on the device. " , comment : " " ) , name )
case . getFromDevice ( let name ) : return String ( format : NSLocalizedString ( " Cannot fetch %@ from the device. " , comment : " " ) , name )
case . setArgument ( let name ) : return String ( format : NSLocalizedString ( " Cannot set %@ on the device. " , comment : " " ) , name )
case . afc : return NSLocalizedString ( " AFC was unable to manage files on the device " , comment : " " )
case . install : return NSLocalizedString ( " Unable to install the app from the staging directory " , comment : " " )
case . uninstall : return NSLocalizedString ( " Unable to uninstall the app " , comment : " " )
case . lookupApps : return NSLocalizedString ( " Unable to fetch apps from the device " , comment : " " )
case . detach : return NSLocalizedString ( " Unable to detach from the app's process " , comment : " " )
2023-04-01 16:02:12 -07:00
case . attach : return NSLocalizedString ( " Unable to attach to the app's process " , comment : " " )
2022-11-02 17:58:59 -07:00
case . functionArguments : return NSLocalizedString ( " A function was passed invalid arguments " , comment : " " )
2023-04-01 16:02:12 -07:00
case . profileManage : return NSLocalizedString ( " Unable to manage profiles on the device " , comment : " " )
2022-11-02 17:58:59 -07:00
case . noConnection : return NSLocalizedString ( " Unable to connect to the device, make sure Wireguard is enabled and you're connected to WiFi " , comment : " " )
2023-04-01 16:02:12 -07:00
case . invalidPairingFile : return NSLocalizedString ( " Invalid pairing file. Your pairing file either didn't have a UDID, or it wasn't a valid plist. Please use jitterbugpair to generate it " , comment : " " )
2020-01-24 14:14:08 -08:00
}
}
var recoverySuggestion : String ? {
switch self
{
2020-02-10 16:30:54 -08:00
case . maximumAppIDLimitReached ( let application , let requiredAppIDs , let availableAppIDs , let date ) :
let baseMessage = NSLocalizedString ( " Delete sideloaded apps to free up App ID slots. " , comment : " " )
let message : String
2020-01-24 14:14:08 -08:00
2020-02-10 16:30:54 -08:00
if requiredAppIDs > 1
{
let availableText : String
2020-01-24 14:14:08 -08:00
2020-02-10 16:30:54 -08:00
switch availableAppIDs
2020-01-24 14:14:08 -08:00
{
2020-02-10 16:30:54 -08:00
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 ) )
2020-01-24 14:14:08 -08:00
}
2020-02-10 16:30:54 -08:00
let prefixMessage = String ( format : NSLocalizedString ( " %@ requires %@ App IDs, but %@. " , comment : " " ) , application . name , NSNumber ( value : requiredAppIDs ) , availableText )
message = prefixMessage + " " + baseMessage
}
else
{
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 = baseMessage + " " + remainingTimeMessage
2020-01-24 14:14:08 -08:00
}
return message
default : return nil
2019-06-10 15:03:47 -07:00
}
}
}
2022-11-02 17:58:59 -07:00
2023-04-01 16:02:12 -07:00
// / c r a s h e s i f e r r o r i s n o t a M i n i m u x e r E r r o r
func minimuxerToOperationError ( _ error : Error ) -> OperationError {
switch error as ! MinimuxerError {
case . NoDevice :
2022-11-02 17:58:59 -07:00
return OperationError . noDevice
2023-04-01 16:02:12 -07:00
case . NoConnection :
return OperationError . noConnection
case . PairingFile :
return OperationError . invalidPairingFile
case . CreateDebug :
2022-11-02 17:58:59 -07:00
return OperationError . createService ( name : " debug " )
2023-04-01 16:02:12 -07:00
case . CreateInstproxy :
2022-11-02 17:58:59 -07:00
return OperationError . createService ( name : " instproxy " )
2023-04-01 16:02:12 -07:00
case . LookupApps :
2022-11-02 17:58:59 -07:00
return OperationError . getFromDevice ( name : " installed apps " )
2023-04-01 16:02:12 -07:00
case . FindApp :
2022-11-02 17:58:59 -07:00
return OperationError . getFromDevice ( name : " path to the app " )
2023-04-01 16:02:12 -07:00
case . BundlePath :
2022-11-02 17:58:59 -07:00
return OperationError . getFromDevice ( name : " bundle path " )
2023-04-01 16:02:12 -07:00
case . MaxPacket :
2022-11-02 17:58:59 -07:00
return OperationError . setArgument ( name : " max packet " )
2023-04-01 16:02:12 -07:00
case . WorkingDirectory :
2022-11-02 17:58:59 -07:00
return OperationError . setArgument ( name : " working directory " )
2023-04-01 16:02:12 -07:00
case . Argv :
2022-11-02 17:58:59 -07:00
return OperationError . setArgument ( name : " argv " )
2023-04-01 16:02:12 -07:00
case . LaunchSuccess :
2022-11-02 17:58:59 -07:00
return OperationError . getFromDevice ( name : " launch success " )
2023-04-01 16:02:12 -07:00
case . Detach :
2022-11-02 17:58:59 -07:00
return OperationError . detach
2023-04-01 16:02:12 -07:00
case . Attach :
return OperationError . attach
case . CreateAfc :
2022-11-02 17:58:59 -07:00
return OperationError . createService ( name : " AFC " )
2023-04-01 16:02:12 -07:00
case . RwAfc :
2022-11-02 17:58:59 -07:00
return OperationError . afc
2023-04-01 16:02:12 -07:00
case . InstallApp :
2022-11-02 17:58:59 -07:00
return OperationError . install
2023-04-01 16:02:12 -07:00
case . UninstallApp :
2022-11-02 17:58:59 -07:00
return OperationError . uninstall
2023-04-01 16:02:12 -07:00
case . CreateMisagent :
2022-11-02 17:58:59 -07:00
return OperationError . createService ( name : " misagent " )
2023-04-01 16:02:12 -07:00
case . ProfileInstall :
return OperationError . profileManage
case . ProfileRemove :
return OperationError . profileManage
2022-11-02 17:58:59 -07:00
}
}