From fb4b91d7916e2b63b323fe98e1b1449d077ab469 Mon Sep 17 00:00:00 2001 From: Todd Wright Date: Mon, 10 Mar 2014 16:08:31 -0400 Subject: idevicescreenshot: Allow user-specified output filename Signed-off-by: Martin Szulecki --- tools/idevicescreenshot.c | 20 +++++++++++++++----- 1 file 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) int result = -1; int i; const char *udid = NULL; + char *filename = NULL; /* parse cmdline args */ for (i = 1; i < argc; i++) { @@ -60,6 +61,10 @@ int main(int argc, char **argv) print_usage(argc, argv); return 0; } + else if (argv[i][0] != '-' && !filename) { + filename = strdup(argv[i]); + continue; + } else { print_usage(argc, argv); return 0; @@ -88,10 +93,12 @@ int main(int argc, char **argv) printf("Could not connect to screenshotr!\n"); } else { char *imgdata = NULL; - char filename[36]; uint64_t imgsize = 0; - time_t now = time(NULL); - strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S.tiff", gmtime(&now)); + if (!filename) { + time_t now = time(NULL); + filename = (char*)malloc(36); + strftime(filename, 36, "screenshot-%Y-%m-%d-%H-%M-%S.tiff", gmtime(&now)); + } if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) { FILE *f = fopen(filename, "wb"); if (f) { @@ -118,6 +125,7 @@ int main(int argc, char **argv) lockdownd_service_descriptor_free(service); idevice_free(device); + free(filename); return result; } @@ -127,9 +135,11 @@ void print_usage(int argc, char **argv) char *name = NULL; name = strrchr(argv[0], '/'); - printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); + printf("Usage: %s [OPTIONS] [FILE]\n", (name ? name + 1: argv[0])); printf("Gets a screenshot from a device.\n"); - printf("The screenshot is saved as a TIFF image in the current directory.\n"); + printf("The screenshot is saved as a TIFF image with the given FILE name,\n"); + printf("where the default name is \"screenshot-DATE.tiff\", e.g.:\n"); + printf(" ./screenshot-2013-12-31-23-59-59.tiff\n\n"); printf("NOTE: A mounted developer disk image is required on the device, otherwise\n"); printf("the screenshotr service is not available.\n\n"); printf(" -d, --debug\t\tenable communication debugging\n"); -- cgit v1.1-32-gdbae