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
2023-05-18 01:30:18 -07:00
case anisetteV1Error ( message : String )
case provisioningError ( result : String , message : String ? )
case anisetteV3Error ( message : String )
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 : " " )
2023-05-18 01:30:18 -07:00
case . anisetteV1Error ( let message ) : return String ( format : NSLocalizedString ( " An error occurred when getting anisette data from a V1 server: %@. Try using another anisette server. " , comment : " " ) , message )
case . provisioningError ( let result , let message ) : return String ( format : NSLocalizedString ( " An error occurred when provisioning: %@%@. Please try again. If the issue persists, report it on GitHub Issues! " , comment : " " ) , result , message != nil ? ( " ( " + message ! + " ) " ) : " " )
case . anisetteV3Error ( let message ) : return String ( format : NSLocalizedString ( " An error occurred when getting anisette data from a V3 server: %@. Please try again. If the issue persists, report it on GitHub Issues! " , comment : " " ) , message )
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-11 21:04:07 -07:00
extension MinimuxerError : LocalizedError {
public var failureReason : String ? {
switch self {
2023-04-09 13:38:44 -07:00
case . NoDevice :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Cannot fetch the device from the muxer " , comment : " " )
2023-04-09 13:38:44 -07:00
case . NoConnection :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to connect to the device, make sure Wireguard is enabled and you're connected to WiFi " , comment : " " )
2023-04-09 13:38:44 -07:00
case . PairingFile :
2023-04-11 21:04:07 -07:00
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 : " " )
2023-04-09 13:38:44 -07:00
case . CreateDebug :
2023-04-11 21:04:07 -07:00
return self . createService ( name : " debug " )
2023-04-09 13:38:44 -07:00
case . LookupApps :
2023-04-11 21:04:07 -07:00
return self . getFromDevice ( name : " installed apps " )
2023-04-09 13:38:44 -07:00
case . FindApp :
2023-04-11 21:04:07 -07:00
return self . getFromDevice ( name : " path to the app " )
2023-04-09 13:38:44 -07:00
case . BundlePath :
2023-04-11 21:04:07 -07:00
return self . getFromDevice ( name : " bundle path " )
2023-04-09 13:38:44 -07:00
case . MaxPacket :
2023-04-11 21:04:07 -07:00
return self . setArgument ( name : " max packet " )
2023-04-09 13:38:44 -07:00
case . WorkingDirectory :
2023-04-11 21:04:07 -07:00
return self . setArgument ( name : " working directory " )
2023-04-09 13:38:44 -07:00
case . Argv :
2023-04-11 21:04:07 -07:00
return self . setArgument ( name : " argv " )
2023-04-09 13:38:44 -07:00
case . LaunchSuccess :
2023-04-11 21:04:07 -07:00
return self . getFromDevice ( name : " launch success " )
2023-04-09 13:38:44 -07:00
case . Detach :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to detach from the app's process " , comment : " " )
2023-04-09 13:38:44 -07:00
case . Attach :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to attach to the app's process " , comment : " " )
case . CreateInstproxy :
return self . createService ( name : " instproxy " )
2023-04-09 13:38:44 -07:00
case . CreateAfc :
2023-04-11 21:04:07 -07:00
return self . createService ( name : " AFC " )
2023-04-09 13:38:44 -07:00
case . RwAfc :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " AFC was unable to manage files on the device " , comment : " " )
2023-04-09 13:38:44 -07:00
case . InstallApp :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to install the app from the staging directory " , comment : " " )
2023-04-09 13:38:44 -07:00
case . UninstallApp :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to uninstall the app " , comment : " " )
2023-04-09 13:38:44 -07:00
case . CreateMisagent :
2023-04-11 21:04:07 -07:00
return self . createService ( name : " misagent " )
2023-04-09 13:38:44 -07:00
case . ProfileInstall :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to manage profiles on the device " , comment : " " )
2023-04-09 13:38:44 -07:00
case . ProfileRemove :
2023-04-11 21:04:07 -07:00
return NSLocalizedString ( " Unable to manage profiles on the device " , comment : " " )
2023-04-09 13:38:44 -07:00
}
2022-11-02 17:58:59 -07:00
}
2023-04-11 21:04:07 -07:00
fileprivate func createService ( name : String ) -> String {
return String ( format : NSLocalizedString ( " Cannot start a %@ server on the device. " , comment : " " ) , name )
}
fileprivate func getFromDevice ( name : String ) -> String {
return String ( format : NSLocalizedString ( " Cannot fetch %@ from the device. " , comment : " " ) , name )
}
fileprivate func setArgument ( name : String ) -> String {
return String ( format : NSLocalizedString ( " Cannot set %@ on the device. " , comment : " " ) , name )
2022-11-02 17:58:59 -07:00
}
2023-04-09 13:38:44 -07:00
return error as ! OperationError
2022-11-02 17:58:59 -07:00
}