2016-05-11 01:10:37 +06:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2016-09-03 12:46:38 +02:00
|
|
|
*
|
|
|
|
* 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 01:10:37 +06:00
|
|
|
|
2016-05-11 20:24:53 +06:00
|
|
|
#ifndef BACKENDS_CLOUD_STORAGE_H
|
|
|
|
#define BACKENDS_CLOUD_STORAGE_H
|
2016-05-11 01:10:37 +06:00
|
|
|
|
2016-05-27 15:21:06 +06:00
|
|
|
#include "backends/cloud/storagefile.h"
|
|
|
|
#include "backends/cloud/storageinfo.h"
|
|
|
|
#include "backends/networking/curl/request.h"
|
|
|
|
#include "backends/networking/curl/curlrequest.h"
|
2016-05-21 00:44:09 +06:00
|
|
|
#include "common/array.h"
|
2016-06-01 16:33:45 +06:00
|
|
|
#include "common/callback.h"
|
|
|
|
#include "common/mutex.h"
|
2016-05-21 00:44:09 +06:00
|
|
|
#include "common/stream.h"
|
2016-05-11 20:24:53 +06:00
|
|
|
#include "common/str.h"
|
2016-05-11 15:15:23 +06:00
|
|
|
|
2016-06-05 20:20:22 +06:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class CommandReceiver;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 20:24:53 +06:00
|
|
|
namespace Cloud {
|
2016-05-11 15:15:23 +06:00
|
|
|
|
2016-06-05 00:06:36 +06:00
|
|
|
class SavesSyncRequest;
|
2016-07-04 16:14:30 +06:00
|
|
|
class FolderDownloadRequest;
|
2016-06-05 00:06:36 +06:00
|
|
|
|
2016-05-11 20:24:53 +06:00
|
|
|
class Storage {
|
2016-05-11 01:10:37 +06:00
|
|
|
public:
|
2016-05-27 15:21:06 +06:00
|
|
|
typedef Networking::Response<Common::Array<StorageFile>&> FileArrayResponse;
|
|
|
|
typedef Networking::Response<StorageInfo> StorageInfoResponse;
|
|
|
|
typedef Networking::Response<bool> BoolResponse;
|
2016-05-31 01:51:32 +06:00
|
|
|
typedef Networking::Response<StorageFile> UploadResponse;
|
|
|
|
typedef Networking::Response<Common::Array<StorageFile> &> ListDirectoryResponse;
|
2016-05-26 19:02:55 +06:00
|
|
|
|
2016-05-27 15:21:06 +06:00
|
|
|
typedef Common::BaseCallback<FileArrayResponse> *FileArrayCallback;
|
|
|
|
typedef Common::BaseCallback<StorageInfoResponse> *StorageInfoCallback;
|
|
|
|
typedef Common::BaseCallback<BoolResponse> *BoolCallback;
|
2016-05-30 13:35:53 +06:00
|
|
|
typedef Common::BaseCallback<UploadResponse> *UploadCallback;
|
2016-05-30 18:13:31 +06:00
|
|
|
typedef Common::BaseCallback<ListDirectoryResponse> *ListDirectoryCallback;
|
2016-05-22 00:04:00 +06:00
|
|
|
|
2016-06-01 12:39:10 +06:00
|
|
|
protected:
|
|
|
|
/** Keeps track of running requests. */
|
|
|
|
uint32 _runningRequestsCount;
|
2016-06-01 16:33:45 +06:00
|
|
|
Common::Mutex _runningRequestsMutex;
|
2016-07-20 18:47:34 +06:00
|
|
|
|
|
|
|
/** SavesSyncRequest-related */
|
2016-06-05 00:06:36 +06:00
|
|
|
SavesSyncRequest *_savesSyncRequest;
|
2016-06-13 12:32:33 +06:00
|
|
|
bool _syncRestartRequestsed;
|
2016-07-20 18:47:34 +06:00
|
|
|
|
|
|
|
/** FolderDownloadRequest-related */
|
2016-07-04 16:14:30 +06:00
|
|
|
FolderDownloadRequest *_downloadFolderRequest;
|
2016-05-31 19:18:06 +06:00
|
|
|
|
2019-07-27 22:44:15 +07:00
|
|
|
/** Whether user manually enabled the Storage. */
|
|
|
|
bool _isEnabled;
|
|
|
|
|
2016-05-31 19:18:06 +06:00
|
|
|
/** Returns default error callback (printErrorResponse). */
|
|
|
|
virtual Networking::ErrorCallback getErrorPrintingCallback();
|
|
|
|
|
|
|
|
/** Prints ErrorResponse contents with debug(). */
|
|
|
|
virtual void printErrorResponse(Networking::ErrorResponse error);
|
|
|
|
|
2016-06-01 12:39:10 +06:00
|
|
|
/**
|
|
|
|
* Adds request to the ConnMan, but also increases _runningRequestsCount.
|
|
|
|
* This method should be used by Storage implementations instead of
|
|
|
|
* direct ConnMan.addRequest() call.
|
|
|
|
*
|
|
|
|
* @return the same Request pointer, just as a shortcut
|
|
|
|
*/
|
|
|
|
virtual Networking::Request *addRequest(Networking::Request *request);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decreases _runningRequestCount. It's called from ConnMan automatically.
|
|
|
|
* Passed pointer is dangling, but one can use the address to determine
|
|
|
|
* some special Requests (which addresses were remembered somewhere).
|
|
|
|
*/
|
|
|
|
virtual void requestFinishedCallback(Networking::Request *invalidRequestPointer);
|
|
|
|
|
2016-05-31 19:18:06 +06:00
|
|
|
public:
|
2016-06-01 12:39:10 +06:00
|
|
|
Storage();
|
|
|
|
virtual ~Storage();
|
2016-05-11 20:24:53 +06:00
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
/**
|
|
|
|
* Storage methods, which are used by CloudManager to save
|
|
|
|
* storage in configuration file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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").
|
|
|
|
*/
|
|
|
|
virtual void saveConfig(Common::String keyPrefix) = 0;
|
|
|
|
|
2016-06-08 18:51:00 +06:00
|
|
|
/**
|
2016-07-21 11:44:36 +06:00
|
|
|
* Return unique storage name.
|
2016-07-21 09:29:54 +02:00
|
|
|
* @returns some unique storage name (for example, "Dropbox (user@example.com)")
|
2016-06-08 18:51:00 +06:00
|
|
|
*/
|
|
|
|
virtual Common::String name() const = 0;
|
|
|
|
|
2019-07-27 22:44:15 +07:00
|
|
|
/**
|
|
|
|
* Return whether Storage has been manually enabled by user.
|
|
|
|
*/
|
|
|
|
bool isEnabled() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set _isEnabled to true.
|
|
|
|
*/
|
|
|
|
void enable();
|
|
|
|
|
2016-05-26 17:12:40 +06:00
|
|
|
/**
|
|
|
|
* Public Cloud API comes down there.
|
|
|
|
*
|
2016-05-27 15:21:06 +06:00
|
|
|
* All Cloud API methods return Networking::Request *, which
|
|
|
|
* might be used to control request. All methods also accept
|
|
|
|
* a callback, which is called, when request is complete.
|
2016-05-26 17:12:40 +06:00
|
|
|
*/
|
2016-05-23 11:23:33 +06:00
|
|
|
|
2016-06-09 18:49:17 +06:00
|
|
|
/** Returns ListDirectoryResponse with list of files. */
|
2016-05-31 01:51:32 +06:00
|
|
|
virtual Networking::Request *listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false) = 0;
|
2016-07-21 11:44:36 +06:00
|
|
|
|
2016-07-20 18:47:34 +06:00
|
|
|
/** Returns StorageFile with info about uploaded file. */
|
2016-05-31 01:51:32 +06:00
|
|
|
virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback) = 0;
|
2016-05-31 14:18:32 +06:00
|
|
|
virtual Networking::Request *upload(Common::String remotePath, Common::String localPath, UploadCallback callback, Networking::ErrorCallback errorCallback);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
2016-07-14 07:44:58 +06:00
|
|
|
/** Returns whether Storage supports upload(ReadStream). */
|
|
|
|
virtual bool uploadStreamSupported();
|
|
|
|
|
2016-05-24 11:57:49 +06:00
|
|
|
/** Returns pointer to Networking::NetworkReadStream. */
|
2016-06-08 13:02:49 +06:00
|
|
|
virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback);
|
|
|
|
virtual Networking::Request *streamFileById(Common::String id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) = 0;
|
2016-05-24 11:57:49 +06:00
|
|
|
|
|
|
|
/** Calls the callback when finished. */
|
2016-05-31 19:41:11 +06:00
|
|
|
virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
|
2016-06-08 12:45:58 +06:00
|
|
|
virtual Networking::Request *downloadById(Common::String remoteId, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
|
2016-05-21 00:44:09 +06:00
|
|
|
|
2016-05-28 20:40:20 +06:00
|
|
|
/** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
|
2016-05-31 19:41:11 +06:00
|
|
|
virtual Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
|
2016-05-28 20:40:20 +06:00
|
|
|
|
2016-05-21 00:44:09 +06:00
|
|
|
/** Calls the callback when finished. */
|
2016-06-05 15:22:26 +06:00
|
|
|
virtual SavesSyncRequest *syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback);
|
2016-05-11 12:31:26 +06:00
|
|
|
|
2016-05-21 00:44:09 +06:00
|
|
|
/** Calls the callback when finished. */
|
2016-05-31 01:51:32 +06:00
|
|
|
virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;
|
2016-05-11 20:24:53 +06:00
|
|
|
|
2016-06-09 18:49:17 +06:00
|
|
|
/**
|
2016-07-20 18:47:34 +06:00
|
|
|
* Returns the StorageInfo struct via <callback>.
|
|
|
|
* Calls the <errorCallback> if failed to get information.
|
2016-06-09 18:49:17 +06:00
|
|
|
*
|
|
|
|
* @note on success Storage should also call
|
2016-07-21 09:29:54 +02:00
|
|
|
* CloudMan.setStorageUsername().
|
2016-06-09 18:49:17 +06:00
|
|
|
*/
|
2016-05-31 01:51:32 +06:00
|
|
|
virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) = 0;
|
2016-05-18 14:08:05 +06:00
|
|
|
|
2016-05-31 16:23:25 +06:00
|
|
|
/** Returns storage's saves directory path with the trailing slash. */
|
|
|
|
virtual Common::String savesDirectoryPath() = 0;
|
|
|
|
|
2016-05-21 00:44:09 +06:00
|
|
|
/** Returns whether there are any requests running. */
|
2016-06-01 12:39:10 +06:00
|
|
|
virtual bool isWorking();
|
2016-06-05 00:06:36 +06:00
|
|
|
|
2016-07-04 16:14:30 +06:00
|
|
|
///// SavesSyncRequest-related /////
|
|
|
|
|
2016-06-05 00:06:36 +06:00
|
|
|
/** Returns whether there is a SavesSyncRequest running. */
|
|
|
|
virtual bool isSyncing();
|
|
|
|
|
2016-06-05 21:07:55 +06:00
|
|
|
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
|
|
|
virtual double getSyncDownloadingProgress();
|
|
|
|
|
2016-06-05 00:06:36 +06:00
|
|
|
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
|
|
|
|
virtual double getSyncProgress();
|
|
|
|
|
|
|
|
/** Returns an array of saves names which are not yet synced (thus cannot be used). */
|
|
|
|
virtual Common::Array<Common::String> getSyncingFiles();
|
2016-06-05 20:20:22 +06:00
|
|
|
|
|
|
|
/** Cancels running sync. */
|
|
|
|
virtual void cancelSync();
|
|
|
|
|
|
|
|
/** Sets SavesSyncRequest's target to given CommandReceiver. */
|
|
|
|
virtual void setSyncTarget(GUI::CommandReceiver *target);
|
2016-07-04 16:14:30 +06:00
|
|
|
|
2016-07-20 12:45:09 +06:00
|
|
|
protected:
|
|
|
|
/** Finishes the sync. Shows an OSD message. */
|
|
|
|
virtual void savesSyncDefaultCallback(BoolResponse response);
|
|
|
|
|
|
|
|
/** Finishes the sync. Shows an OSD message. */
|
|
|
|
virtual void savesSyncDefaultErrorCallback(Networking::ErrorResponse error);
|
|
|
|
|
|
|
|
public:
|
2016-07-04 16:14:30 +06:00
|
|
|
///// DownloadFolderRequest-related /////
|
|
|
|
|
|
|
|
/** Starts a folder download. */
|
|
|
|
virtual bool startDownload(Common::String remotePath, Common::String localPath);
|
|
|
|
|
|
|
|
/** Cancels running download. */
|
|
|
|
virtual void cancelDownload();
|
|
|
|
|
|
|
|
/** Sets FolderDownloadRequest's target to given CommandReceiver. */
|
|
|
|
virtual void setDownloadTarget(GUI::CommandReceiver *target);
|
|
|
|
|
|
|
|
/** Returns whether there is a FolderDownloadRequest running. */
|
|
|
|
virtual bool isDownloading();
|
|
|
|
|
|
|
|
/** Returns a number in [0, 1] range which represents current download progress (1 = complete). */
|
|
|
|
virtual double getDownloadingProgress();
|
|
|
|
|
2016-07-14 15:29:47 +06:00
|
|
|
/** Returns a number of bytes that is downloaded in current download progress. */
|
|
|
|
virtual uint64 getDownloadBytesNumber();
|
|
|
|
|
|
|
|
/** Returns a total number of bytes to be downloaded in current download progress. */
|
|
|
|
virtual uint64 getDownloadTotalBytesNumber();
|
|
|
|
|
2016-07-14 16:01:05 +06:00
|
|
|
/** Returns download speed of current download progress. */
|
|
|
|
virtual uint64 getDownloadSpeed();
|
|
|
|
|
2016-07-04 17:11:58 +06:00
|
|
|
/** Returns remote directory path. */
|
|
|
|
virtual Common::String getDownloadRemoteDirectory();
|
|
|
|
|
|
|
|
/** Returns local directory path. */
|
|
|
|
virtual Common::String getDownloadLocalDirectory();
|
|
|
|
|
2016-07-04 16:14:30 +06:00
|
|
|
protected:
|
|
|
|
/** Finishes the download. Shows an OSD message. */
|
|
|
|
virtual void directoryDownloadedCallback(FileArrayResponse response);
|
|
|
|
|
|
|
|
/** Finishes the download. Shows an OSD message. */
|
|
|
|
virtual void directoryDownloadedErrorCallback(Networking::ErrorResponse error);
|
2016-05-11 01:10:37 +06:00
|
|
|
};
|
|
|
|
|
2016-05-28 20:10:38 +02:00
|
|
|
} // End of namespace Cloud
|
2016-05-11 20:24:53 +06:00
|
|
|
|
2016-05-11 01:10:37 +06:00
|
|
|
#endif
|