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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CLOUD_CLOUDMANAGER_H
#define CLOUD_CLOUDMANAGER_H
#include "backends/cloud/storage.h"
#include "common/array.h"
#include "common/singleton.h"
#include "common/str-array.h"
namespace GUI {
class CommandReceiver;
}
namespace Cloud {
// The actual indexes in CloudManager's array
enum StorageID {
kStorageNoneId = 0,
kStorageDropboxId = 1,
kStorageOneDriveId = 2,
kStorageGoogleDriveId = 3,
kStorageBoxId = 4,
kStorageTotal
};
class CloudManager : public Common::Singleton<CloudManager> {
static const char *const kStoragePrefix;
struct StorageConfig {
Common::String name, username;
uint64 usedBytes;
Common::String lastSyncDate;
};
Common::Array<StorageConfig> _storages;
uint _currentStorageIndex;
Storage *_activeStorage;
void printBool(Cloud::Storage::BoolResponse response) const;
void loadStorage();
Common::String getStorageConfigName(uint32 index) const;
public:
CloudManager();
virtual ~CloudManager();
/**
* Loads all information from configs and creates current Storage instance.
*
* @note It's called once on startup in scummvm_main().
*/
void init();
/**
* Saves all information into configuration file.
*/
void save();
/**
* Replace active Storage.
* @note this method automatically saves the changes with ConfMan.
*
* @param storage Cloud::Storage to replace active storage with.
* @param index one of Cloud::StorageID enum values to indicate what storage type is replaced.
*/
void replaceStorage(Storage *storage, uint32 index);
/**
* Returns active Storage, which could be used to interact
* with cloud storage.
*
* @return active Cloud::Storage or null, if there is no active Storage.
*/
Cloud::Storage *getCurrentStorage() const;
/**
* Return active Storage's index.
*
* @return active Storage's index.
*/
uint32 getStorageIndex() const;
/**
* Return Storages names as list.
*
* @return a list of Storages names.
*/
Common::StringArray listStorages() const;
/**
* Changes the storage to the one with given index.
*
* @param new Storage's index.
*/
bool switchStorage(uint32 index);
/**
* Return username used by Storage.
*
* @param Storage's index.
* @returns username or "" if index is invalid (no such Storage).
*/
Common::String getStorageUsername(uint32 index);
/**
* Return space used by Storage.
*
* @param Storage's index.
* @returns used space in bytes or 0 if index is invalid (no such Storage).
*/
uint64 getStorageUsedSpace(uint32 index);
/**
* Return Storage's last sync date.
*
* @param Storage's index.
* @returns last sync date or "" if index is invalid (no such Storage).
It also returns "" if there never was any sync
or if storage is syncing right now.
*/
Common::String getStorageLastSync(uint32 index);
/**
* Set Storage's username.
* Automatically saves changes to the config.
*
* @param index Storage's index.
* @param name username to set
*/
void setStorageUsername(uint32 index, Common::String name);
/**
* Set Storage's used space field.
* Automatically saves changes to the config.
*
* @param index Storage's index.
* @param used value to set
*/
void setStorageUsedSpace(uint32 index, uint64 used);
/**
* Set Storage's last sync date.
* Automatically saves changes to the config.
*
* @param index Storage's index.
* @param date date to set
*/
void setStorageLastSync(uint32 index, Common::String date);
/**
* Replace Storage which has given index with a
* storage created with given code.
*
* @param index Storage's index
* @param code OAuth2 code received from user
*/
void connectStorage(uint32 index, Common::String code);
/** Returns ListDirectoryResponse with list of files. */
Networking::Request *listDirectory(Common::String path, Storage::ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
/** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, Storage::FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
/** Return the StorageInfo struct. */
Networking::Request *info(Storage::StorageInfoCallback callback, Networking::ErrorCallback errorCallback);
/** Returns storage's saves directory path with the trailing slash. */
Common::String savesDirectoryPath();
/**
* Starts saves syncing process in currently active storage if there is any.
*/
SavesSyncRequest *syncSaves(Cloud::Storage::BoolCallback callback = nullptr, Networking::ErrorCallback errorCallback = nullptr);
/**
* Starts feature testing (the one I'm working on currently). (Temporary)
*/
void testFeature();
/** Returns whether there are any requests running. */
bool isWorking();
///// SavesSyncRequest-related /////
/** Returns whether there is a SavesSyncRequest running. */
bool isSyncing();
/** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */
double getSyncDownloadingProgress();
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
double getSyncProgress();
/** Returns an array of saves names which are not yet synced (thus cannot be used). */
Common::Array<Common::String> getSyncingFiles();
/** Cancels running sync. */
void cancelSync();
/** Sets SavesSyncRequest's target to given CommandReceiver. */
void setSyncTarget(GUI::CommandReceiver *target);
///// DownloadFolderRequest-related /////
/** Starts a folder download. */
bool startDownload(Common::String remotePath, Common::String localPath);
/** Cancels running download. */
void cancelDownload();
/** Sets FolderDownloadRequest's target to given CommandReceiver. */
void setDownloadTarget(GUI::CommandReceiver *target);
/** Returns whether there is a FolderDownloadRequest running. */
bool isDownloading();
/** Returns a number in [0, 1] range which represents current download progress (1 = complete). */
double getDownloadingProgress();
/** Returns remote directory path. */
virtual Common::String getDownloadRemoteDirectory();
/** Returns local directory path. */
virtual Common::String getDownloadLocalDirectory();
};
/** Shortcut for accessing the connection manager. */
#define CloudMan Cloud::CloudManager::instance()
} // End of namespace Cloud
#endif
|