@@ -1274,6 +1274,40 @@ void list_files(AMDeviceRef device)
1274
1274
}
1275
1275
}
1276
1276
1277
+ int app_exists (AMDeviceRef device )
1278
+ {
1279
+ if (bundle_id == NULL ) {
1280
+ printf ("Bundle id is not specified\n" );
1281
+ return false;
1282
+ }
1283
+
1284
+ AMDeviceConnect (device );
1285
+ assert (AMDeviceIsPaired (device ));
1286
+ assert (AMDeviceValidatePairing (device ) == 0 );
1287
+ assert (AMDeviceStartSession (device ) == 0 );
1288
+
1289
+ CFStringRef cf_bundle_id = CFStringCreateWithCString (NULL , bundle_id , kCFStringEncodingASCII );
1290
+
1291
+ NSArray * a = [NSArray arrayWithObjects :@"CFBundleIdentifier" , nil ];
1292
+ NSDictionary * optionsDict = [NSDictionary dictionaryWithObject :a forKey :@"ReturnAttributes" ];
1293
+ CFDictionaryRef options = (CFDictionaryRef )optionsDict ;
1294
+
1295
+ CFDictionaryRef result = nil ;
1296
+ afc_error_t resultStatus = AMDeviceLookupApplications (device , options , & result );
1297
+ assert (resultStatus == 0 );
1298
+
1299
+ CFDictionaryRef app_dict = CFDictionaryGetValue (result , cf_bundle_id );
1300
+
1301
+ int appExists = (app_dict == NULL ) ? -1 : 0 ;
1302
+
1303
+ CFRelease (cf_bundle_id );
1304
+
1305
+ assert (AMDeviceStopSession (device ) == 0 );
1306
+ assert (AMDeviceDisconnect (device ) == 0 );
1307
+
1308
+ return appExists ;
1309
+ }
1310
+
1277
1311
void copy_file_callback (afc_connection * afc_conn_p , const char * name ,int file )
1278
1312
{
1279
1313
const char * local_name = name ;
@@ -1456,6 +1490,8 @@ void handle_device(AMDeviceRef device) {
1456
1490
upload_file (device );
1457
1491
} else if (strcmp ("download" , command ) == 0 ) {
1458
1492
download_tree (device );
1493
+ } else if (strcmp ("exists" , command ) == 0 ) {
1494
+ exit (app_exists (device ));
1459
1495
}
1460
1496
exit (0 );
1461
1497
}
@@ -1636,7 +1672,8 @@ void usage(const char* app) {
1636
1672
" -o, --upload <file> upload file\n"
1637
1673
" -w, --download download app tree\n"
1638
1674
" -2, --to <target pathname> use together with up/download file/tree. specify target\n"
1639
- " -V, --version print the executable version \n" ,
1675
+ " -V, --version print the executable version \n"
1676
+ " -e, --exists check if the app with given bundle_id is installed or not \n" ,
1640
1677
app );
1641
1678
}
1642
1679
@@ -1666,11 +1703,12 @@ int main(int argc, char *argv[]) {
1666
1703
{ "upload" , required_argument , NULL , 'o' },
1667
1704
{ "download" , optional_argument , NULL , 'w' },
1668
1705
{ "to" , required_argument , NULL , '2' },
1706
+ { "exists" , no_argument , NULL , 'e' },
1669
1707
{ NULL , 0 , NULL , 0 },
1670
1708
};
1671
1709
char ch ;
1672
1710
1673
- while ((ch = getopt_long (argc , argv , "VmcdvunrILi :b:a:t:g:x:p:1:2:o:l::w::" , longopts , NULL )) != -1 )
1711
+ while ((ch = getopt_long (argc , argv , "VmcdvunrILei :b:a:t:g:x:p:1:2:o:l::w::" , longopts , NULL )) != -1 )
1674
1712
{
1675
1713
switch (ch ) {
1676
1714
case 'm' :
@@ -1742,6 +1780,10 @@ int main(int argc, char *argv[]) {
1742
1780
command = "download" ;
1743
1781
list_root = optarg ;
1744
1782
break ;
1783
+ case 'e' :
1784
+ command_only = true;
1785
+ command = "exists" ;
1786
+ break ;
1745
1787
default :
1746
1788
usage (argv [0 ]);
1747
1789
return exitcode_error ;
0 commit comments