-
Notifications
You must be signed in to change notification settings - Fork 59
/
afc.c
72 lines (59 loc) · 2.22 KB
/
afc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* afc.c
* Spirit jailbreak for Linux
*
* Copyright (c) 2010 Joshua Hill. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <libimobiledevice/afc.h>
#include "afc.h"
void afc_iter_dir(afc_client_t afc, const char* path, afc_iter_callback callback) {
//struct afc_directory *dir;
//char *dirent;
//if(AFCDirectoryOpen(conn, path, &dir)) return;
//for (;;) {
//_assertZero(AFCDirectoryRead(conn, dir, &dirent));
//if (!dirent) break;
//if (strcmp(dirent, ".") == 0 || strcmp(dirent, "..") == 0) continue;
//callback(conn, path, dirent);
//}
}
void afc_create_directory(afc_client_t afc, const char* path) {
afc_make_directory(afc, path);
}
void list_callback(afc_client_t afc, char* path, char* dirent) {
printf("DEBUG: %s", dirent);
}
void afc_list_files(afc_client_t afc, const char* path) {
afc_iter_dir(afc, path, (afc_iter_callback) list_callback);
}
void remove_callback(afc_client_t afc, const char* path, const char* dirent) {
char subdir[255];
snprintf(subdir, 255, "%s/%s", path, dirent);
afc_remove_all(afc, subdir);
printf("DEBUG: Deleted %s/%s", path, dirent);
}
void afc_remove_all(afc_client_t afc, const char* path) {
//int ret = AFCRemovePath(conn, path);
afc_error_t afc_error = afc_remove_path(afc, path);
if(afc_error == AFC_E_SUCCESS || afc_error == AFC_E_OBJECT_NOT_FOUND) {
return;
}
afc_iter_dir(afc, path, (afc_iter_callback) remove_callback);
printf("DEBUG: Deleting %s (error=%d)", path, afc_error);
afc_remove_path(afc, path);
}