| OLD | NEW |
| (Empty) |
| 1 Index: src/libmtp.c | |
| 2 =================================================================== | |
| 3 --- src/libmtp.c (revision 167447) | |
| 4 +++ src/libmtp.c (working copy) | |
| 5 @@ -4972,6 +4972,56 @@ | |
| 6 } | |
| 7 | |
| 8 /** | |
| 9 + * This copies a chunk of a file off the device to memory. | |
| 10 + * @param device a pointer to the device to get the track from. | |
| 11 + * @param id the file ID of the file to retrieve. | |
| 12 + * @param offset the offset of the file to read from. | |
| 13 + * @param count the amount of data to read. | |
| 14 + * @param data a pointer to the data from the device. Must be | |
| 15 + * <coded>free()</code>:ed by the caller after use. | |
| 16 + * @param datalen the amount of data written to <code>data</code>. | |
| 17 + * @return 0 if the transfer was successful, any other value means | |
| 18 + * failure. | |
| 19 + */ | |
| 20 +int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t* device, uint32_t id, | |
| 21 + uint32_t offset, uint32_t count, | |
| 22 + unsigned char** data, uint32_t* datalen) | |
| 23 +{ | |
| 24 + uint16_t ret; | |
| 25 + PTPParams *params = (PTPParams *) device->params; | |
| 26 + PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; | |
| 27 + PTPObject *ob; | |
| 28 + | |
| 29 + if (!data || !datalen) { | |
| 30 + add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chun
k(): Invalid parameter."); | |
| 31 + return -1; | |
| 32 + } | |
| 33 + | |
| 34 + ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob); | |
| 35 + if (ret != PTP_RC_OK) { | |
| 36 + add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chun
k(): Could not get object info."); | |
| 37 + return -1; | |
| 38 + } | |
| 39 + if (ob->oi.ObjectFormat == PTP_OFC_Association) { | |
| 40 + add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chun
k(): Bad object format."); | |
| 41 + return -1; | |
| 42 + } | |
| 43 + | |
| 44 + ret = ptp_getpartialobject(params, id, offset, count, data, datalen); | |
| 45 + | |
| 46 + if (ret == PTP_ERROR_CANCEL) { | |
| 47 + add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Get_File_Ch
unk(): Cancelled transfer."); | |
| 48 + return -1; | |
| 49 + } | |
| 50 + if (ret != PTP_RC_OK) { | |
| 51 + add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_File_Chunk(): Could no
t get file from device."); | |
| 52 + return -1; | |
| 53 + } | |
| 54 + | |
| 55 + return 0; | |
| 56 +} | |
| 57 + | |
| 58 +/** | |
| 59 * This is a manual conversion from MTPDataGetFunc to PTPDataGetFunc | |
| 60 * to isolate the internal type. | |
| 61 */ | |
| 62 Index: src/libmtp.h | |
| 63 =================================================================== | |
| 64 --- src/libmtp.h (revision 167447) | |
| 65 +++ src/libmtp.h (working copy) | |
| 66 @@ -876,6 +876,8 @@ | |
| 67 uint32_t const, | |
| 68 uint32_t const); | |
| 69 LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); | |
| 70 +int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t*, uint32_t, uint32_t, uint32_t, | |
| 71 + unsigned char**, uint32_t*); | |
| 72 int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, | |
| 73 LIBMTP_progressfunc_t const, void const * const); | |
| 74 int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, | |
| 75 Index: src/libmtp.h.in | |
| 76 =================================================================== | |
| 77 --- src/libmtp.h.in (revision 167447) | |
| 78 +++ src/libmtp.h.in (working copy) | |
| 79 @@ -876,6 +876,8 @@ | |
| 80 uint32_t const, | |
| 81 uint32_t const); | |
| 82 LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const); | |
| 83 +int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t*, uint32_t, uint32_t, uint32_t, | |
| 84 + unsigned char**, uint32_t*); | |
| 85 int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const, | |
| 86 LIBMTP_progressfunc_t const, void const * const); | |
| 87 int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, | |
| 88 Index: src/libmtp.sym | |
| 89 =================================================================== | |
| 90 --- src/libmtp.sym (revision 167447) | |
| 91 +++ src/libmtp.sym (working copy) | |
| 92 @@ -49,6 +49,7 @@ | |
| 93 LIBMTP_Get_Filelisting_With_Callback | |
| 94 LIBMTP_Get_Files_And_Folders | |
| 95 LIBMTP_Get_Filemetadata | |
| 96 +LIBMTP_Get_File_Chunk | |
| 97 LIBMTP_Get_File_To_File | |
| 98 LIBMTP_Get_File_To_File_Descriptor | |
| 99 LIBMTP_Get_File_To_Handler | |
| OLD | NEW |