2022-10-12 04:57:08 +08:00
# import "TSHRootViewController.h"
# import < TSUtil . h >
2022-10-30 06:45:30 +08:00
# import < TSPresentationDelegate . h >
2022-09-02 23:19:48 +08:00
2022-10-12 04:57:08 +08:00
@ implementation TSHRootViewController
2022-09-02 23:19:48 +08:00
2022-09-22 23:38:58 +08:00
- ( BOOL ) isTrollStore
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
return NO ;
2022-09-02 23:19:48 +08:00
}
2022-09-22 23:38:58 +08:00
- ( void ) viewDidLoad
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
[ super viewDidLoad ] ;
2022-10-30 06:45:30 +08:00
TSPresentationDelegate . presentationViewController = self ;
2022-09-22 23:38:58 +08:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self selector : @ selector ( reloadSpecifiers ) name : UIApplicationWillEnterForegroundNotification object : nil ] ;
2022-09-02 23:19:48 +08:00
2022-09-22 23:38:58 +08:00
fetchLatestTrollStoreVersion ( ^ ( NSString * latestVersion )
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
NSString * currentVersion = [ self getTrollStoreVersion ] ;
NSComparisonResult result = [ currentVersion compare : latestVersion options : NSNumericSearch ] ;
if ( result = = NSOrderedAscending )
2022-09-02 23:19:48 +08:00
{
2022-09-22 23:38:58 +08:00
_newerVersion = latestVersion ;
dispatch_async ( dispatch_get _main _queue ( ) , ^
{
[ self reloadSpecifiers ] ;
} ) ;
2022-09-02 23:19:48 +08:00
}
2022-09-22 23:38:58 +08:00
} ) ;
2022-09-02 23:19:48 +08:00
}
- ( NSMutableArray * ) specifiers
{
if ( ! _specifiers )
{
_specifiers = [ NSMutableArray new ] ;
2022-10-12 04:57:08 +08:00
# ifdef EMBEDDED_ROOT _HELPER
2023-11-27 18:46:39 +08:00
NSString * credits = @ "Powered by Fugu15 CoreTrust & installd bugs, thanks to @LinusHenze\n\n© 2023 Lars Fröder (opa334)" ;
2022-10-12 04:57:08 +08:00
# else
2023-11-27 18:46:39 +08:00
NSString * credits = @ "Powered by Fugu15 CoreTrust bug, thanks to @LinusHenze\n\n© 2023 Lars Fröder (opa334)" ;
2022-10-12 04:57:08 +08:00
# endif
2022-09-02 23:19:48 +08:00
PSSpecifier * infoGroupSpecifier = [ PSSpecifier emptyGroupSpecifier ] ;
infoGroupSpecifier . name = @ "Info" ;
[ _specifiers addObject : infoGroupSpecifier ] ;
PSSpecifier * infoSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "TrollStore"
target : self
set : nil
get : @ selector ( getTrollStoreInfoString )
detail : nil
cell : PSTitleValueCell
edit : nil ] ;
infoSpecifier . identifier = @ "info" ;
[ infoSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
[ _specifiers addObject : infoSpecifier ] ;
2022-09-22 23:38:58 +08:00
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 ] ;
}
2022-10-12 04:57:08 +08:00
PSSpecifier * lastGroupSpecifier ;
2022-09-02 23:19:48 +08:00
PSSpecifier * utilitiesGroupSpecifier = [ PSSpecifier emptyGroupSpecifier ] ;
[ _specifiers addObject : utilitiesGroupSpecifier ] ;
2022-10-12 04:57:08 +08:00
lastGroupSpecifier = utilitiesGroupSpecifier ;
2022-11-30 06:46:01 +08:00
if ( isInstalled || trollStoreInstalledAppContainerPaths ( ) . count )
2022-09-02 23:19:48 +08:00
{
PSSpecifier * refreshAppRegistrationsSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "Refresh App Registrations"
target : self
set : nil
get : nil
detail : nil
cell : PSButtonCell
edit : nil ] ;
refreshAppRegistrationsSpecifier . identifier = @ "refreshAppRegistrations" ;
[ refreshAppRegistrationsSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
2022-09-22 23:38:58 +08:00
refreshAppRegistrationsSpecifier . buttonAction = @ selector ( refreshAppRegistrationsPressed ) ;
2022-09-02 23:19:48 +08:00
[ _specifiers addObject : refreshAppRegistrationsSpecifier ] ;
2022-11-30 06:46:01 +08:00
}
if ( isInstalled )
{
2022-09-04 06:48:40 +08:00
PSSpecifier * uninstallTrollStoreSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "Uninstall TrollStore"
target : self
set : nil
get : nil
detail : nil
cell : PSButtonCell
edit : nil ] ;
uninstallTrollStoreSpecifier . identifier = @ "uninstallTrollStore" ;
[ uninstallTrollStoreSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
[ uninstallTrollStoreSpecifier setProperty : NSClassFromString ( @ "PSDeleteButtonCell" ) forKey : @ "cellClass" ] ;
uninstallTrollStoreSpecifier . buttonAction = @ selector ( uninstallTrollStorePressed ) ;
[ _specifiers addObject : uninstallTrollStoreSpecifier ] ;
2022-09-02 23:19:48 +08:00
}
else
{
PSSpecifier * installTrollStoreSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "Install TrollStore"
target : self
set : nil
get : nil
detail : nil
cell : PSButtonCell
edit : nil ] ;
installTrollStoreSpecifier . identifier = @ "installTrollStore" ;
[ installTrollStoreSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
installTrollStoreSpecifier . buttonAction = @ selector ( installTrollStorePressed ) ;
[ _specifiers addObject : installTrollStoreSpecifier ] ;
}
2022-10-30 06:45:30 +08:00
NSString * backupPath = [ safe_getExecutablePath ( ) stringByAppendingString : @ "_TROLLSTORE_BACKUP" ] ;
2022-10-12 04:57:08 +08:00
if ( [ [ NSFileManager defaultManager ] fileExistsAtPath : backupPath ] )
2022-09-02 23:19:48 +08:00
{
2022-10-12 04:57:08 +08:00
PSSpecifier * uninstallHelperGroupSpecifier = [ PSSpecifier emptyGroupSpecifier ] ;
[ _specifiers addObject : uninstallHelperGroupSpecifier ] ;
lastGroupSpecifier = uninstallHelperGroupSpecifier ;
2022-09-02 23:19:48 +08:00
PSSpecifier * uninstallPersistenceHelperSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "Uninstall Persistence Helper"
target : self
set : nil
get : nil
detail : nil
cell : PSButtonCell
edit : nil ] ;
uninstallPersistenceHelperSpecifier . identifier = @ "uninstallPersistenceHelper" ;
[ uninstallPersistenceHelperSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
[ uninstallPersistenceHelperSpecifier setProperty : NSClassFromString ( @ "PSDeleteButtonCell" ) forKey : @ "cellClass" ] ;
uninstallPersistenceHelperSpecifier . buttonAction = @ selector ( uninstallPersistenceHelperPressed ) ;
[ _specifiers addObject : uninstallPersistenceHelperSpecifier ] ;
}
2022-10-12 04:57:08 +08:00
# ifdef EMBEDDED_ROOT _HELPER
LSApplicationProxy * persistenceHelperProxy = findPersistenceHelperApp ( PERSISTENCE_HELPER _TYPE _ALL ) ;
BOOL isRegistered = [ persistenceHelperProxy . bundleIdentifier isEqualToString : NSBundle . mainBundle . bundleIdentifier ] ;
if ( ( isRegistered || ! persistenceHelperProxy ) && ! [ [ NSFileManager defaultManager ] fileExistsAtPath : @ "/Applications/TrollStorePersistenceHelper.app" ] )
{
PSSpecifier * registerUnregisterGroupSpecifier = [ PSSpecifier emptyGroupSpecifier ] ;
lastGroupSpecifier = nil ;
NSString * bottomText ;
PSSpecifier * registerUnregisterSpecifier ;
if ( isRegistered )
{
bottomText = @ "This app is registered as the TrollStore persistence helper and can be used to fix TrollStore app registrations in case they revert back to \" User \ " state and the apps say they're unavailable." ;
registerUnregisterSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "Unregister Persistence Helper"
target : self
set : nil
get : nil
detail : nil
cell : PSButtonCell
edit : nil ] ;
registerUnregisterSpecifier . identifier = @ "registerUnregisterSpecifier" ;
[ registerUnregisterSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
[ registerUnregisterSpecifier setProperty : NSClassFromString ( @ "PSDeleteButtonCell" ) forKey : @ "cellClass" ] ;
registerUnregisterSpecifier . buttonAction = @ selector ( unregisterPersistenceHelperPressed ) ;
}
else if ( ! persistenceHelperProxy )
{
bottomText = @ "If you want to use this app as the TrollStore persistence helper, you can register it here." ;
registerUnregisterSpecifier = [ PSSpecifier preferenceSpecifierNamed : @ "Register Persistence Helper"
target : self
set : nil
get : nil
detail : nil
cell : PSButtonCell
edit : nil ] ;
registerUnregisterSpecifier . identifier = @ "registerUnregisterSpecifier" ;
[ registerUnregisterSpecifier setProperty : @ YES forKey : @ "enabled" ] ;
registerUnregisterSpecifier . buttonAction = @ selector ( registerPersistenceHelperPressed ) ;
}
[ registerUnregisterGroupSpecifier setProperty : [ NSString stringWithFormat : @ "%@\n\n%@" , bottomText , credits ] forKey : @ "footerText" ] ;
lastGroupSpecifier = nil ;
[ _specifiers addObject : registerUnregisterGroupSpecifier ] ;
[ _specifiers addObject : registerUnregisterSpecifier ] ;
}
# endif
if ( lastGroupSpecifier )
{
[ lastGroupSpecifier setProperty : credits forKey : @ "footerText" ] ;
}
2022-09-02 23:19:48 +08:00
}
[ ( UINavigationItem * ) self . navigationItem setTitle : @ "TrollStore Helper" ] ;
return _specifiers ;
}
- ( NSString * ) getTrollStoreInfoString
{
2022-09-22 23:38:58 +08:00
NSString * version = [ self getTrollStoreVersion ] ;
if ( ! version )
2022-09-02 23:19:48 +08:00
{
return @ "Not Installed" ;
}
else
{
return [ NSString stringWithFormat : @ "Installed, %@" , version ] ;
}
}
2022-09-22 23:38:58 +08:00
- ( void ) handleUninstallation
2022-09-04 06:48:40 +08:00
{
2022-09-22 23:38:58 +08:00
_newerVersion = nil ;
[ super handleUninstallation ] ;
2022-09-02 23:19:48 +08:00
}
2022-10-12 04:57:08 +08:00
- ( void ) registerPersistenceHelperPressed
{
int ret = spawnRoot ( rootHelperPath ( ) , @ [ @ "register-user-persistence-helper" , NSBundle . mainBundle . bundleIdentifier ] , nil , nil ) ;
NSLog ( @ "registerPersistenceHelperPressed -> %d" , ret ) ;
if ( ret = = 0 )
{
[ self reloadSpecifiers ] ;
}
}
- ( void ) unregisterPersistenceHelperPressed
{
int ret = spawnRoot ( rootHelperPath ( ) , @ [ @ "uninstall-persistence-helper" ] , nil , nil ) ;
if ( ret = = 0 )
{
[ self reloadSpecifiers ] ;
}
}
2022-09-02 23:19:48 +08:00
@ end