Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Sep 22, 2022
1 parent 6905459 commit b67e3aa
Show file tree
Hide file tree
Showing 18 changed files with 456 additions and 238 deletions.
2 changes: 1 addition & 1 deletion Helper/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.opa334.trollstoreroothelper
Name: trollstoreroothelper
Version: 1.0.10
Version: 1.1
Architecture: iphoneos-arm
Description: An awesome tool of some sort!!
Maintainer: opa334
Expand Down
17 changes: 16 additions & 1 deletion Helper/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ int installApp(NSString* appPath, BOOL sign, BOOL force)
// Wipe old version if needed
if(existed)
{
if(![appId isEqualToString:@"com.opa334.TrollStore"])
{
BKSTerminateApplicationForReasonAndReportWithDescription(appId, 5, false, @"TrollStore - App updated");
}

NSLog(@"[installApp] found existing TrollStore app, cleaning directory");
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:appContainer.url includingPropertiesForKeys:nil options:0 errorHandler:nil];
NSURL* fileURL;
Expand All @@ -738,7 +743,7 @@ int installApp(NSString* appPath, BOOL sign, BOOL force)
// do not under any circumstance delete this file as it makes iOS loose the app registration
if([fileURL.lastPathComponent isEqualToString:@".com.apple.mobile_container_manager.metadata.plist"] || [fileURL.lastPathComponent isEqualToString:@"_TrollStore"])
{
NSLog(@"[installApp] skip removal of %@", fileURL);
NSLog(@"[installApp] skipping removal of %@", fileURL);
continue;
}

Expand Down Expand Up @@ -767,6 +772,8 @@ int installApp(NSString* appPath, BOOL sign, BOOL force)

