From cab5a31ab5f9752d9fdec1afd6d177bf556115cc Mon Sep 17 00:00:00 2001 From: Ugur Kilic Date: Sat, 7 Mar 2015 16:33:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=9Cexists=E2=80=9D=20command=20added=20to?= =?UTF-8?q?=20check=20if=20an=20app=20with=20given=20bundle=20id=20is=20in?= =?UTF-8?q?stalled=20on=20device=20or=20not=20(closes=20#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios-deploy.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/ios-deploy.c b/ios-deploy.c index e1af3c2..cad9ec3 100644 --- a/ios-deploy.c +++ b/ios-deploy.c @@ -1274,6 +1274,40 @@ void list_files(AMDeviceRef device) } } +int app_exists(AMDeviceRef device) +{ + if (bundle_id == NULL) { + printf("Bundle id is not specified\n"); + return false; + } + + AMDeviceConnect(device); + assert(AMDeviceIsPaired(device)); + assert(AMDeviceValidatePairing(device) == 0); + assert(AMDeviceStartSession(device) == 0); + + CFStringRef cf_bundle_id = CFStringCreateWithCString(NULL, bundle_id, kCFStringEncodingASCII); + + NSArray *a = [NSArray arrayWithObjects:@"CFBundleIdentifier", nil]; + NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:a forKey:@"ReturnAttributes"]; + CFDictionaryRef options = (CFDictionaryRef)optionsDict; + + CFDictionaryRef result = nil; + afc_error_t resultStatus = AMDeviceLookupApplications(device, options, &result); + assert(resultStatus == 0); + + CFDictionaryRef app_dict = CFDictionaryGetValue(result, cf_bundle_id); + + int appExists = (app_dict == NULL) ? -1 : 0; + + CFRelease(cf_bundle_id); + + assert(AMDeviceStopSession(device) == 0); + assert(AMDeviceDisconnect(device) == 0); + + return appExists; +} + void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file) { const char *local_name=name; @@ -1456,6 +1490,8 @@ void handle_device(AMDeviceRef device) { upload_file(device); } else if (strcmp("download", command) == 0) { download_tree(device); + } else if (strcmp("exists", command) == 0) { + exit(app_exists(device)); } exit(0); } @@ -1636,7 +1672,8 @@ void usage(const char* app) { " -o, --upload upload file\n" " -w, --download download app tree\n" " -2, --to use together with up/download file/tree. specify target\n" - " -V, --version print the executable version \n", + " -V, --version print the executable version \n" + " -e, --exists check if the app with given bundle_id is installed or not \n", app); } @@ -1666,11 +1703,12 @@ int main(int argc, char *argv[]) { { "upload", required_argument, NULL, 'o'}, { "download", optional_argument, NULL, 'w'}, { "to", required_argument, NULL, '2'}, + { "exists", no_argument, NULL, 'e'}, { NULL, 0, NULL, 0 }, }; char ch; - while ((ch = getopt_long(argc, argv, "VmcdvunrILi:b:a:t:g:x:p:1:2:o:l::w::", longopts, NULL)) != -1) + while ((ch = getopt_long(argc, argv, "VmcdvunrILei:b:a:t:g:x:p:1:2:o:l::w::", longopts, NULL)) != -1) { switch (ch) { case 'm': @@ -1742,6 +1780,10 @@ int main(int argc, char *argv[]) { command = "download"; list_root = optarg; break; + case 'e': + command_only = true; + command = "exists"; + break; default: usage(argv[0]); return exitcode_error;