blob: 8c929d206932da61348c4f7cdb76c9763f4826ac [file] [log] [blame]
Linus Walleij543badf2007-02-05 19:07:38 +00001/**
2 * \file newfolder.c
3 * Example program to create a folder on the device.
4 *
5 * Copyright (C) 2006-2007 Linus Walleij <triad@df.lth.se>
6 * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
Linus Walleij9c6ca022006-04-21 10:24:15 +000023#include "common.h"
Linus Walleij934cd7f2006-12-06 20:21:43 +000024#include "pathutils.h"
cjdebenh4a99f502006-11-09 22:03:05 +000025#include <libgen.h>
Linus Walleij9c6ca022006-04-21 10:24:15 +000026
cjdebenhc80f9b42006-11-09 22:29:26 +000027void newfolder_function(char *);
28void newfolder_command(int,char **);
cjdebenh4a99f502006-11-09 22:03:05 +000029
30extern LIBMTP_folder_t *folders;
31extern LIBMTP_file_t *files;
32extern LIBMTP_mtpdevice_t *device;
33
cjdebenhc80f9b42006-11-09 22:29:26 +000034void newfolder_command (int argc, char **argv)
Linus Walleij9c6ca022006-04-21 10:24:15 +000035{
Linus Walleijc86afbd2006-05-04 19:05:24 +000036 uint32_t newid;
Linus Walleij9c6ca022006-04-21 10:24:15 +000037
38 if(argc != 3) {
39 printf("Usage: newfolder name id\n");
Linus Walleijc86afbd2006-05-04 19:05:24 +000040 printf("(id = parent folder or 0 to create the new folder in the root dir)\n");
cjdebenh4a99f502006-11-09 22:03:05 +000041 return;
Linus Walleij9c6ca022006-04-21 10:24:15 +000042 }
43
Linus Walleijc86afbd2006-05-04 19:05:24 +000044 newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]));
45 if (newid == 0) {
46 printf("Folder creation failed.\n");
47 } else {
48 printf("New folder created with ID: %d\n", newid);
49 }
cjdebenh4a99f502006-11-09 22:03:05 +000050}
Linus Walleij9c6ca022006-04-21 10:24:15 +000051
cjdebenh4a99f502006-11-09 22:03:05 +000052void
cjdebenhc80f9b42006-11-09 22:29:26 +000053newfolder_function(char * path)
cjdebenh4a99f502006-11-09 22:03:05 +000054{
55 printf("Creating new folder %s\n",path);
56 char * parent = dirname(path);
57 char * folder = basename(path);
58 int id = parse_path (parent,files,folders);
59 int newid = LIBMTP_Create_Folder(device, folder, id);
60 if (newid == 0) {
61 printf("Folder creation failed.\n");
Linus Walleij070e9b42007-01-22 08:49:28 +000062 LIBMTP_Dump_Errorstack(device);
63 LIBMTP_Clear_Errorstack(device);
cjdebenh4a99f502006-11-09 22:03:05 +000064 } else {
65 printf("New folder created with ID: %d\n", newid);
66 }
Linus Walleij9c6ca022006-04-21 10:24:15 +000067}
68