int uninstallApp(NSString* appPath, NSString* appId)
{
BKSTerminateApplicationForReasonAndReportWithDescription(appId, 5, false, @"TrollStore - App uninstalled");

LSApplicationProxy* appProxy = [LSApplicationProxy applicationProxyForIdentifier:appId];
MCMContainer *appContainer = [objc_getClass("MCMAppDataContainer") containerWithIdentifier:appId createIfNecessary:NO existed:nil error:nil];
NSString *containerPath = [appContainer url].path;
Expand Down Expand Up @@ -1156,6 +1163,14 @@ int main(int argc, char *argv[], char *envp[]) {
} else if([cmd isEqualToString:@"uninstall-persistence-helper"])
{
uninstallPersistenceHelper();
} else if([cmd isEqualToString:@"dash"])
{
LSApplicationProxy* appProxy = findPersistenceHelperApp();
if(appProxy)
{
NSString* executablePath = appProxy.canonicalExecutablePath;
registerPath((char*)executablePath.UTF8String, 1);
}
}

NSLog(@"returning %d", ret);
Expand Down
6 changes: 4 additions & 2 deletions Helper/uicache.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ void registerPath(char* cPath, int unregister)
// Misc

dictToRegister[@"ApplicationType"] = @"System";
dictToRegister[@"BundleNameIsLocalized"] = @1;
dictToRegister[@"CFBundleIdentifier"] = appBundleID;
dictToRegister[@"CodeInfoIdentifier"] = appBundleID;
dictToRegister[@"CompatibilityState"] = @0;
Expand All @@ -144,6 +143,10 @@ void registerPath(char* cPath, int unregister)
dictToRegister[@"SignerIdentity"] = @"Apple iPhone OS Application Signing";
dictToRegister[@"IsAdHocSigned"] = @YES;
dictToRegister[@"LSInstallType"] = @1;
dictToRegister[@"HasMIDBasedSINF"] = @0;
dictToRegister[@"MissingSINF"] = @0;
dictToRegister[@"FamilyID"] = @0;
dictToRegister[@"IsOnDemandInstallCapable"] = @0;

NSString* teamIdentifier = constructTeamIdentifierForEntitlements(entitlements);
if(teamIdentifier) dictToRegister[@"TeamIdentifier"] = teamIdentifier;
Expand Down Expand Up @@ -199,7 +202,6 @@ void registerPath(char* cPath, int unregister)
// Misc

pluginDict[@"ApplicationType"] = @"PluginKitPlugin";
pluginDict[@"BundleNameIsLocalized"] = @1;
pluginDict[@"CFBundleIdentifier"] = pluginBundleID;
pluginDict[@"CodeInfoIdentifier"] = pluginBundleID;
pluginDict[@"CompatibilityState"] = @0;
Expand Down
2 changes: 1 addition & 1 deletion PersistenceHelper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include $(THEOS)/makefiles/common.mk

APPLICATION_NAME = TrollStorePersistenceHelper

TrollStorePersistenceHelper_FILES = $(wildcard *.m) ../Helper/Shared.m ../Store/TSUtil.m
TrollStorePersistenceHelper_FILES = $(wildcard *.m) ../Helper/Shared.m ../Store/TSUtil.m ../Store/TSListControllerShared.m
TrollStorePersistenceHelper_FRAMEWORKS = UIKit CoreGraphics CoreServices
TrollStorePersistenceHelper_PRIVATE_FRAMEWORKS = Preferences
TrollStorePersistenceHelper_CFLAGS = -fobjc-arc
Expand Down
2 changes: 1 addition & 1 deletion PersistenceHelper/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1.0.10</string>
<string>1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
Expand Down
8 changes: 3 additions & 5 deletions PersistenceHelper/TSPHRootViewController.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#import <UIKit/UIKit.h>
#import <Preferences/PSListController.h>
#import <Preferences/PSSpecifier.h>
#import "../Store/TSListControllerShared.h"

@interface TSPHRootViewController : PSListController
@interface TSPHRootViewController : TSListControllerShared
{
UIAlertController* _activityController;
NSString* _newerVersion;
}
@end
172 changes: 40 additions & 132 deletions PersistenceHelper/TSPHRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,29 @@

@implementation TSPHRootViewController

- (void)loadView
- (BOOL)isTrollStore
{
[super loadView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadSpecifiers) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)startActivity:(NSString*)activity
{
if(_activityController) return;

_activityController = [UIAlertController alertControllerWithTitle:activity message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(5,5,50,50)];
activityIndicator.hidesWhenStopped = YES;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
[activityIndicator startAnimating];
[_activityController.view addSubview:activityIndicator];

[self presentViewController:_activityController animated:YES completion:nil];
return NO;
}

- (void)stopActivityWithCompletion:(void (^)(void))completion
- (void)viewDidLoad
{
if(!_activityController) return;
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadSpecifiers) name:UIApplicationWillEnterForegroundNotification object:nil];

[_activityController dismissViewControllerAnimated:YES completion:^
fetchLatestTrollStoreVersion(^(NSString* latestVersion)
{
_activityController = nil;
if(completion)
NSString* currentVersion = [self getTrollStoreVersion];
NSComparisonResult result = [currentVersion compare:latestVersion options:NSNumericSearch];
if(result == NSOrderedAscending)
{
completion();
_newerVersion = latestVersion;
dispatch_async(dispatch_get_main_queue(), ^
{
[self reloadSpecifiers];
});
}
}];
});
}

- (NSMutableArray*)specifiers
Expand All @@ -60,10 +51,28 @@ - (NSMutableArray*)specifiers

[_specifiers addObject:infoSpecifier];

BOOL isInstalled = trollStoreAppPath();

