files.c

00001 
00023 #include "common.h"
00024 
00025 static void dump_fileinfo(LIBMTP_file_t *file)
00026 {
00027   printf("File ID: %u\n", file->item_id);
00028   if (file->filename != NULL)
00029     printf("   Filename: %s\n", file->filename);
00030 
00031   // This is sort of special...
00032   if (file->filesize == (uint32_t) -1) {
00033     printf("   None. (abstract file, size = -1)\n");
00034   } else {
00035     printf("   File size %llu (0x%08llX) bytes\n", file->filesize, file->filesize);
00036   }
00037   printf("   Parent ID: %u\n", file->parent_id);
00038   printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype));
00039 }
00040 
00041 int main (int argc, char **argv)
00042 {
00043   LIBMTP_mtpdevice_t *device_list, *iter;
00044   LIBMTP_file_t *files;
00045 
00046   LIBMTP_Init();
00047 
00048   switch(LIBMTP_Get_Connected_Devices(&device_list))
00049   {
00050   case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
00051     fprintf(stdout, "mtp-files: No Devices have been found\n");
00052     return 0;
00053   case LIBMTP_ERROR_CONNECTING:
00054     fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n");
00055     return 1;
00056   case LIBMTP_ERROR_MEMORY_ALLOCATION:
00057     fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n");
00058     return 1;
00059  
00060   /* Unknown general errors - This should never execute */
00061   case LIBMTP_ERROR_GENERAL:
00062   default:
00063     fprintf(stderr, "mtp-files: Unknown error, please report "
00064                     "this to the libmtp developers\n");
00065   return 1;
00066 
00067   /* Successfully connected at least one device, so continue */
00068   case LIBMTP_ERROR_NONE:
00069     fprintf(stdout, "mtp-files: Successfully connected\n");
00070     fflush(stdout);
00071   }
00072   
00073   /* iterate through connected MTP devices */
00074   for(iter = device_list; iter != NULL; iter = iter->next)
00075   {
00076         
00077     char *friendlyname;
00078     
00079     /* Echo the friendly name so we know which device we are working with */
00080     friendlyname = LIBMTP_Get_Friendlyname(iter);
00081     if (friendlyname == NULL) {
00082       printf("Listing File Information on Device with name: (NULL)\n");
00083     } else {
00084       printf("Listing File Information on Device with name: %s\n", friendlyname);
00085       free(friendlyname);
00086     }
00087   
00088           /* Get track listing. */
00089           files = LIBMTP_Get_Filelisting_With_Callback(iter, NULL, NULL);
00090           if (files == NULL) {
00091             printf("No files.\n");
00092             LIBMTP_Dump_Errorstack(iter);
00093             LIBMTP_Clear_Errorstack(iter);
00094           } else {
00095             LIBMTP_file_t *file, *tmp;
00096             file = files;
00097             while (file != NULL) {
00098               dump_fileinfo(file);
00099               tmp = file;
00100               file = file->next;
00101               LIBMTP_destroy_file_t(tmp);
00102       }
00103           }
00104   }
00105     
00106   LIBMTP_Release_Device_List(device_list);
00107   printf("OK.\n");
00108   exit (0);
00109 }
00110 

Generated on Fri Mar 30 18:11:08 2007 for libmtp by  doxygen 1.5.1