Advertising
- sendfirm.c
- Thursday, November 22nd, 2007 at 10:12:57am MST
- /**
- * \file sendfile.c
- * Example program to send an arbitrary file to a device.
- *
- * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
- * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
- #define _LARGEFILE_SOURCE
- #define _LARGEFILE64_SOURCE
- #include <string.h>
- #include <libgen.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include "common.h"
- #include "libmtp.h"
- LIBMTP_folder_t *folders;
- LIBMTP_file_t *files;
- LIBMTP_mtpdevice_t *device;
- int sendfile_function(char *);
- void sendfile_command(int, char **);
- void sendfile_usage(void);
- static int progress (u_int64_t const sent, u_int64_t const total, void const * const data)
- {
- int percent = (sent*100)/total;
- #ifdef __WIN32__
- #else
- #endif
- fflush(stdout);
- return 0;
- }
- void sendfile_usage(void)
- {
- fprintf(stderr, "usage: upgrade <local filename>\n");
- }
- int sendfile_function(char * from_path)
- {
- char *filename;
- uint64_t filesize;
- #ifdef __USE_LARGEFILE64
- struct stat64 sb;
- #else
- struct stat sb;
- #endif
- LIBMTP_file_t *genfile;
- int ret;
- uint32_t parent_id = 0;
- #ifdef __USE_LARGEFILE64
- if ( stat64(from_path, &sb) == -1 ) {
- #else
- if ( stat(from_path, &sb) == -1 ) {
- #endif
- fprintf(stderr, "%s: ", from_path);
- perror("stat");
- exit(1);
- }
- #ifdef __USE_LARGEFILE64
- filesize = sb.st_size;
- #else
- filesize = (uint64_t) sb.st_size;
- #endif
- filename = basename(from_path);
- genfile = LIBMTP_new_file_t();
- genfile->filesize = filesize;
- genfile->filename = strdup("nk.bin");
- genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
- ret = LIBMTP_Send_File_From_File(device, from_path, genfile, progress, NULL, parent_id);
- if (ret != 0) {
- LIBMTP_Dump_Errorstack(device);
- LIBMTP_Clear_Errorstack(device);
- } else {
- }
- LIBMTP_destroy_file_t(genfile);
- return 0;
- }
- int main (int argc, char **argv)
- {
- if ( argc < 2 ) {
- sendfile_usage();
- return 1;
- }
- /*
- * Check environment variables $LANG and $LC_CTYPE
- * to see if we want to support UTF-8 unicode
- */
- char * lang = getenv("LANG");
- if (lang != NULL) {
- if (strlen(lang) > 5) {
- char *langsuff = &lang[strlen(lang)-5];
- if (strcmp(langsuff, "UTF-8")) {
- }
- }
- }
- LIBMTP_Init();
- fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
- device = LIBMTP_Get_First_Device();
- if (device == NULL) {
- return 0;
- }
- files = LIBMTP_Get_Filelisting_With_Callback (device, NULL, NULL);
- folders = LIBMTP_Get_Folder_List (device);
- sendfile_function(argv[1]);
- LIBMTP_Release_Device(device);
- exit (0);
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.