OLD | NEW |
1 /** | 1 /** |
2 * \file folders.c | 2 * \file folders.c |
3 * Example program that lists all folders on a device. | 3 * Example program that lists all folders on a device. |
4 * | 4 * |
5 * Copyright (C) 2005-2011 Linus Walleij <triad@df.lth.se> | 5 * Copyright (C) 2005-2011 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 23 matching lines...) Expand all Loading... |
34 for(i=0;i<level;i++) printf(" "); | 34 for(i=0;i<level;i++) printf(" "); |
35 | 35 |
36 printf("%s\n", folderlist->name); | 36 printf("%s\n", folderlist->name); |
37 | 37 |
38 dump_folder_list(folderlist->child, level+1); | 38 dump_folder_list(folderlist->child, level+1); |
39 dump_folder_list(folderlist->sibling, level); | 39 dump_folder_list(folderlist->sibling, level); |
40 } | 40 } |
41 | 41 |
42 int main (int argc, char **argv) | 42 int main (int argc, char **argv) |
43 { | 43 { |
44 LIBMTP_mtpdevice_t *device_list, *device; | 44 LIBMTP_raw_device_t *rawdevices; |
| 45 int numrawdevices; |
| 46 int i; |
45 | 47 |
46 LIBMTP_Init(); | 48 LIBMTP_Init(); |
47 printf("Attempting to connect device(s)\n"); | 49 printf("Attempting to connect device(s)\n"); |
48 | 50 |
49 switch(LIBMTP_Get_Connected_Devices(&device_list)) | 51 switch (LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices)) { |
50 { | |
51 case LIBMTP_ERROR_NO_DEVICE_ATTACHED: | 52 case LIBMTP_ERROR_NO_DEVICE_ATTACHED: |
52 printf("mtp-folders: no devices found\n"); | 53 printf("mtp-folders: no devices found\n"); |
53 return 0; | 54 return 0; |
54 case LIBMTP_ERROR_CONNECTING: | 55 case LIBMTP_ERROR_CONNECTING: |
55 fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n"); | 56 fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n"); |
56 return 1; | 57 return 1; |
57 case LIBMTP_ERROR_MEMORY_ALLOCATION: | 58 case LIBMTP_ERROR_MEMORY_ALLOCATION: |
58 fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n"); | 59 fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n"); |
59 return 1; | 60 return 1; |
60 | 61 |
61 /* Unknown general errors - This should never execute */ | 62 /* Unknown general errors - This should never execute */ |
62 case LIBMTP_ERROR_GENERAL: | 63 case LIBMTP_ERROR_GENERAL: |
63 default: | 64 default: |
64 fprintf(stderr, "mtp-folders: Unknown error, please report " | 65 fprintf(stderr, "mtp-folders: Unknown error, please report " |
65 "this to the libmtp developers\n"); | 66 "this to the libmtp developers\n"); |
66 return 1; | 67 return 1; |
67 | 68 |
68 /* Successfully connected at least one device, so continue */ | 69 /* Successfully connected at least one device, so continue */ |
69 case LIBMTP_ERROR_NONE: | 70 case LIBMTP_ERROR_NONE: |
70 printf("mtp-folders: Successfully connected\n"); | 71 printf("mtp-folders: Successfully connected\n"); |
71 } | 72 } |
72 | 73 |
73 /* iterate through connected MTP devices */ | 74 /* iterate through connected MTP devices */ |
74 for(device = device_list; device != NULL; device = device->next) | 75 for (i = 0; i < numrawdevices; i++) { |
75 { | 76 LIBMTP_mtpdevice_t *device; |
76 LIBMTP_devicestorage_t *storage; | 77 LIBMTP_devicestorage_t *storage; |
77 char *friendlyname; | 78 char *friendlyname; |
78 int ret; | 79 int ret; |
79 | 80 |
| 81 device = LIBMTP_Open_Raw_Device(&rawdevices[i]); |
| 82 if (device == NULL) { |
| 83 fprintf(stderr, "Unable to open raw device %d\n", i); |
| 84 continue; |
| 85 } |
| 86 |
80 /* Echo the friendly name so we know which device we are working with */ | 87 /* Echo the friendly name so we know which device we are working with */ |
81 friendlyname = LIBMTP_Get_Friendlyname(device); | 88 friendlyname = LIBMTP_Get_Friendlyname(device); |
82 if (friendlyname == NULL) { | 89 if (friendlyname == NULL) { |
83 printf("Friendly name: (NULL)\n"); | 90 printf("Friendly name: (NULL)\n"); |
84 } else { | 91 } else { |
85 printf("Friendly name: %s\n", friendlyname); | 92 printf("Friendly name: %s\n", friendlyname); |
86 free(friendlyname); | 93 free(friendlyname); |
87 } | 94 } |
88 | 95 |
89 LIBMTP_Dump_Errorstack(device); | 96 LIBMTP_Dump_Errorstack(device); |
(...skipping 17 matching lines...) Expand all Loading... |
107 | 114 |
108 if (folders == NULL) { | 115 if (folders == NULL) { |
109 fprintf(stdout, "No folders found\n"); | 116 fprintf(stdout, "No folders found\n"); |
110 LIBMTP_Dump_Errorstack(device); | 117 LIBMTP_Dump_Errorstack(device); |
111 LIBMTP_Clear_Errorstack(device); | 118 LIBMTP_Clear_Errorstack(device); |
112 } else { | 119 } else { |
113 dump_folder_list(folders,0); | 120 dump_folder_list(folders,0); |
114 } | 121 } |
115 LIBMTP_destroy_folder_t(folders); | 122 LIBMTP_destroy_folder_t(folders); |
116 } | 123 } |
| 124 LIBMTP_Release_Device(device); |
117 } | 125 } |
118 | 126 |
119 LIBMTP_Release_Device_List(device_list); | 127 free(rawdevices); |
120 printf("OK.\n"); | 128 printf("OK.\n"); |
121 | 129 |
122 return 0; | 130 return 0; |
123 } | 131 } |
OLD | NEW |