1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Based on sendfile.c from libmtp: http://libmtp.sourceforge.net
11 * Modified by Maurus Cuelenaere and Nicolas Pennequin.
13 * Copyright (C) 2005-2007 Linus Walleij
14 * Copyright (C) 2006 Chris A. Debenham
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ****************************************************************************/
26 #define _LARGEFILE_SOURCE
27 #define _LARGEFILE64_SOURCE
32 #include <sys/types.h>
37 LIBMTP_mtpdevice_t
*device
;
39 static int progress(uint64_t const sent
, uint64_t const total
,
40 void const *const data
)
42 int percent
= (sent
* 100) / total
;
44 printf("Progress: %I64u of %I64u (%d%%)\r", sent
, total
, percent
);
46 printf("Progress: %"PRIu64
" of %"PRIu64
" (%d%%)\r", sent
, total
, percent
);
54 fprintf(stderr
, "usage: sendfirm <local filename>\n");
57 int sendfile_function(char *from_path
)
59 printf("Sending %s\n", from_path
);
61 #ifdef __USE_LARGEFILE64
66 LIBMTP_file_t
*genfile
;
69 #ifdef __USE_LARGEFILE64
70 if (stat64(from_path
, &sb
) == -1)
73 if (stat(from_path
, &sb
) == -1)
76 fprintf(stderr
, "%s: ", from_path
);
81 #ifdef __USE_LARGEFILE64
82 filesize
= sb
.st_size
;
84 filesize
= (uint64_t) sb
.st_size
;
87 genfile
= LIBMTP_new_file_t();
88 genfile
->filesize
= filesize
;
89 genfile
->filename
= strdup("nk.bin");
90 genfile
->filetype
= LIBMTP_FILETYPE_FIRMWARE
;
92 printf("Sending file...\n");
95 ret
= LIBMTP_Send_File_From_File(device
, from_path
, genfile
, progress
,
98 ret
= LIBMTP_Send_File_From_File(device
, from_path
, genfile
, progress
,
105 printf("Error sending file.\n");
106 LIBMTP_Dump_Errorstack(device
);
107 LIBMTP_Clear_Errorstack(device
);
111 printf("New file ID: %d\n", genfile
->item_id
);
114 LIBMTP_destroy_file_t(genfile
);
119 int main(int argc
, char **argv
)
129 fprintf(stdout
, "libmtp version: " LIBMTP_VERSION_STRING
"\n\n");
131 device
= LIBMTP_Get_First_Device();
134 printf("No devices.\n");
138 sendfile_function(argv
[1]);
140 LIBMTP_Release_Device(device
);