if(_newerVersion && isInstalled)
{
// Update TrollStore
PSSpecifier* updateTrollStoreSpecifier = [PSSpecifier preferenceSpecifierNamed:[NSString stringWithFormat:@"Update TrollStore to %@", _newerVersion]
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
updateTrollStoreSpecifier.identifier = @"updateTrollStore";
[updateTrollStoreSpecifier setProperty:@YES forKey:@"enabled"];
updateTrollStoreSpecifier.buttonAction = @selector(updateTrollStorePressed);
[_specifiers addObject:updateTrollStoreSpecifier];
}

PSSpecifier* utilitiesGroupSpecifier = [PSSpecifier emptyGroupSpecifier];
[_specifiers addObject:utilitiesGroupSpecifier];

if(trollStoreAppPath())
if(isInstalled)
{
PSSpecifier* refreshAppRegistrationsSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Refresh App Registrations"
target:self
Expand All @@ -74,7 +83,7 @@ - (NSMutableArray*)specifiers
edit:nil];
refreshAppRegistrationsSpecifier.identifier = @"refreshAppRegistrations";
[refreshAppRegistrationsSpecifier setProperty:@YES forKey:@"enabled"];
refreshAppRegistrationsSpecifier.buttonAction = @selector(refreshAppRegistrations);
refreshAppRegistrationsSpecifier.buttonAction = @selector(refreshAppRegistrationsPressed);
[_specifiers addObject:refreshAppRegistrationsSpecifier];

PSSpecifier* uninstallTrollStoreSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Uninstall TrollStore"
Expand Down Expand Up @@ -130,122 +139,21 @@ - (NSMutableArray*)specifiers

- (NSString*)getTrollStoreInfoString
{
NSString* trollStore = trollStoreAppPath();
if(!trollStore)
NSString* version = [self getTrollStoreVersion];
if(!version)
{
return @"Not Installed";
}
else
{
NSBundle* trollStoreBundle = [NSBundle bundleWithPath:trollStore];
NSString* version = [trollStoreBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
return [NSString stringWithFormat:@"Installed, %@", version];
}
}

- (void)refreshAppRegistrations
{
[self startActivity:@"Refreshing"];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
spawnRoot(helperPath(), @[@"refresh"], nil, nil);
respring();

dispatch_async(dispatch_get_main_queue(), ^
{
[self stopActivityWithCompletion:nil];
});
});
}

- (void)installTrollStorePressed
{
NSURL* trollStoreURL = [NSURL URLWithString:@"https://github.com/opa334/TrollStore/releases/latest/download/TrollStore.tar"];
NSURLRequest* trollStoreRequest = [NSURLRequest requestWithURL:trollStoreURL];

[self startActivity:@"Installing TrollStore"];

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(), ^
{
[self stopActivityWithCompletion:^
{
[self presentViewController:errorAlert animated:YES completion:nil];
}];
});
}
else
{
NSString* tarTmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"TrollStore.tar"];
[[NSFileManager defaultManager] copyItemAtPath:location.path toPath:tarTmpPath error:nil];

int ret = spawnRoot(helperPath(), @[@"install-trollstore", tarTmpPath], nil, nil);
dispatch_async(dispatch_get_main_queue(), ^
{
[[NSFileManager defaultManager] removeItemAtPath:tarTmpPath error:nil];
[self stopActivityWithCompletion:^
{
[self reloadSpecifiers];

if(ret == 0)
{
respring();
}
else
{
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];
[self presentViewController:errorAlert animated:YES completion:nil];
}
}];
});
}
}];

[downloadTask resume];
}

- (void)uninstallTrollStorePressed
- (void)handleUninstallation
{
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(helperPath(), @[@"uninstall-trollstore"], nil, nil);
[self reloadSpecifiers];
}];
[uninstallWarningAlert addAction:continueAction];

[self presentViewController:uninstallWarningAlert animated:YES completion:nil];
}

- (void)uninstallPersistenceHelperPressed
{
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(helperPath(), @[@"uninstall-persistence-helper"], nil, nil);
exit(0);
}];
[uninstallWarningAlert addAction:continueAction];

[self presentViewController:uninstallWarningAlert animated:YES completion:nil];
_newerVersion = nil;
[super handleUninstallation];
}

@end
2 changes: 1 addition & 1 deletion PersistenceHelper/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.opa334.trollstorehelper
Name: TrollStore Helper
Version: 1.0.10
Version: 1.1
Architecture: iphoneos-arm
Description: Helper utility to install and manage TrollStore!
Maintainer: opa334
Expand Down
2 changes: 1 addition & 1 deletion Store/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1.0.10</string>
<string>1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
Expand Down
Loading

0 comments on commit b67e3aa

Please sign in to comment.