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>
36 LIBMTP_mtpdevice_t
*device
;
38 static int progress(u_int64_t
const sent
, u_int64_t
const total
,
39 void const *const data
)
41 int percent
= (sent
* 100) / total
;
43 printf("Progress: %I64u of %I64u (%d%%)\r", sent
, total
, percent
);
45 printf("Progress: %llu of %llu (%d%%)\r", sent
, total
, percent
);
53 fprintf(stderr
, "usage: sendfirm <local filename>\n");
56 int sendfile_function(char *from_path
)
58 printf("Sending %s\n", from_path
);
60 #ifdef __USE_LARGEFILE64
65 LIBMTP_file_t
*genfile
;
67 uint32_t parent_id
= 0;
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");
93 ret
= LIBMTP_Send_File_From_File(device
, from_path
, genfile
, progress
,
98 printf("Error sending file.\n");
99 LIBMTP_Dump_Errorstack(device
);
100 LIBMTP_Clear_Errorstack(device
);
104 printf("New file ID: %d\n", genfile
->item_id
);
107 LIBMTP_destroy_file_t(genfile
);
112 int main(int argc
, char **argv
)
122 fprintf(stdout
, "libmtp version: " LIBMTP_VERSION_STRING
"\n\n");
124 device
= LIBMTP_Get_First_Device();
127 printf("No devices.\n");
131 sendfile_function(argv
[1]);
133 LIBMTP_Release_Device(device
);