mirror of https://github.com/opa334/TrollStore.git
207 lines
6.1 KiB
Objective-C
207 lines
6.1 KiB
Objective-C
#import "TSListControllerShared.h"
|
|
#import "TSUtil.h"
|
|
#import "TSPresentationDelegate.h"
|
|
|
|
@implementation TSListControllerShared
|
|
|
|
- (BOOL)isTrollStore
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
- (NSString*)getTrollStoreVersion
|
|
{
|
|
if([self isTrollStore])
|
|
{
|
|
return [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
|
|
}
|
|
else
|
|
{
|
|
NSString* trollStorePath = trollStoreAppPath();
|
|
if(!trollStorePath) return nil;
|
|
|
|
NSBundle* trollStoreBundle = [NSBundle bundleWithPath:trollStorePath];
|
|
return [trollStoreBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
|
|
}
|
|
}
|
|
|
|
- (void)downloadTrollStoreAndDo:(void (^)(NSString* localTrollStoreTarPath))doHandler
|
|
{
|
|
NSURL* trollStoreURL = [NSURL URLWithString:@"https://github.com/opa334/TrollStore/releases/latest/download/TrollStore.tar"];
|
|
NSURLRequest* trollStoreRequest = [NSURLRequest requestWithURL:trollStoreURL];
|
|
|
|
NSURLSessionDownloadTask* downloadTask = [NSURLSession.sharedSession downloadTaskWithRequest:trollStoreRequest completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error)
|
|
{
|
|
if(error)
|
|
{
|
|
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Error downloading TrollStore: %@", error] preferredStyle:UIAlertControllerStyleAlert];
|
|
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
|
|
[errorAlert addAction:closeAction];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^
|
|
{
|
|
[TSPresentationDelegate stopActivityWithCompletion:^
|
|
{
|
|
[TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil];
|
|
}];
|
|
});
|
|
}
|
|
else
|
|
{
|
|
NSString* tarTmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"TrollStore.tar"];
|
|
[[NSFileManager defaultManager] copyItemAtPath:location.path toPath:tarTmpPath error:nil];
|
|
|
|
doHandler(tarTmpPath);
|
|
}
|
|
}];
|
|
|
|
[downloadTask resume];
|
|
}
|
|
|
|
- (void)_updateOrInstallTrollStore:(BOOL)update
|
|
{
|
|
if(update)
|
|
{
|
|
[TSPresentationDelegate startActivity:@"Updating TrollStore"];
|
|
}
|
|
else
|
|
{
|
|
[TSPresentationDelegate startActivity:@"Installing TrollStore"];
|
|
}
|
|
|
|
[self downloadTrollStoreAndDo:^(NSString* tmpTarPath)
|
|
{
|
|
int ret = spawnRoot(rootHelperPath(), @[@"install-trollstore", tmpTarPath], nil, nil);
|
|
[[NSFileManager defaultManager] removeItemAtPath:tmpTarPath error:nil];
|
|
|
|
if(ret == 0)
|
|
{
|
|
respring();
|
|
|
|
if([self isTrollStore])
|
|
{
|
|
exit(0);
|
|
}
|
|
else
|
|
{
|
|
dispatch_async(dispatch_get_main_queue(), ^
|
|
{
|
|
[TSPresentationDelegate stopActivityWithCompletion:^
|
|
{
|
|
[self reloadSpecifiers];
|
|
}];
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dispatch_async(dispatch_get_main_queue(), ^
|
|
{
|
|
[TSPresentationDelegate stopActivityWithCompletion:^
|
|
{
|
|
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Error installing TrollStore: trollstorehelper returned %d", ret] preferredStyle:UIAlertControllerStyleAlert];
|
|
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
|
|
[errorAlert addAction:closeAction];
|
|
[TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil];
|
|
}];
|
|
});
|
|
}
|
|
}];
|
|
}
|
|
|
|
- (void)installTrollStorePressed
|
|
{
|
|
[self _updateOrInstallTrollStore:NO];
|
|
}
|
|
|
|
- (void)updateTrollStorePressed
|
|
{
|
|
[self _updateOrInstallTrollStore:YES];
|
|
}
|
|
|
|
- (void)rebuildIconCachePressed
|
|
{
|
|
[TSPresentationDelegate startActivity:@"Rebuilding Icon Cache"];
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
|
|
{
|
|
spawnRoot(rootHelperPath(), @[@"refresh-all"], nil, nil);
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^
|
|
{
|
|
[TSPresentationDelegate stopActivityWithCompletion:nil];
|
|
});
|
|
});
|
|
}
|
|
|
|
- (void)refreshAppRegistrationsPressed
|
|
{
|
|
[TSPresentationDelegate startActivity:@"Refreshing"];
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
|
|
{
|
|
spawnRoot(rootHelperPath(), @[@"refresh"], nil, nil);
|
|
respring();
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^
|
|
{
|
|
[TSPresentationDelegate stopActivityWithCompletion:nil];
|
|
});
|
|
});
|
|
}
|
|
|
|
- (void)uninstallPersistenceHelperPressed
|
|
{
|
|
if([self isTrollStore])
|
|
{
|
|
spawnRoot(rootHelperPath(), @[@"uninstall-persistence-helper"], nil, nil);
|
|
[self reloadSpecifiers];
|
|
}
|
|
else
|
|
{
|
|
UIAlertController* uninstallWarningAlert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Uninstalling the persistence helper will revert this app back to it's original state, you will however no longer be able to persistently refresh the TrollStore app registrations. Continue?" preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
|
|
[uninstallWarningAlert addAction:cancelAction];
|
|
|
|
UIAlertAction* continueAction = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action)
|
|
{
|
|
spawnRoot(rootHelperPath(), @[@"uninstall-persistence-helper"], nil, nil);
|
|
exit(0);
|
|
}];
|
|
[uninstallWarningAlert addAction:continueAction];
|
|
|
|
[TSPresentationDelegate presentViewController:uninstallWarningAlert animated:YES completion:nil];
|
|
}
|
|
}
|
|
|
|
- (void)handleUninstallation
|
|
{
|
|
if([self isTrollStore])
|
|
{
|
|
exit(0);
|
|
}
|
|
else
|
|
{
|
|
[self reloadSpecifiers];
|
|
}
|
|
}
|
|
|
|
- (void)uninstallTrollStorePressed
|
|
{
|
|
UIAlertController* uninstallWarningAlert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"About to uninstall TrollStore and all of the apps installed by it. Continue?" preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
|
|
[uninstallWarningAlert addAction:cancelAction];
|
|
|
|
UIAlertAction* continueAction = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action)
|
|
{
|
|
spawnRoot(rootHelperPath(), @[@"uninstall-trollstore"], nil, nil);
|
|
[self handleUninstallation];
|
|
}];
|
|
[uninstallWarningAlert addAction:continueAction];
|
|
|
|
[TSPresentationDelegate presentViewController:uninstallWarningAlert animated:YES completion:nil];
|
|
}
|
|
|
|
@end |