“exists” command added to check if an app with given bundle id is
installed on device or not (closes #107)
This commit is contained in:
parent
56abf4e92e
commit
cab5a31ab5
46
ios-deploy.c
46
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)
|
void copy_file_callback(afc_connection* afc_conn_p, const char *name,int file)
|
||||||
{
|
{
|
||||||
const char *local_name=name;
|
const char *local_name=name;
|
||||||
@ -1456,6 +1490,8 @@ void handle_device(AMDeviceRef device) {
|
|||||||
upload_file(device);
|
upload_file(device);
|
||||||
} else if (strcmp("download", command) == 0) {
|
} else if (strcmp("download", command) == 0) {
|
||||||
download_tree(device);
|
download_tree(device);
|
||||||
|
} else if (strcmp("exists", command) == 0) {
|
||||||
|
exit(app_exists(device));
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -1636,7 +1672,8 @@ void usage(const char* app) {
|
|||||||
" -o, --upload <file> upload file\n"
|
" -o, --upload <file> upload file\n"
|
||||||
" -w, --download download app tree\n"
|
" -w, --download download app tree\n"
|
||||||
" -2, --to <target pathname> use together with up/download file/tree. specify target\n"
|
" -2, --to <target pathname> 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);
|
app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1666,11 +1703,12 @@ int main(int argc, char *argv[]) {
|
|||||||
{ "upload", required_argument, NULL, 'o'},
|
{ "upload", required_argument, NULL, 'o'},
|
||||||
{ "download", optional_argument, NULL, 'w'},
|
{ "download", optional_argument, NULL, 'w'},
|
||||||
{ "to", required_argument, NULL, '2'},
|
{ "to", required_argument, NULL, '2'},
|
||||||
|
{ "exists", no_argument, NULL, 'e'},
|
||||||
{ NULL, 0, NULL, 0 },
|
{ NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
char ch;
|
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) {
|
switch (ch) {
|
||||||
case 'm':
|
case 'm':
|
||||||
@ -1742,6 +1780,10 @@ int main(int argc, char *argv[]) {
|
|||||||
command = "download";
|
command = "download";
|
||||||
list_root = optarg;
|
list_root = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
command_only = true;
|
||||||
|
command = "exists";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return exitcode_error;
|
return exitcode_error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user