| OLD | NEW | 
|---|
| 1 /** | 1 /** | 
| 2  * \file files.c | 2  * \file files.c | 
| 3  * Example program that lists all files on a device. | 3  * Example program that lists all files on a device. | 
| 4  * | 4  * | 
| 5  * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> | 5  * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> | 
| 6  * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> | 6  * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> | 
| 7  * | 7  * | 
| 8  * This library is free software; you can redistribute it and/or | 8  * This library is free software; you can redistribute it and/or | 
| 9  * modify it under the terms of the GNU Lesser General Public | 9  * modify it under the terms of the GNU Lesser General Public | 
| 10  * License as published by the Free Software Foundation; either | 10  * License as published by the Free Software Foundation; either | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 39     printf("   File size %llu (0x%016llX) bytes\n", | 39     printf("   File size %llu (0x%016llX) bytes\n", | 
| 40            (long long unsigned int) file->filesize, | 40            (long long unsigned int) file->filesize, | 
| 41            (long long unsigned int) file->filesize); | 41            (long long unsigned int) file->filesize); | 
| 42 #endif | 42 #endif | 
| 43   } | 43   } | 
| 44   printf("   Parent ID: %u\n", file->parent_id); | 44   printf("   Parent ID: %u\n", file->parent_id); | 
| 45   printf("   Storage ID: 0x%08X\n", file->storage_id); | 45   printf("   Storage ID: 0x%08X\n", file->storage_id); | 
| 46   printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype)); | 46   printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype)); | 
| 47 } | 47 } | 
| 48 | 48 | 
| 49 static void | 49 int main (int argc, char **argv) | 
| 50 dump_files(LIBMTP_mtpdevice_t *device, uint32_t storageid, int leaf) |  | 
| 51 { | 50 { | 
|  | 51   LIBMTP_mtpdevice_t *device_list, *device; | 
| 52   LIBMTP_file_t *files; | 52   LIBMTP_file_t *files; | 
| 53 | 53 | 
| 54   /* Get file listing. */ |  | 
| 55   files = LIBMTP_Get_Files_And_Folders(device, |  | 
| 56                                        storageid, |  | 
| 57                                        leaf); |  | 
| 58   if (files == NULL) { |  | 
| 59     LIBMTP_Dump_Errorstack(device); |  | 
| 60     LIBMTP_Clear_Errorstack(device); |  | 
| 61   } else { |  | 
| 62     LIBMTP_file_t *file, *tmp; |  | 
| 63     file = files; |  | 
| 64     while (file != NULL) { |  | 
| 65       /* Please don't print these */ |  | 
| 66       if (file->filetype == LIBMTP_FILETYPE_FOLDER) { |  | 
| 67         dump_files(device, storageid, file->item_id); |  | 
| 68       } else { |  | 
| 69         dump_fileinfo(file); |  | 
| 70       } |  | 
| 71       tmp = file; |  | 
| 72       file = file->next; |  | 
| 73       LIBMTP_destroy_file_t(tmp); |  | 
| 74     } |  | 
| 75   } |  | 
| 76 } |  | 
| 77 |  | 
| 78 int main(int argc, char **argv) |  | 
| 79 { |  | 
| 80   LIBMTP_raw_device_t *rawdevices; |  | 
| 81   int numrawdevices; |  | 
| 82   LIBMTP_error_number_t err; |  | 
| 83   int i; |  | 
| 84 |  | 
| 85   fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); | 54   fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); | 
| 86 | 55 | 
| 87   LIBMTP_Init(); | 56   LIBMTP_Init(); | 
| 88 | 57 | 
| 89   err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); | 58   switch(LIBMTP_Get_Connected_Devices(&device_list)) | 
| 90   switch(err) |  | 
| 91   { | 59   { | 
| 92   case LIBMTP_ERROR_NO_DEVICE_ATTACHED: | 60   case LIBMTP_ERROR_NO_DEVICE_ATTACHED: | 
| 93     fprintf(stdout, "mtp-files: No Devices have been found\n"); | 61     fprintf(stdout, "mtp-files: No Devices have been found\n"); | 
| 94     return 0; | 62     return 0; | 
| 95   case LIBMTP_ERROR_CONNECTING: | 63   case LIBMTP_ERROR_CONNECTING: | 
| 96     fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n"); | 64     fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n"); | 
| 97     return 1; | 65     return 1; | 
| 98   case LIBMTP_ERROR_MEMORY_ALLOCATION: | 66   case LIBMTP_ERROR_MEMORY_ALLOCATION: | 
| 99     fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n"); | 67     fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n"); | 
| 100     return 1; | 68     return 1; | 
| 101 | 69 | 
| 102   /* Unknown general errors - This should never execute */ | 70   /* Unknown general errors - This should never execute */ | 
| 103   case LIBMTP_ERROR_GENERAL: | 71   case LIBMTP_ERROR_GENERAL: | 
| 104   default: | 72   default: | 
| 105     fprintf(stderr, "mtp-files: Unknown error, please report " | 73     fprintf(stderr, "mtp-files: Unknown error, please report " | 
| 106                     "this to the libmtp developers\n"); | 74                     "this to the libmtp developers\n"); | 
| 107     return 1; | 75   return 1; | 
| 108 | 76 | 
| 109   /* Successfully connected at least one device, so continue */ | 77   /* Successfully connected at least one device, so continue */ | 
| 110   case LIBMTP_ERROR_NONE: | 78   case LIBMTP_ERROR_NONE: | 
| 111     fprintf(stdout, "mtp-files: Successfully connected\n"); | 79     fprintf(stdout, "mtp-files: Successfully connected\n"); | 
| 112     fflush(stdout); | 80     fflush(stdout); | 
| 113     break; |  | 
| 114   } | 81   } | 
| 115 | 82 | 
| 116   /* iterate through connected MTP devices */ | 83   /* iterate through connected MTP devices */ | 
| 117   for (i = 0; i < numrawdevices; i++) { | 84   for(device = device_list; device != NULL; device = device->next) | 
| 118     LIBMTP_mtpdevice_t *device; | 85   { | 
| 119     LIBMTP_devicestorage_t *storage; |  | 
| 120     char *friendlyname; | 86     char *friendlyname; | 
| 121 | 87 | 
| 122     device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]); |  | 
| 123     if (device == NULL) { |  | 
| 124       fprintf(stderr, "Unable to open raw device %d\n", i); |  | 
| 125       continue; |  | 
| 126     } |  | 
| 127 |  | 
| 128     /* Echo the friendly name so we know which device we are working with */ | 88     /* Echo the friendly name so we know which device we are working with */ | 
| 129     friendlyname = LIBMTP_Get_Friendlyname(device); | 89     friendlyname = LIBMTP_Get_Friendlyname(device); | 
| 130     if (friendlyname == NULL) { | 90     if (friendlyname == NULL) { | 
| 131       printf("Listing File Information on Device with name: (NULL)\n"); | 91       printf("Listing File Information on Device with name: (NULL)\n"); | 
| 132     } else { | 92     } else { | 
| 133       printf("Listing File Information on Device with name: %s\n", friendlyname)
     ; | 93       printf("Listing File Information on Device with name: %s\n", friendlyname)
     ; | 
| 134       free(friendlyname); | 94       free(friendlyname); | 
| 135     } | 95     } | 
| 136 | 96 | 
| 137     LIBMTP_Dump_Errorstack(device); | 97 »         /* Get track listing. */ | 
| 138     LIBMTP_Clear_Errorstack(device); | 98 »         files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL); | 
| 139 | 99 »         if (files == NULL) { | 
| 140     /* Loop over storages */ | 100 »           printf("No files.\n"); | 
| 141     for (storage = device->storage; storage != 0; storage = storage->next) { | 101 »           LIBMTP_Dump_Errorstack(device); | 
| 142       dump_files(device, storage->id, 0); | 102 »           LIBMTP_Clear_Errorstack(device); | 
| 143     } | 103 »         } else { | 
| 144     LIBMTP_Release_Device(device); | 104 »           LIBMTP_file_t *file, *tmp; | 
|  | 105 »           file = files; | 
|  | 106 »           while (file != NULL) { | 
|  | 107 »             dump_fileinfo(file); | 
|  | 108 »             tmp = file; | 
|  | 109 »             file = file->next; | 
|  | 110 »             LIBMTP_destroy_file_t(tmp); | 
|  | 111       } | 
|  | 112 »         } | 
| 145   } | 113   } | 
| 146 | 114 | 
| 147   free(rawdevices); | 115   LIBMTP_Release_Device_List(device_list); | 
| 148 |  | 
| 149   printf("OK.\n"); | 116   printf("OK.\n"); | 
| 150   exit (0); | 117   exit (0); | 
| 151 } | 118 } | 
| OLD | NEW | 
|---|