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
00032 if (file->filesize == (uint32_t) -1) {
00033 printf(" None. (abstract file, size = -1)\n");
00034 } else {
00035 #ifdef __WIN32__
00036 printf(" File size %llu (0x%08I64X) bytes\n", file->filesize, file->filesize);
00037 #else
00038 printf(" File size %llu (0x%08llX) bytes\n", file->filesize, file->filesize);
00039 #endif
00040 }
00041 printf(" Parent ID: %u\n", file->parent_id);
00042 printf(" Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype));
00043 }
00044
00045 int main (int argc, char **argv)
00046 {
00047 LIBMTP_mtpdevice_t *device_list, *iter;
00048 LIBMTP_file_t *files;
00049
00050 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
00051
00052 LIBMTP_Init();
00053
00054 switch(LIBMTP_Get_Connected_Devices(&device_list))
00055 {
00056 case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
00057 fprintf(stdout, "mtp-files: No Devices have been found\n");
00058 return 0;
00059 case LIBMTP_ERROR_CONNECTING:
00060 fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n");
00061 return 1;
00062 case LIBMTP_ERROR_MEMORY_ALLOCATION:
00063 fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n");
00064 return 1;
00065
00066
00067 case LIBMTP_ERROR_GENERAL:
00068 default:
00069 fprintf(stderr, "mtp-files: Unknown error, please report "
00070 "this to the libmtp developers\n");
00071 return 1;
00072
00073
00074 case LIBMTP_ERROR_NONE:
00075 fprintf(stdout, "mtp-files: Successfully connected\n");
00076 fflush(stdout);
00077 }
00078
00079
00080 for(iter = device_list; iter != NULL; iter = iter->next)
00081 {
00082
00083 char *friendlyname;
00084
00085
00086 friendlyname = LIBMTP_Get_Friendlyname(iter);
00087 if (friendlyname == NULL) {
00088 printf("Listing File Information on Device with name: (NULL)\n");
00089 } else {
00090 printf("Listing File Information on Device with name: %s\n", friendlyname);
00091 free(friendlyname);
00092 }
00093
00094
00095 files = LIBMTP_Get_Filelisting_With_Callback(iter, NULL, NULL);
00096 if (files == NULL) {
00097 printf("No files.\n");
00098 LIBMTP_Dump_Errorstack(iter);
00099 LIBMTP_Clear_Errorstack(iter);
00100 } else {
00101 LIBMTP_file_t *file, *tmp;
00102 file = files;
00103 while (file != NULL) {
00104 dump_fileinfo(file);
00105 tmp = file;
00106 file = file->next;
00107 LIBMTP_destroy_file_t(tmp);
00108 }
00109 }
00110 }
00111
00112 LIBMTP_Release_Device_List(device_list);
00113 printf("OK.\n");
00114 exit (0);
00115 }
00116