Properly handle errors where an app cannot be added to icon cache

This commit is contained in:
opa334 2023-12-12 13:21:58 +01:00
parent bbdd0fdcdd
commit 8cdef95733
4 changed files with 14 additions and 5 deletions

View File

@ -915,7 +915,10 @@ int installApp(NSString* appPackagePath, BOOL sign, BOOL force, BOOL isTSUpdate,
// Also permissions need to be fixed
NSURL* updatedAppURL = findAppURLInBundleURL(appContainer.url);
fixPermissionsOfAppBundle(updatedAppURL.path);
registerPath(updatedAppURL.path, 0, YES);
if (!registerPath(updatedAppURL.path, 0, YES)) {
[[NSFileManager defaultManager] removeItemAtURL:appContainer.url error:nil];
return 181;
}
return 0;
}

View File

@ -1 +1 @@
extern void registerPath(NSString* path, BOOL unregister, BOOL system);
extern bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem);

View File

@ -81,8 +81,8 @@ NSDictionary *constructEnvironmentVariablesForContainerPath(NSString *containerP
};
}
void registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
if (!path) return;
bool registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
if (!path) return false;
LSApplicationWorkspace *workspace = [LSApplicationWorkspace defaultWorkspace];
if (unregister && ![[NSFileManager defaultManager] fileExistsAtPath:path]) {
@ -97,7 +97,7 @@ void registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
NSDictionary *appInfoPlist = [NSDictionary dictionaryWithContentsOfFile:[path stringByAppendingPathComponent:@"Info.plist"]];
NSString *appBundleID = [appInfoPlist objectForKey:@"CFBundleIdentifier"];
if([immutableAppBundleIdentifiers() containsObject:appBundleID.lowercaseString]) return;
if([immutableAppBundleIdentifiers() containsObject:appBundleID.lowercaseString]) return false;
if (appBundleID && !unregister) {
NSString *appExecutablePath = [path stringByAppendingPathComponent:appInfoPlist[@"CFBundleExecutable"]];
@ -236,11 +236,14 @@ void registerPath(NSString *path, BOOL unregister, BOOL forceSystem) {
if (![workspace registerApplicationDictionary:dictToRegister]) {
NSLog(@"Error: Unable to register %@", path);
return false;
}
} else {
NSURL *url = [NSURL fileURLWithPath:path];
if (![workspace unregisterApplication:url]) {
NSLog(@"Error: Unable to register %@", path);
return false;
}
}
return true;
}

View File

@ -77,6 +77,9 @@ extern NSUserDefaults* trollStoreUserDefaults();
case 180:
errorDescription = @"The app you tried to install contains encrypted binaries, which cannot have the CoreTrust bypass applied to them. Please ensure you install decrypted apps.";
break;
case 181:
errorDescription = @"Failed to add app to icon cache.";
break;
}
NSError* error = [NSError errorWithDomain:TrollStoreErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey : errorDescription}];