diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/idevicescreenshot.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c index 8f5fcaf..486265e 100644 --- a/tools/idevicescreenshot.c +++ b/tools/idevicescreenshot.c | |||
| @@ -40,6 +40,7 @@ int main(int argc, char **argv) | |||
| 40 | int result = -1; | 40 | int result = -1; |
| 41 | int i; | 41 | int i; |
| 42 | const char *udid = NULL; | 42 | const char *udid = NULL; |
| 43 | char *filename = NULL; | ||
| 43 | 44 | ||
| 44 | /* parse cmdline args */ | 45 | /* parse cmdline args */ |
| 45 | for (i = 1; i < argc; i++) { | 46 | for (i = 1; i < argc; i++) { |
| @@ -60,6 +61,10 @@ int main(int argc, char **argv) | |||
| 60 | print_usage(argc, argv); | 61 | print_usage(argc, argv); |
| 61 | return 0; | 62 | return 0; |
| 62 | } | 63 | } |
| 64 | else if (argv[i][0] != '-' && !filename) { | ||
| 65 | filename = strdup(argv[i]); | ||
| 66 | continue; | ||
| 67 | } | ||
| 63 | else { | 68 | else { |
| 64 | print_usage(argc, argv); | 69 | print_usage(argc, argv); |
| 65 | return 0; | 70 | return 0; |
| @@ -88,10 +93,12 @@ int main(int argc, char **argv) | |||
| 88 | printf("Could not connect to screenshotr!\n"); | 93 | printf("Could not connect to screenshotr!\n"); |
| 89 | } else { | 94 | } else { |
| 90 | char *imgdata = NULL; | 95 | char *imgdata = NULL; |
| 91 | char filename[36]; | ||
| 92 | uint64_t imgsize = 0; | 96 | uint64_t imgsize = 0; |
| 93 | time_t now = time(NULL); | 97 | if (!filename) { |
| 94 | strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S.tiff", gmtime(&now)); | 98 | time_t now = time(NULL); |
| 99 | filename = (char*)malloc(36); | ||
| 100 | strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S.tiff", gmtime(&now)); | ||
| 101 | } | ||
| 95 | if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) { | 102 | if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) { |
| 96 | FILE *f = fopen(filename, "wb"); | 103 | FILE *f = fopen(filename, "wb"); |
| 97 | if (f) { | 104 | if (f) { |
| @@ -118,6 +125,7 @@ int main(int argc, char **argv) | |||
| 118 | lockdownd_service_descriptor_free(service); | 125 | lockdownd_service_descriptor_free(service); |
| 119 | 126 | ||
| 120 | idevice_free(device); | 127 | idevice_free(device); |
| 128 | free(filename); | ||
| 121 | 129 | ||
| 122 | return result; | 130 | return result; |
| 123 | } | 131 | } |
| @@ -127,9 +135,11 @@ void print_usage(int argc, char **argv) | |||
| 127 | char *name = NULL; | 135 | char *name = NULL; |
| 128 | 136 | ||
| 129 | name = strrchr(argv[0], '/'); | 137 | name = strrchr(argv[0], '/'); |
| 130 | printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | 138 | printf("Usage: %s [OPTIONS] [FILE]\n", (name ? name + 1: argv[0])); |
| 131 | printf("Gets a screenshot from a device.\n"); | 139 | printf("Gets a screenshot from a device.\n"); |
| 132 | printf("The screenshot is saved as a TIFF image in the current directory.\n"); | 140 | printf("The screenshot is saved as a TIFF image with the given FILE name,\n"); |
| 141 | printf("where the default name is \"screenshot-DATE.tiff\", e.g.:\n"); | ||
| 142 | printf(" ./screenshot-2013-12-31-23-59-59.tiff\n\n"); | ||
| 133 | printf("NOTE: A mounted developer disk image is required on the device, otherwise\n"); | 143 | printf("NOTE: A mounted developer disk image is required on the device, otherwise\n"); |
| 134 | printf("the screenshotr service is not available.\n\n"); | 144 | printf("the screenshotr service is not available.\n\n"); |
| 135 | printf(" -d, --debug\t\tenable communication debugging\n"); | 145 | printf(" -d, --debug\t\tenable communication debugging\n"); |
