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 | * |
| 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 Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 23 | #include "common.h" |
Linus Walleij | 934cd7f | 2006-12-06 20:21:43 +0000 | [diff] [blame] | 24 | #include "pathutils.h" |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 25 | #include <libgen.h> |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 26 | |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 27 | void newfolder_function(char *); |
| 28 | void newfolder_command(int,char **); |
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 | |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 34 | void 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 | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 37 | |
| 38 | if(argc != 3) { |
| 39 | printf("Usage: newfolder name id\n"); |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 40 | printf("(id = parent folder or 0 to create the new folder in the root dir)\n"); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 41 | return; |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 44 | 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 | } |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 50 | } |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 51 | |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 52 | void |
cjdebenh | c80f9b4 | 2006-11-09 22:29:26 +0000 | [diff] [blame] | 53 | newfolder_function(char * path) |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 54 | { |
| 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 Walleij | 070e9b4 | 2007-01-22 08:49:28 +0000 | [diff] [blame] | 62 | LIBMTP_Dump_Errorstack(device); |
| 63 | LIBMTP_Clear_Errorstack(device); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame] | 64 | } else { |
| 65 | printf("New folder created with ID: %d\n", newid); |
| 66 | } |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 67 | } |
| 68 | |