blob: 8979dba19aa2b8243017f6ea1fa883e29599f8cb [file] [log] [blame]
Linus Walleijdcde6082006-02-17 16:16:34 +00001#include "common.h"
cjdebenh4a99f502006-11-09 22:03:05 +00002#include "pathutils.h"
Linus Walleijdcde6082006-02-17 16:16:34 +00003
cjdebenhc80f9b42006-11-09 22:29:26 +00004void getfile_function(char *,char *);
5void getfile_command(int, char **);
6void getfile_usage(void);
Linus Walleijdcde6082006-02-17 16:16:34 +00007
cjdebenh4a99f502006-11-09 22:03:05 +00008extern LIBMTP_folder_t *folders;
9extern LIBMTP_file_t *files;
10extern LIBMTP_mtpdevice_t *device;
11
cjdebenhc80f9b42006-11-09 22:29:26 +000012void getfile_usage (void)
Linus Walleijdcde6082006-02-17 16:16:34 +000013{
Linus Walleijf6bc1782006-03-24 15:12:47 +000014 fprintf(stderr, "getfile <fileid/trackid> <filename>\n");
Linus Walleijdcde6082006-02-17 16:16:34 +000015}
16
cjdebenh4a99f502006-11-09 22:03:05 +000017void
cjdebenhc80f9b42006-11-09 22:29:26 +000018getfile_function(char * from_path,char * to_path)
Linus Walleijdcde6082006-02-17 16:16:34 +000019{
cjdebenh4a99f502006-11-09 22:03:05 +000020 int id = parse_path (from_path,files,folders);
21 if (id > 0) {
22 printf("Getting %s to %s\n",from_path,to_path);
23 if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) {
24 printf("\nError getting file from MTP device.\n");
Linus Walleij070e9b42007-01-22 08:49:28 +000025 LIBMTP_Dump_Errorstack(device);
26 LIBMTP_Clear_Errorstack(device);
cjdebenh4a99f502006-11-09 22:03:05 +000027 }
28 }
29}
30
31
cjdebenhc80f9b42006-11-09 22:29:26 +000032void getfile_command(int argc, char **argv)
cjdebenh4a99f502006-11-09 22:03:05 +000033{
Linus Walleijdcde6082006-02-17 16:16:34 +000034 u_int32_t id;
35 char *endptr;
36 char *file;
37
Linus Walleijf6bc1782006-03-24 15:12:47 +000038 // We need file ID and filename
Linus Walleij0cd85432006-02-20 14:37:50 +000039 if ( argc != 3 ) {
cjdebenh4a99f502006-11-09 22:03:05 +000040 getfile_usage();
41 return;
Linus Walleijdcde6082006-02-17 16:16:34 +000042 }
43
44 // Sanity check song ID
Linus Walleij0cd85432006-02-20 14:37:50 +000045 id = strtoul(argv[1], &endptr, 10);
Linus Walleijdcde6082006-02-17 16:16:34 +000046 if ( *endptr != 0 ) {
Linus Walleij0cd85432006-02-20 14:37:50 +000047 fprintf(stderr, "illegal value %s\n", argv[1]);
cjdebenh4a99f502006-11-09 22:03:05 +000048 return;
Linus Walleijdcde6082006-02-17 16:16:34 +000049 } else if ( ! id ) {
Linus Walleijf6bc1782006-03-24 15:12:47 +000050 fprintf(stderr, "bad file/track id %u\n", id);
cjdebenh4a99f502006-11-09 22:03:05 +000051 return;
Linus Walleij0cd85432006-02-20 14:37:50 +000052 }
Linus Walleijdcde6082006-02-17 16:16:34 +000053
54 // Filename, e.g. "foo.mp3"
Linus Walleij0cd85432006-02-20 14:37:50 +000055 file = argv[2];
Linus Walleijf6bc1782006-03-24 15:12:47 +000056 printf("Getting file/track %d to local file %s\n", id, file);
Linus Walleijdcde6082006-02-17 16:16:34 +000057
Linus Walleijf6bc1782006-03-24 15:12:47 +000058 // This function will also work just as well for tracks.
59 if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) {
Linus Walleijee73ef22006-08-27 19:56:00 +000060 printf("\nError getting file from MTP device.\n");
Linus Walleijdcde6082006-02-17 16:16:34 +000061 }
Linus Walleijee73ef22006-08-27 19:56:00 +000062 // Terminate progress bar.
63 printf("\n");
Linus Walleijdcde6082006-02-17 16:16:34 +000064
cjdebenh4a99f502006-11-09 22:03:05 +000065 return;
Linus Walleijdcde6082006-02-17 16:16:34 +000066}
67