summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-07-18 17:22:13 +0200
committerGravatar Nikias Bassen2013-07-18 17:22:13 +0200
commitdee792dc79246d3fe7b0e5ddccc3c44c8a5379a6 (patch)
tree44df246bdae408b579b6ccc05727a076ea7bc429
parent127f9d363fb59abb68104ae0386e891ecdfcf63f (diff)
downloadideviceinstaller-dee792dc79246d3fe7b0e5ddccc3c44c8a5379a6.tar.gz
ideviceinstaller-dee792dc79246d3fe7b0e5ddccc3c44c8a5379a6.tar.bz2
allow installing developer apps by passing a .app directory
-rw-r--r--src/ideviceinstaller.c75
1 files changed, 65 insertions, 10 deletions
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c
index a99df2c..3aac8ae 100644
--- a/src/ideviceinstaller.c
+++ b/src/ideviceinstaller.c
@@ -35,6 +35,7 @@
35#include <inttypes.h> 35#include <inttypes.h>
36#include <limits.h> 36#include <limits.h>
37#include <sys/stat.h> 37#include <sys/stat.h>
38#include <dirent.h>
38 39
39#include <libimobiledevice/libimobiledevice.h> 40#include <libimobiledevice/libimobiledevice.h>
40#include <libimobiledevice/lockdown.h> 41#include <libimobiledevice/lockdown.h>
@@ -428,6 +429,42 @@ static int afc_upload_file(afc_client_t afc, const char* filename, const char* d
428 return 0; 429 return 0;
429} 430}
430 431
432static void afc_upload_dir(afc_client_t afc, const char* path, const char* afcpath)
433{
434 afc_make_directory(afc, afcpath);
435
436 DIR *dir = opendir(path);
437 if (dir) {
438 struct dirent* ep;
439 while ((ep = readdir(dir))) {
440 if ((strcmp(ep->d_name, ".") == 0) || (strcmp(ep->d_name, "..") == 0)) {
441 continue;
442 }
443 char *fpath = (char*)malloc(strlen(path)+1+strlen(ep->d_name)+1);
444 char *apath = (char*)malloc(strlen(afcpath)+1+strlen(ep->d_name)+1);
445
446 struct stat st;
447
448 strcpy(fpath, path);
449 strcat(fpath, "/");
450 strcat(fpath, ep->d_name);
451
452 strcpy(apath, afcpath);
453 strcat(apath, "/");
454 strcat(apath, ep->d_name);
455
456 if ((stat(fpath, &st) == 0) && S_ISDIR(st.st_mode)) {
457 afc_upload_dir(afc, fpath, apath);
458 } else {
459 afc_upload_file(afc, fpath, apath);
460 }
461 free(fpath);
462 free(apath);
463 }
464 closedir(dir);
465 }
466}
467
431int main(int argc, char **argv) 468int main(int argc, char **argv)
432{ 469{
433 idevice_t phone = NULL; 470 idevice_t phone = NULL;
@@ -652,17 +689,19 @@ run_again:
652 free(strs); 689 free(strs);
653 } 690 }
654 691
655 /* open install package */
656 int errp = 0;
657 struct zip *zf = zip_open(appid, 0, &errp);
658 if (!zf) {
659 fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp);
660 goto leave_cleanup;
661 }
662
663 plist_t client_opts = instproxy_client_options_new(); 692 plist_t client_opts = instproxy_client_options_new();
664 693
694 /* open install package */
695 int errp = 0;
696 struct zip *zf = NULL;
697
665 if ((strlen(appid) > 5) && (strcmp(&appid[strlen(appid)-5], ".ipcc") == 0)) { 698 if ((strlen(appid) > 5) && (strcmp(&appid[strlen(appid)-5], ".ipcc") == 0)) {
699 zf = zip_open(appid, 0, &errp);
700 if (!zf) {
701 fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp);
702 goto leave_cleanup;
703 }
704
666 char* ipcc = strdup(appid); 705 char* ipcc = strdup(appid);
667 if ((asprintf(&pkgname, "%s/%s", PKG_PATH, basename(ipcc)) > 0) && pkgname) { 706 if ((asprintf(&pkgname, "%s/%s", PKG_PATH, basename(ipcc)) > 0) && pkgname) {
668 afc_make_directory(afc, pkgname); 707 afc_make_directory(afc, pkgname);
@@ -749,7 +788,21 @@ run_again:
749 printf("done.\n"); 788 printf("done.\n");
750 789
751 instproxy_client_options_add(client_opts, "PackageType", "CarrierBundle", NULL); 790 instproxy_client_options_add(client_opts, "PackageType", "CarrierBundle", NULL);
791 } else if (S_ISDIR(fst.st_mode)) {
792 /* upload developer app directory */
793 instproxy_client_options_add(client_opts, "PackageType", "Developer", NULL);
794
795 asprintf(&pkgname, "%s/%s", PKG_PATH, basename(appid));
796
797 printf("Uploading %s package contents...\n", basename(appid));
798 afc_upload_dir(afc, appid, pkgname);
752 } else { 799 } else {
800 zf = zip_open(appid, 0, &errp);
801 if (!zf) {
802 fprintf(stderr, "ERROR: zip_open: %s: %d\n", appid, errp);
803 goto leave_cleanup;
804 }
805
753 /* extract iTunesMetadata.plist from package */ 806 /* extract iTunesMetadata.plist from package */
754 char *zbuf = NULL; 807 char *zbuf = NULL;
755 uint32_t len = 0; 808 uint32_t len = 0;
@@ -860,8 +913,10 @@ run_again:
860 instproxy_client_options_add(client_opts, "iTunesMetadata", meta, NULL); 913 instproxy_client_options_add(client_opts, "iTunesMetadata", meta, NULL);
861 } 914 }
862 } 915 }
863 zip_unchange_all(zf); 916 if (zf) {
864 zip_close(zf); 917 zip_unchange_all(zf);
918 zip_close(zf);
919 }
865 920
866 /* perform installation or upgrade */ 921 /* perform installation or upgrade */
867 if (install_mode) { 922 if (install_mode) {