2016-05-11 01:10:37 +06:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-11 20:24:53 +06:00
|
|
|
#ifndef BACKENDS_CLOUD_DROPBOX_STORAGE_H
|
|
|
|
#define BACKENDS_CLOUD_DROPBOX_STORAGE_H
|
2016-05-11 01:10:37 +06:00
|
|
|
|
2016-05-11 20:24:53 +06:00
|
|
|
#include "backends/cloud/storage.h"
|
2016-05-21 14:06:50 +06:00
|
|
|
#include "common/callback.h"
|
2016-05-26 19:22:27 +06:00
|
|
|
#include "backends/networking/curl/curljsonrequest.h"
|
2016-05-11 15:15:23 +06:00
|
|
|
|
2016-05-18 14:08:05 +06:00
|
|
|
namespace Cloud {
|
|
|
|
namespace Dropbox {
|
2016-05-11 20:24:53 +06:00
|
|
|
|
2016-05-18 14:08:05 +06:00
|
|
|
class DropboxStorage: public Cloud::Storage {
|
2016-05-27 22:33:39 +06:00
|
|
|
static char *KEY, *SECRET;
|
|
|
|
|
|
|
|
static void loadKeyAndSecret();
|
2016-05-18 14:08:05 +06:00
|
|
|
|
|
|
|
Common::String _token, _uid;
|
|
|
|
|
|
|
|
/** This private constructor is called from loadFromConfig(). */
|
|
|
|
DropboxStorage(Common::String token, Common::String uid);
|
|
|
|
|
2016-05-18 15:21:09 +06:00
|
|
|
static void getAccessToken(Common::String code);
|
2016-05-18 14:08:05 +06:00
|
|
|
|
2016-05-22 00:04:00 +06:00
|
|
|
/** Constructs StorageInfo based on JSON response from cloud. */
|
2016-05-27 15:21:06 +06:00
|
|
|
void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json);
|
2016-05-22 00:04:00 +06:00
|
|
|
|
2016-05-27 20:59:40 +06:00
|
|
|
void printFiles(FileArrayResponse pair);
|
2016-05-30 02:23:29 +06:00
|
|
|
void printBool(BoolResponse pair);
|
2016-05-30 13:35:53 +06:00
|
|
|
void printUploadStatus(UploadResponse pair);
|
2016-05-24 00:14:24 +06:00
|
|
|
|
2016-05-18 14:08:05 +06:00
|
|
|
public:
|
2016-05-15 00:31:02 +06:00
|
|
|
virtual ~DropboxStorage();
|
2016-05-11 12:31:26 +06:00
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
/**
|
2016-05-28 20:10:38 +02:00
|
|
|
* Storage methods, which are used by CloudManager to save
|
|
|
|
* storage in configuration file.
|
|
|
|
*/
|
2016-05-23 11:23:33 +06:00
|
|
|
|
|
|
|
/**
|
2016-05-28 20:10:38 +02:00
|
|
|
* Save storage data using ConfMan.
|
|
|
|
* @param keyPrefix all saved keys must start with this prefix.
|
|
|
|
* @note every Storage must write keyPrefix + "type" key
|
|
|
|
* with common value (e.g. "Dropbox").
|
|
|
|
*/
|
2016-05-23 11:23:33 +06:00
|
|
|
virtual void saveConfig(Common::String keyPrefix);
|
|
|
|
|
|
|
|
/** Public Cloud API comes down there. */
|
|
|
|
|
2016-05-30 18:13:31 +06:00
|
|
|
/** Returns ListDirectoryStatus struct with list of files. */
|
|
|
|
virtual Networking::Request *listDirectory(Common::String path, ListDirectoryCallback callback, bool recursive = false);
|
|
|
|
|
|
|
|
/** Returns UploadStatus struct with info about uploaded file. */
|
2016-05-30 13:35:53 +06:00
|
|
|
virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback);
|
|
|
|
virtual Networking::Request *upload(Common::String remotePath, Common::String localPath, UploadCallback callback);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
2016-05-24 11:57:49 +06:00
|
|
|
/** Returns pointer to Networking::NetworkReadStream. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback);
|
2016-05-24 11:57:49 +06:00
|
|
|
|
|
|
|
/** Calls the callback when finished. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
2016-05-27 20:59:40 +06:00
|
|
|
/** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
|
2016-05-28 20:40:20 +06:00
|
|
|
virtual Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, bool recursive = false);
|
2016-05-27 20:59:40 +06:00
|
|
|
|
2016-05-21 00:44:09 +06:00
|
|
|
/** Calls the callback when finished. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *remove(Common::String path, BoolCallback callback) { return nullptr; } //TODO
|
2016-05-21 00:44:09 +06:00
|
|
|
|
|
|
|
/** Calls the callback when finished. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *syncSaves(BoolCallback callback);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
|
|
|
/** Calls the callback when finished. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback) { return nullptr; } //TODO
|
2016-05-21 00:44:09 +06:00
|
|
|
|
|
|
|
/** Calls the callback when finished. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *touch(Common::String path, BoolCallback callback) { return nullptr; } //TODO
|
2016-05-21 23:21:42 +06:00
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
/** Returns the StorageInfo struct. */
|
2016-05-27 15:21:06 +06:00
|
|
|
virtual Networking::Request *info(StorageInfoCallback callback);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
2016-05-22 00:04:00 +06:00
|
|
|
/** This method is passed into info(). (Temporary) */
|
2016-05-27 15:21:06 +06:00
|
|
|
void infoMethodCallback(StorageInfoResponse pair);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
|
|
|
/** Returns whether saves sync process is running. */
|
|
|
|
virtual bool isSyncing() { return false; } //TODO
|
|
|
|
|
|
|
|
/** Returns whether there are any requests running. */
|
|
|
|
virtual bool isWorking() { return false; } //TODO
|
|
|
|
|
2016-05-18 14:08:05 +06:00
|
|
|
/**
|
2016-05-28 20:10:38 +02:00
|
|
|
* Load token and user id from configs and return DropboxStorage for those.
|
|
|
|
* @return pointer to the newly created DropboxStorage or 0 if some problem occured.
|
|
|
|
*/
|
2016-05-23 11:23:33 +06:00
|
|
|
static DropboxStorage *loadFromConfig(Common::String keyPrefix);
|
2016-05-18 14:08:05 +06:00
|
|
|
|
|
|
|
/**
|
2016-05-28 20:10:38 +02:00
|
|
|
* Returns Dropbox auth link.
|
|
|
|
*/
|
2016-05-18 15:31:22 +06:00
|
|
|
static Common::String getAuthLink();
|
2016-05-18 14:08:05 +06:00
|
|
|
|
|
|
|
/**
|
2016-05-28 20:10:38 +02:00
|
|
|
* Show message with Dropbox auth instructions. (Temporary)
|
|
|
|
*/
|
2016-05-18 15:21:09 +06:00
|
|
|
static void authThroughConsole();
|
2016-05-11 01:10:37 +06:00
|
|
|
};
|
|
|
|
|
2016-05-28 20:10:38 +02:00
|
|
|
} // End of namespace Dropbox
|
|
|
|
} // End of namespace Cloud
|
2016-05-11 20:24:53 +06:00
|
|
|
|
2016-05-11 01:10:37 +06:00
|
|
|
#endif
|