int main () { LIBMTP_mtpdevice_t *device_list, *iter; LIBMTP_Init(); fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); switch(LIBMTP_Get_Connected_Devices(&device_list)) { case LIBMTP_ERROR_NO_DEVICE_ATTACHED: fprintf(stdout, "mtp-albums: No Devices have been found\n"); return 0; case LIBMTP_ERROR_CONNECTING: fprintf(stderr, "mtp-albums: There has been an error connecting. Exit\n"); return 1; case LIBMTP_ERROR_MEMORY_ALLOCATION: fprintf(stderr, "mtp-albums: Memory Allocation Error. Exit\n"); return 1; case LIBMTP_ERROR_GENERAL: default: fprintf(stderr, "mtp-albums: Unknown error, please report " "this to the libmtp developers\n"); return 1; case LIBMTP_ERROR_NONE: fprintf(stdout, "mtp-albums: Successfully connected\n"); fflush(stdout); } for(iter = device_list; iter != NULL; iter = iter->next) { char *friendlyname; LIBMTP_album_t *album_list, *album, *tmp; friendlyname = LIBMTP_Get_Friendlyname(iter); if (friendlyname == NULL) { printf("Retrieving Albums on Device with name: (NULL)\n"); } else { printf("Retrieving Albums on Device with name: %s\n", friendlyname); free(friendlyname); } album_list = LIBMTP_Get_Album_List(iter); album = album_list; while(album != NULL) { dump_albuminfo(album); tmp = album; album = album->next; LIBMTP_destroy_album_t(tmp); } } LIBMTP_Release_Device_List(device_list); printf("OK.\n"); return 0; }
int main (int argc, char **argv) { LIBMTP_mtpdevice_t *device_list, *iter; LIBMTP_file_t *files; fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); LIBMTP_Init(); switch(LIBMTP_Get_Connected_Devices(&device_list)) { case LIBMTP_ERROR_NO_DEVICE_ATTACHED: fprintf(stdout, "mtp-files: No Devices have been found\n"); return 0; case LIBMTP_ERROR_CONNECTING: fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n"); return 1; case LIBMTP_ERROR_MEMORY_ALLOCATION: fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n"); return 1; /* Unknown general errors - This should never execute */ case LIBMTP_ERROR_GENERAL: default: fprintf(stderr, "mtp-files: Unknown error, please report " "this to the libmtp developers\n"); return 1; /* Successfully connected at least one device, so continue */ case LIBMTP_ERROR_NONE: fprintf(stdout, "mtp-files: Successfully connected\n"); fflush(stdout); } /* iterate through connected MTP devices */ for(iter = device_list; iter != NULL; iter = iter->next) { char *friendlyname; /* Echo the friendly name so we know which device we are working with */ friendlyname = LIBMTP_Get_Friendlyname(iter); if (friendlyname == NULL) { printf("Listing File Information on Device with name: (NULL)\n"); } else { printf("Listing File Information on Device with name: %s\n", friendlyname); free(friendlyname); } /* Get track listing. */ files = LIBMTP_Get_Filelisting_With_Callback(iter, NULL, NULL); if (files == NULL) { printf("No files.\n"); LIBMTP_Dump_Errorstack(iter); LIBMTP_Clear_Errorstack(iter); } else { LIBMTP_file_t *file, *tmp; file = files; while (file != NULL) { dump_fileinfo(file); tmp = file; file = file->next; LIBMTP_destroy_file_t(tmp); } } } LIBMTP_Release_Device_List(device_list); printf("OK.\n"); exit (0); }