blob: 70ea68411d104d625dc82c125dce889893e183ca [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 *
Linus Walleij2242b022009-01-02 01:44:00 +00005 * Copyright (C) 2006-2009 Linus Walleij <triad@df.lth.se>
Linus Walleij543badf2007-02-05 19:07:38 +00006 * 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 Walleij2eaaff02009-01-15 21:30:36 +000023#include <stdlib.h>
cjdebenh4a99f502006-11-09 22:03:05 +000024#include <libgen.h>
Linus Walleij9c6ca022006-04-21 10:24:15 +000025
Linus Walleij843210f2010-10-17 22:40:45 +000026#include "common.h"
27#include "pathutils.h"
28#include "connect.h"
cjdebenh4a99f502006-11-09 22:03:05 +000029
30extern LIBMTP_folder_t *folders;
31extern LIBMTP_file_t *files;
32extern LIBMTP_mtpdevice_t *device;
33
Linus Walleij843210f2010-10-17 22:40:45 +000034int 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 Walleij843210f2010-10-17 22:40:45 +000037
Linus Walleij2242b022009-01-02 01:44:00 +000038 if(argc != 4) {
Linus Walleijea68f1f2008-06-22 21:54:44 +000039 printf("Usage: newfolder name <parent> <storage>\n");
40 printf(" parent = parent folder or 0 to create the new folder in the root dir\n");
41 printf(" storage = storage id or 0 to create the new folder on the primary storage\n");
Linus Walleij843210f2010-10-17 22:40:45 +000042 return 0;
Linus Walleij9c6ca022006-04-21 10:24:15 +000043 }
Linus Walleij843210f2010-10-17 22:40:45 +000044
Linus Walleijea68f1f2008-06-22 21:54:44 +000045 newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3]));
Linus Walleijc86afbd2006-05-04 19:05:24 +000046 if (newid == 0) {
47 printf("Folder creation failed.\n");
Linus Walleij843210f2010-10-17 22:40:45 +000048 return 1;
Linus Walleijc86afbd2006-05-04 19:05:24 +000049 } else {
50 printf("New folder created with ID: %d\n", newid);
51 }
Linus Walleij843210f2010-10-17 22:40:45 +000052 return 0;
cjdebenh4a99f502006-11-09 22:03:05 +000053}
Linus Walleij9c6ca022006-04-21 10:24:15 +000054
Linus Walleij843210f2010-10-17 22:40:45 +000055int
cjdebenhc80f9b42006-11-09 22:29:26 +000056newfolder_function(char * path)
cjdebenh4a99f502006-11-09 22:03:05 +000057{
58 printf("Creating new folder %s\n",path);
59 char * parent = dirname(path);
60 char * folder = basename(path);
61 int id = parse_path (parent,files,folders);
Linus Walleijea68f1f2008-06-22 21:54:44 +000062 int newid = LIBMTP_Create_Folder(device, folder, id, 0);
cjdebenh4a99f502006-11-09 22:03:05 +000063 if (newid == 0) {
64 printf("Folder creation failed.\n");
Linus Walleij070e9b42007-01-22 08:49:28 +000065 LIBMTP_Dump_Errorstack(device);
66 LIBMTP_Clear_Errorstack(device);
Linus Walleij843210f2010-10-17 22:40:45 +000067 return 1;
cjdebenh4a99f502006-11-09 22:03:05 +000068 } else {
69 printf("New folder created with ID: %d\n", newid);
70 }
Linus Walleij843210f2010-10-17 22:40:45 +000071 return 0;
Linus Walleij9c6ca022006-04-21 10:24:15 +000072}
73