libmtp: getfile.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# getfile.c

    00001 #include "common.h"
    00002 #include "pathutils.h"
    00003
    00004 void getfile_function(char *,char *);
    00005 void getfile_command(int, char **);
    00006 void getfile_usage(void);
    00007
    00008 extern LIBMTP_folder_t *folders;
    00009 extern LIBMTP_file_t *files;
    00010 extern LIBMTP_mtpdevice_t *device;
    00011
    00012 void getfile_usage (void)
    00013 {
    00014   fprintf(stderr, "getfile <fileid/trackid> <filename>\n");
    00015 }
    00016
    00017 void
    00018 getfile_function(char * from_path,char * to_path)
    00019 {
    00020   int id = parse_path (from_path,files,folders);
    00021   if (id > 0) {
    00022     printf("Getting %s to %s\n",from_path,to_path);
    00023     if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) {
    00024       printf("\nError getting file from MTP device.\n");
    00025     }
    00026   }
    00027 }
    00028
    00029
    00030 void getfile_command(int argc, char **argv)
    00031 {
    00032   u_int32_t id;
    00033   char *endptr;
    00034   char *file;
    00035
    00036   // We need file ID and filename
    00037   if ( argc != 3 ) {
    00038     getfile_usage();
    00039     return;
    00040   }
    00041
    00042   // Sanity check song ID
    00043   id = strtoul(argv[1], &endptr, 10);
    00044   if ( *endptr != 0 ) {
    00045     fprintf(stderr, "illegal value %s\n", argv[1]);
    00046     return;
    00047   } else if ( ! id ) {
    00048     fprintf(stderr, "bad file/track id %u\n", id);
    00049     return;
    00050  }
    00051
    00052   // Filename, e.g. "foo.mp3"
    00053   file = argv[2];
    00054   printf("Getting file/track %d to local file %s\n", id, file);
    00055
    00056   // This function will also work just as well for tracks.
    00057   if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) {
    00058     printf("\nError getting file from MTP device.\n");
    00059   }
    00060   // Terminate progress bar.
    00061   printf("\n");
    00062
    00063   return;
    00064 }
    00065