2022-09-02 23:19:48 +08:00
# import "TSApplicationsManager.h"
# import "TSUtil.h"
# import "../Helper/Shared.h"
2022-09-03 09:08:59 +08:00
# define TrollStoreErrorDomain @ "TrollStoreErrorDomain"
2022-09-02 23:19:48 +08:00
@ implementation TSApplicationsManager
+ ( instancetype ) sharedInstance
{
static TSApplicationsManager * sharedInstance = nil ;
static dispatch_once _t onceToken ;
dispatch_once ( & onceToken , ^ {
sharedInstance = [ [ TSApplicationsManager alloc ] init ] ;
} ) ;
return sharedInstance ;
}
- ( NSArray * ) installedAppPaths
{
return trollStoreInstalledAppBundlePaths ( ) ;
}
- ( NSDictionary * ) infoDictionaryForAppPath : ( NSString * ) appPath
{
NSString * infoPlistPath = [ appPath stringByAppendingPathComponent : @ "Info.plist" ] ;
return [ NSDictionary dictionaryWithContentsOfFile : infoPlistPath ] ;
}
- ( NSString * ) appIdForAppPath : ( NSString * ) appPath
{
return [ self infoDictionaryForAppPath : appPath ] [ @ "CFBundleIdentifier" ] ;
}
- ( NSString * ) displayNameForAppPath : ( NSString * ) appPath
{
NSDictionary * infoDict = [ self infoDictionaryForAppPath : appPath ] ;
NSString * displayName = infoDict [ @ "CFBundleDisplayName" ] ;
if ( ! [ displayName isKindOfClass : [ NSString class ] ] ) displayName = nil ;
if ( ! displayName || [ displayName isEqualToString : @ "" ] )
{
displayName = infoDict [ @ "CFBundleName" ] ;
if ( ! [ displayName isKindOfClass : [ NSString class ] ] ) displayName = nil ;
if ( ! displayName || [ displayName isEqualToString : @ "" ] )
{
displayName = infoDict [ @ "CFBundleExecutable" ] ;
if ( ! [ displayName isKindOfClass : [ NSString class ] ] ) displayName = [ appPath lastPathComponent ] ;
}
}
return displayName ;
}
2022-09-03 09:08:59 +08:00
- ( NSError * ) errorForCode : ( int ) code
{
NSString * errorDescription = @ "Unknown Error" ;
switch ( code )
{
case 166 :
errorDescription = @ "The IPA file does not exist or is not accessible." ;
break ;
case 167 :
errorDescription = @ "The IPA file does not appear to contain an app." ;
break ;
case 170 :
errorDescription = @ "Failed to create container for app bundle." ;
break ;
case 171 :
2022-09-04 00:49:53 +08:00
errorDescription = @ "A non-TrollStore app with the same identifier is already installed. If you are absolutely sure it is not, you can force install it." ;
2022-09-03 09:08:59 +08:00
break ;
case 172 :
errorDescription = @ "The app does not seem to contain an Info.plist" ;
break ;
2022-09-06 07:04:10 +08:00
case 173 :
errorDescription = @ "The app is not signed with a fake CoreTrust certificate and ldid does not seem to be installed. Make sure ldid is installed in the settings tab and try again." ;
break ;
2022-09-03 09:08:59 +08:00
}
NSError * error = [ NSError errorWithDomain : TrollStoreErrorDomain code : code userInfo : @ { NSLocalizedDescriptionKey : errorDescription } ] ;
return error ;
}
2022-09-04 00:49:53 +08:00
- ( int ) installIpa : ( NSString * ) pathToIpa force : ( BOOL ) force
2022-09-02 23:19:48 +08:00
{
2022-09-04 00:49:53 +08:00
int ret ;
if ( force )
{
ret = spawnRoot ( helperPath ( ) , @ [ @ "install" , pathToIpa , @ "force" ] ) ;
}
else
{
ret = spawnRoot ( helperPath ( ) , @ [ @ "install" , pathToIpa ] ) ;
}
2022-09-02 23:19:48 +08:00
[ [ NSNotificationCenter defaultCenter ] postNotificationName : @ "ApplicationsChanged" object : nil ] ;
return ret ;
}
2022-09-04 00:49:53 +08:00
- ( int ) installIpa : ( NSString * ) pathToIpa
{
return [ self installIpa : pathToIpa force : NO ] ;
}
2022-09-03 09:08:59 +08:00
- ( int ) uninstallApp : ( NSString * ) appId
2022-09-02 23:19:48 +08:00
{
2022-09-04 21:37:49 +08:00
if ( ! appId ) return -200 ;
2022-09-03 09:08:59 +08:00
int ret = spawnRoot ( helperPath ( ) , @ [ @ "uninstall" , appId ] ) ;
2022-09-02 23:19:48 +08:00
[ [ NSNotificationCenter defaultCenter ] postNotificationName : @ "ApplicationsChanged" object : nil ] ;
return ret ;
}
2022-09-04 21:37:49 +08:00
- ( int ) uninstallAppByPath : ( NSString * ) path
{
if ( ! path ) return -200 ;
int ret = spawnRoot ( helperPath ( ) , @ [ @ "uninstall-path" , path ] ) ;
[ [ NSNotificationCenter defaultCenter ] postNotificationName : @ "ApplicationsChanged" object : nil ] ;
return ret ;
}
2022-09-02 23:19:48 +08:00
@ end