Linus Walleij | 543badf | 2007-02-05 19:07:38 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file newfolder.c |
| 3 | * Example program to create a folder on the device. |
| 4 | * |
Linus Walleij | 2242b02 | 2009-01-02 01:44:00 +0000 | [diff] [blame] | 5 | * Copyright (C) 2006-2009 Linus Walleij <triad@df.lth.se> |
Linus Walleij | 543badf | 2007-02-05 19:07:38 +0000 | [diff] [blame] | 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 Walleij | 2eaaff0 | 2009-01-15 21:30:36 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 24 | #include <libgen.h> |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 25 | |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 26 | #include "common.h" |
| 27 | #include "pathutils.h" |
| 28 | #include "connect.h" |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 29 | |
| 30 | extern LIBMTP_folder_t *folders; |
| 31 | extern LIBMTP_file_t *files; |
| 32 | extern LIBMTP_mtpdevice_t *device; |
| 33 | |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 34 | int newfolder_command (int argc, char **argv) |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 35 | { |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 36 | uint32_t newid; |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 37 | |
Linus Walleij | 2242b02 | 2009-01-02 01:44:00 +0000 | [diff] [blame] | 38 | if(argc != 4) { |
Linus Walleij | ea68f1f | 2008-06-22 21:54:44 +0000 | [diff] [blame] | 39 | 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 Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 42 | return 0; |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 43 | } |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 44 | |
Linus Walleij | ea68f1f | 2008-06-22 21:54:44 +0000 | [diff] [blame] | 45 | newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3])); |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 46 | if (newid == 0) { |
| 47 | printf("Folder creation failed.\n"); |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 48 | return 1; |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 49 | } else { |
| 50 | printf("New folder created with ID: %d\n", newid); |
| 51 | } |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 52 | return 0; |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 53 | } |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 54 | |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 55 | int |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 56 | newfolder_function(char * path) |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 57 | { |
| 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 Walleij | ea68f1f | 2008-06-22 21:54:44 +0000 | [diff] [blame] | 62 | int newid = LIBMTP_Create_Folder(device, folder, id, 0); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 63 | if (newid == 0) { |
| 64 | printf("Folder creation failed.\n"); |
Linus Walleij | 070e9b4 | 2007-01-22 08:49:28 +0000 | [diff] [blame] | 65 | LIBMTP_Dump_Errorstack(device); |
| 66 | LIBMTP_Clear_Errorstack(device); |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 67 | return 1; |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 68 | } else { |
| 69 | printf("New folder created with ID: %d\n", newid); |
| 70 | } |
Linus Walleij | 843210f | 2010-10-17 22:40:45 +0000 | [diff] [blame] | 71 | return 0; |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 72 | } |
| 73 | |