[AltServer] Adds ALTServerConnectionError to wrap libimobiledevice errors

This commit is contained in:
Riley Testut
2021-05-20 11:46:38 -07:00
parent bc2dae1b21
commit c97acfc76c
6 changed files with 242 additions and 2 deletions

View File

@@ -10,9 +10,13 @@
extern NSErrorDomain const AltServerErrorDomain;
extern NSErrorDomain const AltServerInstallationErrorDomain;
extern NSErrorDomain const AltServerConnectionErrorDomain;
extern NSErrorUserInfoKey const ALTUnderlyingErrorDomainErrorKey;
extern NSErrorUserInfoKey const ALTUnderlyingErrorCodeErrorKey;
extern NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey;
extern NSErrorUserInfoKey const ALTAppNameErrorKey;
extern NSErrorUserInfoKey const ALTDeviceNameErrorKey;
typedef NS_ERROR_ENUM(AltServerErrorDomain, ALTServerError)
{
@@ -44,6 +48,17 @@ typedef NS_ERROR_ENUM(AltServerErrorDomain, ALTServerError)
ALTServerErrorAppDeletionFailed = 16,
};
typedef NS_ERROR_ENUM(AltServerConnectionErrorDomain, ALTServerConnectionError)
{
ALTServerConnectionErrorUnknown,
ALTServerConnectionErrorDeviceLocked,
ALTServerConnectionErrorInvalidRequest,
ALTServerConnectionErrorInvalidResponse,
ALTServerConnectionErrorUsbmuxd,
ALTServerConnectionErrorSSL,
ALTServerConnectionErrorTimedOut,
};
NS_ASSUME_NONNULL_BEGIN
@interface NSError (ALTServerError)

View File

@@ -10,9 +10,13 @@
NSErrorDomain const AltServerErrorDomain = @"com.rileytestut.AltServer";
NSErrorDomain const AltServerInstallationErrorDomain = @"com.rileytestut.AltServer.Installation";
NSErrorDomain const AltServerConnectionErrorDomain = @"com.rileytestut.AltServer.Connection";
NSErrorUserInfoKey const ALTUnderlyingErrorDomainErrorKey = @"underlyingErrorDomain";
NSErrorUserInfoKey const ALTUnderlyingErrorCodeErrorKey = @"underlyingErrorCode";
NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdentifier";
NSErrorUserInfoKey const ALTAppNameErrorKey = @"appName";
NSErrorUserInfoKey const ALTDeviceNameErrorKey = @"deviceName";
@implementation NSError (ALTServerError)
@@ -23,14 +27,26 @@ NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdenti
{
return [error altserver_localizedFailureReason];
}
if ([userInfoKey isEqualToString:NSLocalizedRecoverySuggestionErrorKey])
else if ([userInfoKey isEqualToString:NSLocalizedRecoverySuggestionErrorKey])
{
return [error altserver_localizedRecoverySuggestion];
}
return nil;
}];
[NSError setUserInfoValueProviderForDomain:AltServerConnectionErrorDomain provider:^id _Nullable(NSError * _Nonnull error, NSErrorUserInfoKey _Nonnull userInfoKey) {
if ([userInfoKey isEqualToString:NSLocalizedDescriptionKey])
{
return [error altserver_connection_localizedDescription];
}
else if ([userInfoKey isEqualToString:NSLocalizedRecoverySuggestionErrorKey])
{
return [error altserver_connection_localizedRecoverySuggestion];
}
return nil;
}];
}
- (nullable NSString *)altserver_localizedFailureReason
@@ -146,5 +162,88 @@ NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdenti
return localizedDescription;
}
#pragma mark - AltServerConnectionErrorDomain -
- (nullable NSString *)altserver_connection_localizedDescription
{
switch ((ALTServerConnectionError)self.code)
{
case ALTServerConnectionErrorUnknown:
{
NSString *underlyingErrorDomain = self.userInfo[ALTUnderlyingErrorDomainErrorKey];
NSString *underlyingErrorCode = self.userInfo[ALTUnderlyingErrorCodeErrorKey];
if (underlyingErrorDomain != nil && underlyingErrorCode != nil)
{
return [NSString stringWithFormat:NSLocalizedString(@"%@ error %@.", @""), underlyingErrorDomain, underlyingErrorCode];
}
else if (underlyingErrorCode != nil)
{
return [NSString stringWithFormat:NSLocalizedString(@"Connection error code: %@", @""), underlyingErrorCode];
}
return nil;
}
case ALTServerConnectionErrorDeviceLocked:
{
NSString *deviceName = self.userInfo[ALTDeviceNameErrorKey] ?: NSLocalizedString(@"The device", @"");
return [NSString stringWithFormat:NSLocalizedString(@"%@ is currently locked.", @""), deviceName];
}
case ALTServerConnectionErrorInvalidRequest:
{
NSString *deviceName = self.userInfo[ALTDeviceNameErrorKey] ?: NSLocalizedString(@"The device", @"");
return [NSString stringWithFormat:NSLocalizedString(@"%@ received an invalid request from AltServer.", @""), deviceName];
}
case ALTServerConnectionErrorInvalidResponse:
{
NSString *deviceName = self.userInfo[ALTDeviceNameErrorKey] ?: NSLocalizedString(@"the device", @"");
return [NSString stringWithFormat:NSLocalizedString(@"AltServer received an invalid response from %@.", @""), deviceName];
}
case ALTServerConnectionErrorUsbmuxd:
{
return NSLocalizedString(@"There was an issue communicating with the usbmuxd daemon.", @"");
}
case ALTServerConnectionErrorSSL:
{
NSString *deviceName = self.userInfo[ALTDeviceNameErrorKey] ?: NSLocalizedString(@"the device", @"");
return [NSString stringWithFormat:NSLocalizedString(@"AltServer could not establish a secure connection to %@.", @""), deviceName];
}
case ALTServerConnectionErrorTimedOut:
{
NSString *deviceName = self.userInfo[ALTDeviceNameErrorKey] ?: NSLocalizedString(@"the device", @"");
return [NSString stringWithFormat:NSLocalizedString(@"AltServer's connection to %@ timed out.", @""), deviceName];
}
}
return nil;
}
- (nullable NSString *)altserver_connection_localizedRecoverySuggestion
{
switch ((ALTServerConnectionError)self.code)
{
case ALTServerConnectionErrorDeviceLocked:
{
return NSLocalizedString(@"Please unlock the device with your passcode and try again.", @"");
}
case ALTServerConnectionErrorUnknown:
case ALTServerConnectionErrorInvalidRequest:
case ALTServerConnectionErrorInvalidResponse:
case ALTServerConnectionErrorUsbmuxd:
case ALTServerConnectionErrorSSL:
case ALTServerConnectionErrorTimedOut:
{
return nil;
}
}
}
@end