From 0928fa78c3a6964686e43b3d26e6cce09721e82c Mon Sep 17 00:00:00 2001 From: Scott Fritzinger Date: Thu, 3 Aug 2000 21:13:36 +0000 Subject: [PATCH] moved to filename-based system. tested (pretty well) and working with barbie, directory, and fujitsu libraries git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@823 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/NOTES | 19 ----- camlibs/barbie/barbie.c | 25 ++++-- camlibs/directory/directory.c | 107 +++++++++++++++++--------- camlibs/fujitsu/fujitsu.c | 139 +++++++++++++++++++++++++--------- camlibs/fujitsu/fujitsu.h | 1 + camlibs/sonydscf1/chotplay.c | 3 +- camlibs/sonydscf1/sonydscf1.c | 3 +- configure.in | 5 +- frontends/command-line/main.c | 90 ++++++++++++++++------ 9 files changed, 268 insertions(+), 124 deletions(-) diff --git a/camlibs/NOTES b/camlibs/NOTES index e344faf56..8e1c10507 100644 --- a/camlibs/NOTES +++ b/camlibs/NOTES @@ -1,22 +1,3 @@ -* template for CameraAbilities: - - strcpy(abilities[]->model, "Camera Model Name"); - abilities[]->serial = ; - abilities[]->usb = ; - abilities[]->parallel = ; - abilities[]->ieee1394 = ; - - abilities[]->serial_baud[0] = 9600; - abilities[]->serial_baud[1] = 0; - - abilities[]->cancel = ; - abilities[]->capture = ; - abilities[]->config = ; - abilities[]->delete_file = ; - abilities[]->file_preview = ; - abilities[]->file_put = ; - abilities[]->lock = ; - * Interfaces should wait to close the configuration dialog until gp_config_set returns. If GP_OK is returned, close the window. If GP_ERROR is returned, it is expected that the camera libraries have already notified diff --git a/camlibs/barbie/barbie.c b/camlibs/barbie/barbie.c index 5ad76ca5f..8b100654f 100644 --- a/camlibs/barbie/barbie.c +++ b/camlibs/barbie/barbie.c @@ -52,6 +52,7 @@ int camera_init(Camera *camera, CameraInit *init) { camera->functions->init = camera_init; camera->functions->exit = camera_exit; camera->functions->folder_list = camera_folder_list; + camera->functions->file_list = camera_file_list; camera->functions->folder_set = camera_folder_set; camera->functions->file_count = camera_file_count; camera->functions->file_get = camera_file_get; @@ -101,20 +102,30 @@ int camera_exit(Camera *camera) { return GP_OK; } -int camera_folder_list (Camera *camera, char *folder_name, CameraFolderList *list) { +int camera_file_list (Camera *camera, char *folder_name, CameraList *list) { int count, x; BarbieStruct *b = (BarbieStruct*)camera->camlib_data; + if (strcmp(folder_name, "/")!=0) + return (GP_ERROR); + count = camera_file_count(camera); /* Populate the filesystem */ - gp_filesystem_populate(b->fs, "mattel%02i.ppm", count); + gp_filesystem_populate(b->fs, "/", "mattel%02i.ppm", count); - for (x=0; xfs); x++) - gp_folder_list_append(list, gp_filesystem_name(b->fs, x), 0); + for (x=0; xfs, folder_name); x++) + gp_list_append(list, gp_filesystem_name(b->fs, folder_name, x), GP_LIST_FILE); - return 0; + return GP_OK; +} + +int camera_folder_list (Camera *camera, char *folder_name, CameraList *list) { + + /* there are never any subfolders */ + + return GP_OK; } int camera_folder_set (Camera *camera, char *folder_name) { @@ -158,7 +169,7 @@ int camera_file_get (Camera *camera, CameraFile *file, char *filename) { strcpy(file->type, "image/ppm"); /* Retrieve the number of the photo on the camera */ - num = gp_filesystem_number(b->fs, filename); + num = gp_filesystem_number(b->fs, "/", filename); file->data = barbie_read_picture(b, num, 0, &size); if (!file->data) @@ -183,7 +194,7 @@ int camera_file_get_preview (Camera *camera, CameraFile *file, char *filename) { strcpy(file->type, "image/ppm"); /* Retrieve the number of the photo on the camera */ - num = gp_filesystem_number(b->fs, filename); + num = gp_filesystem_number(b->fs, "/", filename); file->data = barbie_read_picture(b, num, 1, &size);; if (!file->data) diff --git a/camlibs/directory/directory.c b/camlibs/directory/directory.c index 72eaa6292..2b7c1d867 100644 --- a/camlibs/directory/directory.c +++ b/camlibs/directory/directory.c @@ -15,6 +15,35 @@ #include "directory.h" +char *extension[] = { + "gif", + "tif", + "jpg", + "xpm", + "png", + "pbm", + "pgm", + "jpeg", + "tiff", + NULL +}; + +int is_image (char *filename) { + + char *dot; + int x=0; + + dot = strrchr(filename, '.'); + if (dot) { + while (extension[x]) { + if (strcasecmp(extension[x], dot+1)==0) + return (1); + x++; + } + } + return (0); +} + int camera_id (char *id) { strcpy(id, "directory"); @@ -22,10 +51,6 @@ int camera_id (char *id) { return (GP_OK); } -int camera_debug_set (int onoff) { - - return (GP_OK); -} int camera_abilities (CameraAbilities *abilities, int *count) { @@ -55,6 +80,7 @@ int camera_init (Camera *camera, CameraInit *init) { camera->functions->init = camera_init; camera->functions->exit = camera_exit; camera->functions->folder_list = camera_folder_list; + camera->functions->file_list = camera_file_list; camera->functions->folder_set = camera_folder_set; camera->functions->file_count = camera_file_count; camera->functions->file_get = camera_file_get; @@ -73,8 +99,6 @@ int camera_init (Camera *camera, CameraInit *init) { d->num_images = 0; - d->debug = init->debug; - for (i=0; i<1024; i++) strcpy(d->images[i], ""); @@ -95,7 +119,7 @@ int camera_exit (Camera *camera) { return (GP_OK); } -int camera_folder_list(Camera *camera, char *folder_name, CameraFolderInfo *list) { +int camera_file_list(Camera *camera, char *folder_name, CameraList *list) { DIR *d; struct dirent *de; @@ -108,18 +132,43 @@ int camera_folder_list(Camera *camera, char *folder_name, CameraFolderInfo *list return (GP_ERROR); while (de = readdir(d)) { - if ((strcmp(de->d_name, ".") !=0) && + if ((strcmp(de->d_name, "." )!=0) && (strcmp(de->d_name, "..")!=0)) { sprintf(buf, "%s/%s", folder_name, de->d_name); if (stat(buf, &st)==0) { - if (S_ISDIR(st.st_mode)) { - strcpy(list[count++].name, de->d_name); - } + if ((!S_ISDIR(st.st_mode))&&(is_image(de->d_name))) + gp_list_append(list, de->d_name, GP_LIST_FILE); } } } - return (count); + return (GP_OK); +} + +int camera_folder_list(Camera *camera, char *folder_name, CameraList *list) { + + DIR *d; + struct dirent *de; + struct stat st; + char *ch; + char buf[1024]; + int count=0; + + if ((d = opendir(folder_name))==NULL) + return (GP_ERROR); + + while (de = readdir(d)) { + if ((strcmp(de->d_name, "." )!=0) && + (strcmp(de->d_name, "..")!=0)) { + sprintf(buf, "%s/%s", folder_name, de->d_name); + if (stat(buf, &st)==0) { + if (S_ISDIR(st.st_mode)) + gp_list_append(list, de->d_name, GP_LIST_FOLDER); + } + } + } + + return (GP_OK); } int folder_index(Camera *camera) { @@ -141,23 +190,11 @@ int folder_index(Camera *camera) { stat(fname, &s); /* If it's a file ...*/ if (S_ISREG(s.st_mode)) { - dot = strrchr(de->d_name, '.'); - if (dot) { - if ( - (strcasecmp(dot, ".gif")==0)|| - (strcasecmp(dot, ".tif")==0)|| - (strcasecmp(dot, ".tiff")==0)|| - (strcasecmp(dot, ".jpg")==0)|| - (strcasecmp(dot, ".xpm")==0)|| - (strcasecmp(dot, ".png")==0)|| - (strcasecmp(dot, ".pbm")==0)|| - (strcasecmp(dot, ".pgm")==0)|| - (strcasecmp(dot, ".jpeg")==0)) { + if (is_image(de->d_name)) { strcpy(d->images[d->num_images++], de->d_name); - if (d->debug) + if (camera->debug) printf("directory: found \"%s\"\n", de->d_name); - } } } de = readdir(dir); @@ -183,33 +220,33 @@ int camera_file_count (Camera *camera) { return (d->num_images); } -int camera_file_get (Camera *camera, CameraFile *file, int file_number) { +int camera_file_get (Camera *camera, CameraFile *file, char *filename) { /**********************************/ /* file_number now starts at 0!!! */ /**********************************/ - char filename[1024]; + char buf[1024]; DirectoryStruct *d = (DirectoryStruct*)camera->camlib_data; - sprintf(filename, "%s/%s", d->directory, d->images[file_number]); - if (gp_file_open(file, filename)==GP_ERROR) + sprintf(buf, "%s/%s", d->directory, filename); + if (gp_file_open(file, buf)==GP_ERROR) return (GP_ERROR); return (GP_OK); } -int camera_file_get_preview (Camera *camera, CameraFile *file, int file_number) { +int camera_file_get_preview (Camera *camera, CameraFile *file, char *filename) { /**********************************/ /* file_number now starts at 0!!! */ /**********************************/ - char filename[1024]; + char buf[1024]; DirectoryStruct *d = (DirectoryStruct*)camera->camlib_data; - sprintf(filename, "%s/%s", d->directory, d->images[file_number]); - if (gp_file_open(file, filename)==GP_ERROR) + sprintf(buf, "%s/%s", d->directory, filename); + if (gp_file_open(file, buf)==GP_ERROR) return (GP_ERROR); return (GP_OK); @@ -221,7 +258,7 @@ int camera_file_put (Camera *camera, CameraFile *file) { } -int camera_file_delete (Camera *camera, int file_number) { +int camera_file_delete (Camera *camera, char *filename) { return (GP_ERROR); } diff --git a/camlibs/fujitsu/fujitsu.c b/camlibs/fujitsu/fujitsu.c index 6f0b15db5..1ff9c1ce7 100644 --- a/camlibs/fujitsu/fujitsu.c +++ b/camlibs/fujitsu/fujitsu.c @@ -134,6 +134,7 @@ int camera_init (Camera *camera, CameraInit *init) { camera->functions->init = camera_init; camera->functions->exit = camera_exit; camera->functions->folder_list = camera_folder_list; + camera->functions->file_list = camera_file_list; camera->functions->folder_set = camera_folder_set; camera->functions->file_count = camera_file_count; camera->functions->file_get = camera_file_get; @@ -192,15 +193,18 @@ int camera_init (Camera *camera, CameraInit *init) { if (fujitsu_set_string_register(camera, 84, "\\", 1)==GP_ERROR) fd->folders = 0; else - fd->folders = 1; + fd->folders = 1; if (fd->folders) debug_print(fd, "Camera supports folders"); + else + debug_print(fd, "Camera doesn't support folders. Using CameraFilesystem emu."); + fd->fs = gp_filesystem_new(); + gpio_set_timeout(fd->dev, TIMEOUT); fd->speed = init->port_settings.speed; -if (camera_stop(camera)==GP_ERROR) -return (GP_ERROR); + camera_stop(camera); return (GP_OK); } @@ -253,9 +257,11 @@ int camera_start(Camera *camera) { gp_camera_message(camera, "Can not set the serial port speed"); return (GP_ERROR); } - if (fujitsu_change_folder(camera, fd->folder)) { - gp_camera_message(camera, "Can't change folder"); - return (GP_ERROR); + if (fd->folders) { + if (fujitsu_change_folder(camera, fd->folder)) { + gp_camera_message(camera, "Can't change folder"); + return (GP_ERROR); + } } return (GP_OK); } @@ -290,24 +296,81 @@ int camera_exit (Camera *camera) { return (GP_OK); } -int camera_folder_list(Camera *camera, char *folder_name, CameraFolderInfo *list) { +int camera_file_list(Camera *camera, char *folder_name, CameraList *list) { + + FujitsuData *fd = (FujitsuData*)camera->camlib_data; + int x=0, error=0, count; + char buf[1024]; + +printf("here\n"); + if ((!fd->folders)&&(strcmp("/", folder_name)!=0)) + return (GP_ERROR); +printf("here\n"); + if (camera_start(camera)==GP_ERROR) + return (GP_ERROR); + +printf("here\n"); + if (fd->folders) { + if (fujitsu_change_folder(camera, folder_name)) { + gp_camera_message(camera, "Can't change folder"); + return (GP_ERROR); + } + } + +printf("here\n"); + count = camera_file_count(camera); + + /* Populate the filesystem */ + gp_filesystem_populate(fd->fs, folder_name, "PIC%04i.jpg", count); + + while ((x 0) + /* Filename supported. Use the camera filename */ + gp_list_append(list, buf, GP_LIST_FILE); + else +#endif + /* Filename not supported. Use CameraFileSystem entry */ + gp_list_append(list, gp_filesystem_name(fd->fs, folder_name, x), + GP_LIST_FILE); + x++; + } + + camera_stop(camera); + return GP_OK; +} + +int camera_folder_list(Camera *camera, char *folder_name, CameraList *list) { FujitsuData *fd = (FujitsuData*)camera->camlib_data; int count, i, bsize; - + char buf[1024]; debug_print(fd, "Listing folders"); if (!fd->folders) /* camera doesn't support folders */ - return (0); + return GP_OK; if (camera_start(camera) != GP_OK) /* XXX */ - return 0; + return GP_ERROR; if ((fujitsu_change_folder(camera, folder_name) != GP_OK) || (fujitsu_get_int_register(camera, 83, &count) != GP_OK)) { camera_stop(camera); - return 0; + return GP_ERROR; } if (count) for (i = 0; i < count; i++) { @@ -317,13 +380,17 @@ int camera_folder_list(Camera *camera, char *folder_name, CameraFolderInfo *list if (fujitsu_set_int_register(camera, 83, i+1) != GP_OK) { break; } - bsize = sizeof(list[i].name); - if (fujitsu_get_string_register(camera, 84, NULL, list[i].name, &bsize) != GP_OK) { + bsize = 1024; + if (fujitsu_get_string_register(camera, 84, NULL, buf, &bsize) != GP_OK) { break; + } else { + /* append the folder name on to the folder list */ + gp_list_append(list, buf, GP_LIST_FOLDER); } + } camera_stop(camera); - return (i); + return (GP_OK); } int camera_folder_set(Camera *camera, char *folder_name) { @@ -331,8 +398,15 @@ int camera_folder_set(Camera *camera, char *folder_name) { char buf[4096]; FujitsuData *fd = (FujitsuData*)camera->camlib_data; - if (!fd->folders) - return GP_ERROR; + /* If the camera doesn't support folders and it was passed something + other than "/", return an error! */ + if ((!fd->folders)&&(strcmp("/", folder_name)!=0)) + return (GP_ERROR); + + /* If the camera doesn't support folders and it was passed "/", + then that's OK */ + if ((!fd->folders)&&(strcmp("/", folder_name)==0)) + return (GP_OK); if (folder_name[0] != '/') { strcat(fd->folder, folder_name); @@ -373,15 +447,18 @@ return (GP_ERROR); } int camera_file_get_generic (Camera *camera, CameraFile *file, - int file_number, int thumbnail) { + char *filename, int thumbnail) { char buf[4096]; - int length, regl, regd; + int length, regl, regd, file_number; FujitsuData *fd = (FujitsuData*)camera->camlib_data; if (camera_start(camera)==GP_ERROR) return (GP_ERROR); + /* Get the file number from the CameraFileSystem */ + file_number = gp_filesystem_number(fd->fs, fd->folder, filename); + if (thumbnail) { sprintf(buf, "Getting file preview #%i", file_number); regl = 13; @@ -409,15 +486,7 @@ return (GP_ERROR); strcpy(file->type, "image/jpg"); - /* Get the picture filename */ - if (fujitsu_get_string_register(camera, 79, NULL, file->name, &length)==GP_ERROR) { - gp_camera_message(camera, "Can not get picture filename"); - return (GP_ERROR); - } - - /* In case the register doesn't have the filename, use this one */ - if (length == 0) - sprintf(file->name, "fujitsu%03i.jpg", file_number+1); + strcpy(file->name, filename); /* Get the picture data */ if (fujitsu_get_string_register(camera, regd, file, NULL, NULL)==GP_ERROR) { @@ -431,14 +500,14 @@ return (GP_ERROR); return (GP_OK); } -int camera_file_get (Camera *camera, CameraFile *file, int file_number) { +int camera_file_get (Camera *camera, CameraFile *file, char *filename) { - return (camera_file_get_generic(camera, file, file_number, 0)); + return (camera_file_get_generic(camera, file, filename, 0)); } -int camera_file_get_preview (Camera *camera, CameraFile *file, int file_number) { +int camera_file_get_preview (Camera *camera, CameraFile *file, char *filename) { - return (camera_file_get_generic(camera, file, file_number, 1)); + return (camera_file_get_generic(camera, file, filename, 1)); } int camera_file_put (Camera *camera, CameraFile *file) { @@ -450,16 +519,18 @@ int camera_file_put (Camera *camera, CameraFile *file) { return (GP_ERROR); } -int camera_file_delete (Camera *camera, int file_number) { +int camera_file_delete (Camera *camera, char *filename) { - int ret; + int ret, file_number; char buf[4096]; FujitsuData *fd = (FujitsuData*)camera->camlib_data; if (camera_start(camera)==GP_ERROR) return (GP_ERROR); - sprintf(buf, "Deleting file #%i", file_number); + file_number = gp_filesystem_number(fd->fs, fd->folder, filename); + + sprintf(buf, "Deleting photo #%i", file_number+1); debug_print(fd, buf); ret = fujitsu_delete(camera, file_number+1); diff --git a/camlibs/fujitsu/fujitsu.h b/camlibs/fujitsu/fujitsu.h index fe696a6de..99217b989 100644 --- a/camlibs/fujitsu/fujitsu.h +++ b/camlibs/fujitsu/fujitsu.h @@ -5,6 +5,7 @@ typedef struct { int first_packet; gpio_device* dev; char folder[128]; + CameraFilesystem *fs; } FujitsuData; void debug_print(FujitsuData *fd, char *message); diff --git a/camlibs/sonydscf1/chotplay.c b/camlibs/sonydscf1/chotplay.c index 4d87817dd..3a902f86d 100644 --- a/camlibs/sonydscf1/chotplay.c +++ b/camlibs/sonydscf1/chotplay.c @@ -25,7 +25,6 @@ extern int errno; #include "command.h" #include #include "pmp.h" -#include #define MAX_PICTURE_NUM 200 u_char picture_index[MAX_PICTURE_NUM]; @@ -973,4 +972,4 @@ main(argc, argv) Exit (errflg ? 1 : 0); return(255); } -#endif \ No newline at end of file +#endif diff --git a/camlibs/sonydscf1/sonydscf1.c b/camlibs/sonydscf1/sonydscf1.c index 2b0191669..787b4b1c4 100644 --- a/camlibs/sonydscf1/sonydscf1.c +++ b/camlibs/sonydscf1/sonydscf1.c @@ -185,7 +185,7 @@ int camera_summary (Camera *camera, CameraText *summary) { int camera_manual (Camera *camera, CameraText *manual) { printf("sony dscf1: manual\n"); - strcpy(manual, "Manual Not Available"); + strcpy(manual->text, "Manual Not Available"); return (GP_OK); } @@ -202,4 +202,3 @@ int camera_about (Camera *camera, CameraText *about) { return (GP_OK); } - diff --git a/configure.in b/configure.in index 60f89e3ca..57e301a64 100644 --- a/configure.in +++ b/configure.in @@ -58,7 +58,7 @@ AC_SUBST(CFLAGS) AC_SUBST(LIBS) dnl Find out which drivers to compile -camlibs='barbie canon directory fujitsu konica panasonic digita' +camlibs='barbie canon directory fujitsu konica panasonic digita sonydscf1' AC_SUBST(SUBDIRS_CAMLIBS) for i in $camlibs; do d=`echo $i | tr a-z A-Z` @@ -71,7 +71,7 @@ AC_ARG_WITH(drivers, [ 'all' compiles all drivers; ] [ possible drivers are: ] [ barbie, canon, digita, directory, ] - [ fujitsu, konica, panasonic ], + [ fujitsu, konica, panasonic sonydscf1], drivers="$withval", drivers="all") if test "$drivers" = "all"; then for i in $camlibs; do @@ -108,6 +108,7 @@ camlibs/panasonic/Makefile \ camlibs/konica/Makefile \ camlibs/digita/Makefile \ camlibs/canon/Makefile \ +camlibs/sonydscf1/Makefile \ frontends/Makefile \ frontends/command-line/Makefile \ frontends/libgphoto2_frontend/Makefile \ diff --git a/frontends/command-line/main.c b/frontends/command-line/main.c index c64ca4f81..c61b015c4 100644 --- a/frontends/command-line/main.c +++ b/frontends/command-line/main.c @@ -84,6 +84,7 @@ OPTION_CALLBACK(debug); OPTION_CALLBACK(use_folder); OPTION_CALLBACK(recurse); OPTION_CALLBACK(list_folders); +OPTION_CALLBACK(list_files); OPTION_CALLBACK(num_pictures); OPTION_CALLBACK(get_picture); OPTION_CALLBACK(get_all_pictures); @@ -129,6 +130,7 @@ Option option[] = { {"f", "folder", "folder", "Specify camera folder (default=\"/\")",use_folder,0}, {"R", "recurse", "", "Recursively descend through folders",recurse, 0}, {"l", "list-folders", "", "List folders in folder", list_folders, 0}, +{"L", "list-files", "", "List files in folder", list_files, 0}, {"n", "num-pictures", "", "Display number of pictures", num_pictures, 0}, {"p", "get-picture", "range", "Get pictures given in range", get_picture, 0}, {"P", "get-all-pictures","", "Get all pictures from folder", get_all_pictures,0}, @@ -156,6 +158,7 @@ char glob_port[128]; char glob_model[64]; char glob_folder[128]; int glob_speed; +int glob_num=1; Camera *glob_camera=NULL; CameraAbilities glob_abilities; @@ -393,7 +396,7 @@ typedef int folder_action(char *subfolder); Image numbering is 0-based. Should return GP_OK or GP_ERROR. */ -typedef int image_action(int num); +typedef int image_action(char *filename); /* for_each_subfolder() - call action() for every subfolder in 'folder' and, if @@ -405,8 +408,8 @@ typedef int image_action(int num); int for_each_subfolder(char *folder, folder_action action, int recurse) { - CameraFolderList folderlist; - CameraFolderListEntry *entry; + CameraList folderlist; + CameraListEntry *entry; int count = 0; char prefix[1024], subfolder[1024]; @@ -427,16 +430,13 @@ int for_each_subfolder(char *folder, folder_action action, int recurse) { gp_camera_folder_list(glob_camera, prefix, &folderlist); - for (i = 0; i < gp_folder_list_count(folderlist); i++) { - entry = gp_folder_list_entry(folderlist, i); - /* folder_list now returns a listing of all files/folders in the folder */ - if (entry->is_folder) { - sprintf(subfolder, "%s%s", prefix, entry->name); - if (action(subfolder) == GP_ERROR) - return (GP_ERROR); - if (recurse) - for_each_subfolder(subfolder, action, recurse); - } + for (i = 0; i < gp_list_count(&folderlist); i++) { + entry = gp_list_entry(&folderlist, i); + sprintf(subfolder, "%s%s", prefix, entry->name); + if (action(subfolder) == GP_ERROR) + return (GP_ERROR); + if (recurse) + for_each_subfolder(subfolder, action, recurse); } return (GP_OK); @@ -454,7 +454,9 @@ int for_each_image(char *folder, image_action action, int recurse) { int count = 0; int i; - + CameraList filelist; + CameraListEntry *entry; + if (folder != NULL && 0 < strlen(folder)) if (gp_camera_folder_set(glob_camera, folder) == GP_ERROR) { cli_error_print("Can not find folder \"%s\"", folder); @@ -467,10 +469,14 @@ int for_each_image(char *folder, image_action action, int recurse) { cli_error_print("Could not get number of pictures on camera"); return (GP_ERROR); } - - for (i = 0; i < count; i++) - if (action(i) == GP_ERROR) + + gp_camera_file_list(glob_camera, folder, &filelist); + + for (i = 0; i < gp_list_count(&filelist); i++) { + entry = gp_list_entry(&filelist, i); + if (action(entry->name) == GP_ERROR) return (GP_ERROR); + } if (recurse) { @@ -501,11 +507,43 @@ OPTION_CALLBACK(list_folders) { return (GP_ERROR); if (!glob_quiet) - printf("Subfolders of: %s\n", glob_folder); + printf("Subfolders of %s:\n", glob_folder); return for_each_subfolder(glob_folder, print_folder, glob_recurse); } +OPTION_CALLBACK(list_files) { + + int print_files(char *subfolder) { + CameraList filelist; + CameraListEntry *entry; + int x; + char buf[64]; + + if (!glob_quiet) + printf("Files in %s:\n", subfolder); + + gp_camera_file_list(glob_camera, subfolder, &filelist); + for (x=0; xname); + } + return (GP_OK); + } + + if (set_globals() == GP_ERROR) + return (GP_ERROR); + + print_files(glob_folder); + + if (!glob_recurse) + return (GP_OK); + + return for_each_subfolder(glob_folder, print_files, glob_recurse); +} + + OPTION_CALLBACK(num_pictures) { int count; @@ -630,6 +668,9 @@ int for_each_image_in_range(char *range, image_action action) { char index[MAX_IMAGE_NUMBER]; int i, count = 0, max = 0; + CameraList filelist; + CameraListEntry *entry; + memset(index, 0, MAX_IMAGE_NUMBER); if (parse_range(range, index) == GP_ERROR) { @@ -651,9 +692,12 @@ int for_each_image_in_range(char *range, image_action action) { return (GP_ERROR); } + gp_camera_file_list(glob_camera, glob_folder, &filelist); + for (i = 0; i <= max; i++) if (index[i]) { - if (action(i) == GP_ERROR) + entry = gp_list_entry(&filelist, i); + if (action(entry->name) == GP_ERROR) return (GP_ERROR); } @@ -675,22 +719,22 @@ int save_picture_to_file(char *filename, int thumbnail) { if (thumbnail) { if (gp_camera_file_get_preview(glob_camera, file, filename) == GP_ERROR) { - cli_error_print("Can not get preview #%i.", num+1); + cli_error_print("Can not get preview for %s.", filename); return (GP_ERROR); } } else { if (gp_camera_file_get(glob_camera, file, filename) == GP_ERROR) { - cli_error_print("Can not get picture #%i.", num+1); + cli_error_print("Can not get picture %s", filename); return (GP_ERROR); } } if ((glob_filename_override)&&(strlen(glob_filename)>0)) - sprintf(out_filename, glob_filename, num+1); + sprintf(out_filename, glob_filename, glob_num++); else strcpy(out_filename, filename); if (!glob_quiet) - printf("Saving %s #%i as %s\n", thumbnail ? "preview" : "image", num+1, out_filename); + printf("Saving %s as %s\n", thumbnail ? "preview" : "image", out_filename); if (gp_file_save(file, out_filename) == GP_ERROR) cli_error_print("Can not save %s as %s", thumbnail ? "preview" : "image", out_filename);