mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltServer] Adds ALTServerConnectionError to wrap libimobiledevice errors
This commit is contained in:
25
AltServer/Categories/NSError+libimobiledevice.h
Normal file
25
AltServer/Categories/NSError+libimobiledevice.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// NSError+libimobiledevice.h
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 3/23/21.
|
||||
// Copyright © 2021 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
#import <libimobiledevice/mobile_image_mounter.h>
|
||||
#import <libimobiledevice/debugserver.h>
|
||||
#import <libimobiledevice/installation_proxy.h>
|
||||
|
||||
#import <AltSign/ALTDevice.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NSError (libimobiledevice)
|
||||
|
||||
+ (nullable instancetype)errorWithMobileImageMounterError:(mobile_image_mounter_error_t)error device:(nullable ALTDevice *)device;
|
||||
+ (nullable instancetype)errorWithDebugServerError:(debugserver_error_t)error device:(nullable ALTDevice *)device;
|
||||
+ (nullable instancetype)errorWithInstallationProxyError:(instproxy_error_t)error device:(nullable ALTDevice *)device;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
86
AltServer/Categories/NSError+libimobiledevice.mm
Normal file
86
AltServer/Categories/NSError+libimobiledevice.mm
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// NSError+libimobiledevice.m
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 3/23/21.
|
||||
// Copyright © 2021 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSError+libimobiledevice.h"
|
||||
#import "NSError+ALTServerError.h"
|
||||
|
||||
@implementation NSError (libimobiledevice)
|
||||
|
||||
+ (nullable instancetype)errorWithMobileImageMounterError:(mobile_image_mounter_error_t)error device:(nullable ALTDevice *)device
|
||||
{
|
||||
NSMutableDictionary *userInfo = [@{
|
||||
ALTUnderlyingErrorDomainErrorKey: @"Mobile Image Mounter",
|
||||
ALTUnderlyingErrorCodeErrorKey: [@(error) description],
|
||||
} mutableCopy];
|
||||
|
||||
if (device)
|
||||
{
|
||||
userInfo[ALTDeviceNameErrorKey] = device.name;
|
||||
}
|
||||
|
||||
switch (error)
|
||||
{
|
||||
case MOBILE_IMAGE_MOUNTER_E_SUCCESS: return nil;
|
||||
case MOBILE_IMAGE_MOUNTER_E_INVALID_ARG: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidRequest userInfo:userInfo];
|
||||
case MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidResponse userInfo:userInfo];
|
||||
case MOBILE_IMAGE_MOUNTER_E_CONN_FAILED: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUsbmuxd userInfo:userInfo];
|
||||
case MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidRequest userInfo:userInfo];
|
||||
case MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorDeviceLocked userInfo:userInfo];
|
||||
case MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUnknown userInfo:userInfo];
|
||||
}
|
||||
}
|
||||
|
||||
+ (nullable instancetype)errorWithDebugServerError:(debugserver_error_t)error device:(nullable ALTDevice *)device
|
||||
{
|
||||
NSMutableDictionary *userInfo = [@{
|
||||
ALTUnderlyingErrorDomainErrorKey: @"Debug Server",
|
||||
ALTUnderlyingErrorCodeErrorKey: [@(error) description],
|
||||
} mutableCopy];
|
||||
|
||||
if (device)
|
||||
{
|
||||
userInfo[ALTDeviceNameErrorKey] = device.name;
|
||||
}
|
||||
|
||||
switch (error)
|
||||
{
|
||||
case DEBUGSERVER_E_SUCCESS: return nil;
|
||||
case DEBUGSERVER_E_INVALID_ARG: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidRequest userInfo:userInfo];
|
||||
case DEBUGSERVER_E_MUX_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUsbmuxd userInfo:userInfo];
|
||||
case DEBUGSERVER_E_SSL_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorSSL userInfo:userInfo];
|
||||
case DEBUGSERVER_E_RESPONSE_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidResponse userInfo:userInfo];
|
||||
case DEBUGSERVER_E_TIMEOUT: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorTimedOut userInfo:userInfo];
|
||||
case DEBUGSERVER_E_UNKNOWN_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUnknown userInfo:userInfo];
|
||||
}
|
||||
}
|
||||
|
||||
+ (nullable instancetype)errorWithInstallationProxyError:(instproxy_error_t)error device:(nullable ALTDevice *)device
|
||||
{
|
||||
NSMutableDictionary *userInfo = [@{
|
||||
ALTUnderlyingErrorDomainErrorKey: @"Installation Proxy",
|
||||
ALTUnderlyingErrorCodeErrorKey: [@(error) description],
|
||||
} mutableCopy];
|
||||
|
||||
if (device)
|
||||
{
|
||||
userInfo[ALTDeviceNameErrorKey] = device.name;
|
||||
}
|
||||
|
||||
switch (error)
|
||||
{
|
||||
case INSTPROXY_E_SUCCESS: return nil;
|
||||
case INSTPROXY_E_INVALID_ARG: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidRequest userInfo:userInfo];
|
||||
case INSTPROXY_E_PLIST_ERROR: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorInvalidResponse userInfo:userInfo];
|
||||
case INSTPROXY_E_CONN_FAILED: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUsbmuxd userInfo:userInfo];
|
||||
case INSTPROXY_E_RECEIVE_TIMEOUT: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorTimedOut userInfo:userInfo];
|
||||
// case INSTPROXY_E_DEVICE_OS_VERSION_TOO_LOW: return [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorUnsupportediOSVersion userInfo:nil]; // Error message assumes we're installing AltStore
|
||||
default: return [NSError errorWithDomain:AltServerConnectionErrorDomain code:ALTServerConnectionErrorUnknown userInfo:userInfo];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user