forked from ghajba/dropbox-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropboxFunctions.java
More file actions
142 lines (118 loc) · 3.98 KB
/
Copy pathDropboxFunctions.java
File metadata and controls
142 lines (118 loc) · 3.98 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import com.dropbox.core.DbxAppInfo;
import com.dropbox.core.DbxAuthFinish;
import com.dropbox.core.DbxClient;
import com.dropbox.core.DbxEntry;
import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.DbxWebAuthNoRedirect;
import com.dropbox.core.DbxWriteMode;
public class DropboxFunctions {
public static String authorizeUrl, currentdir;
public static DbxWebAuthNoRedirect webAuth;
public static DbxClient client;
public static DbxRequestConfig config;
public static List<String> CleanArrayGetPaths(String arraytostring)
{
List<String> passing=new ArrayList<String>();
while(arraytostring.contains("("))
{
int pos = arraytostring.indexOf("("), y=0;
char c=' ';
while (c!='"')
{
y++;
c=arraytostring.charAt(pos+2+y);
}
passing.add(arraytostring.substring(pos+2,pos+2+y));
arraytostring = arraytostring.substring(pos+2+y, arraytostring.length());
}
return passing;
}
public static List<String>listDropboxFolders(String folderPath, DbxClient client, boolean includeDeleted) throws DbxException {
List<String> array= new ArrayList<String>();
DbxEntry.WithChildren listing = client.getMetadataWithChildren(folderPath, includeDeleted);
for (DbxEntry child : listing.children) {
array.add(" " + child.name + ": " + child.toString());
}
currentdir = folderPath;
return array;
}
public static void SetupAuthentication()
{
final String APP_KEY = "YOURAPPKEY";
final String APP_SECRET = "YOURAPPSECRET";
DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
config = new DbxRequestConfig(
"ROCkSafe", Locale.getDefault().toString());
webAuth = new DbxWebAuthNoRedirect(config, appInfo);
authorizeUrl = webAuth.start();
}
public static void Authenticate(String code) throws DbxException
{
DbxAuthFinish authFinish = webAuth.finish(code);
String accessToken = authFinish.accessToken;
client = new DbxClient(config, accessToken);
BuildGUI.link.setText("Linked account: " + client.getAccountInfo().displayName);
}
public static List<String> getRevisionsArray(String listostring, List<String> revs)
{
revs.clear();
while(listostring.contains("rev"))
{
int pos = listostring.indexOf("rev"), y=0;
char c=' ';
while (c!='"')
{
y++;
c=listostring.charAt(pos+5+y);
}
revs.add(listostring.substring(pos+5,pos+5+y));
listostring = listostring.substring(pos+3, listostring.length());
}
//revs=["PIU' NUOVA", "PIU' VECCHIA"], ultima che leggi, prima versione "0"
return revs;
}
public static void Upload(String filetoupload, String where) throws DbxException, IOException
{
File inputFile = new File(filetoupload);
FileInputStream inputStream = new FileInputStream(inputFile);
try {
while (filetoupload.contains("/"))
{
filetoupload= filetoupload.substring(1, filetoupload.length());
}
if (where!="/")
{
where=where+"/";
}
DbxEntry.File uploadedFile = client.uploadFile(where+filetoupload,
DbxWriteMode.add(), inputFile.length(), inputStream);
} finally {
inputStream.close();
}
}
public static void Download(String filetodownload, String where) throws DbxException, IOException
{
String filetodownloadstripped=filetodownload;
while (filetodownloadstripped.contains("/"))
{
filetodownloadstripped= filetodownloadstripped.substring(1, filetodownloadstripped.length());
}
File inputFile = new File(where+filetodownloadstripped);
FileOutputStream outputStream = new FileOutputStream(inputFile);
try {
DbxEntry.File downloadFile = client.getFile(filetodownload, null, outputStream);
} finally {
outputStream.close();
}
}
}