2024-08-06 10:43:52 +09:00
|
|
|
//
|
|
|
|
|
// ALTWrappedError.m
|
|
|
|
|
// AltStoreCore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 11/28/22.
|
|
|
|
|
// Copyright © 2022 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "ALTWrappedError.h"
|
|
|
|
|
|
|
|
|
|
@implementation ALTWrappedError
|
|
|
|
|
|
|
|
|
|
+ (BOOL)supportsSecureCoding
|
|
|
|
|
{
|
|
|
|
|
// Required in order to serialize errors for legacy AltServer communication.
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithError:(NSError *)error userInfo:(NSDictionary<NSString *,id> *)userInfo
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
|
|
|
if (self)
|
|
|
|
|
{
|
|
|
|
|
if ([error isKindOfClass:[ALTWrappedError class]])
|
|
|
|
|
{
|
|
|
|
|
_wrappedError = [(ALTWrappedError *)error wrappedError];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_wrappedError = [error copy];
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-07 17:45:09 +05:30
|
|
|
|
2024-08-06 10:43:52 +09:00
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)localizedDescription
|
|
|
|
|
{
|
2022-12-15 15:59:39 -06:00
|
|
|
NSString *localizedFailureReason = self.wrappedError.localizedFailureReason ?: self.wrappedError.localizedDescription;
|
|
|
|
|
|
2022-12-12 16:04:53 -06:00
|
|
|
NSString *wrappedLocalizedDescription = self.wrappedError.userInfo[NSLocalizedDescriptionKey];
|
|
|
|
|
if (wrappedLocalizedDescription != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *localizedFailure = self.wrappedError.userInfo[NSLocalizedFailureErrorKey];
|
|
|
|
|
|
2022-12-15 15:59:39 -06:00
|
|
|
NSString *fallbackDescription = localizedFailure != nil ? [NSString stringWithFormat:@"%@ %@", localizedFailure, localizedFailureReason] : localizedFailureReason;
|
2022-12-12 16:04:53 -06:00
|
|
|
if (![wrappedLocalizedDescription isEqualToString:fallbackDescription])
|
|
|
|
|
{
|
|
|
|
|
return wrappedLocalizedDescription;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 10:43:52 +09:00
|
|
|
NSString *localizedFailure = self.userInfo[NSLocalizedFailureErrorKey];
|
|
|
|
|
if (localizedFailure != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *wrappedLocalizedDescription = self.wrappedError.userInfo[NSLocalizedDescriptionKey];
|
|
|
|
|
NSString *localizedFailureReason = wrappedLocalizedDescription ?: self.wrappedError.localizedFailureReason ?: self.wrappedError.localizedDescription;
|
|
|
|
|
|
|
|
|
|
NSString *localizedDescription = [NSString stringWithFormat:@"%@ %@", localizedFailure, localizedFailureReason];
|
|
|
|
|
return localizedDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// localizedFailure is nil, so return wrappedError's localizedDescription.
|
|
|
|
|
return self.wrappedError.localizedDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)localizedFailureReason
|
|
|
|
|
{
|
|
|
|
|
return self.wrappedError.localizedFailureReason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)localizedRecoverySuggestion
|
|
|
|
|
{
|
|
|
|
|
return self.wrappedError.localizedRecoverySuggestion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)debugDescription
|
|
|
|
|
{
|
|
|
|
|
return self.wrappedError.debugDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)helpAnchor
|
|
|
|
|
{
|
|
|
|
|
return self.wrappedError.helpAnchor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|