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