2016-05-10 19:10:37 +00: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-06-01 10:22:42 +00:00
|
|
|
#ifndef CLOUD_CLOUDMANAGER_H
|
|
|
|
#define CLOUD_CLOUDMANAGER_H
|
2016-05-10 19:10:37 +00:00
|
|
|
|
2016-05-11 14:24:53 +00:00
|
|
|
#include "backends/cloud/storage.h"
|
2016-06-01 10:22:42 +00:00
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/singleton.h"
|
2016-06-12 20:24:14 +00:00
|
|
|
#include "common/str-array.h"
|
2016-05-11 09:15:23 +00:00
|
|
|
|
2016-06-05 14:20:22 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class CommandReceiver;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-01 10:22:42 +00:00
|
|
|
namespace Cloud {
|
|
|
|
|
2016-06-12 19:32:29 +00:00
|
|
|
// The actual indexes in CloudManager's array
|
|
|
|
enum StorageID {
|
2016-06-09 07:49:52 +00:00
|
|
|
kStorageNoneId = 0,
|
|
|
|
kStorageDropboxId = 1,
|
|
|
|
kStorageOneDriveId = 2,
|
|
|
|
kStorageGoogleDriveId = 3,
|
2016-07-12 18:33:35 +00:00
|
|
|
kStorageBoxId = 4,
|
2016-06-09 07:49:52 +00:00
|
|
|
|
|
|
|
kStorageTotal
|
|
|
|
};
|
|
|
|
|
2016-06-01 10:22:42 +00:00
|
|
|
class CloudManager : public Common::Singleton<CloudManager> {
|
2016-06-12 20:12:15 +00:00
|
|
|
static const char *const kStoragePrefix;
|
|
|
|
|
2016-06-09 07:49:52 +00:00
|
|
|
struct StorageConfig {
|
|
|
|
Common::String name, username;
|
|
|
|
uint64 usedBytes;
|
|
|
|
Common::String lastSyncDate;
|
|
|
|
};
|
|
|
|
|
|
|
|
Common::Array<StorageConfig> _storages;
|
|
|
|
uint _currentStorageIndex;
|
|
|
|
Storage *_activeStorage;
|
2016-06-01 10:22:42 +00:00
|
|
|
|
|
|
|
void printBool(Cloud::Storage::BoolResponse response) const;
|
2016-05-11 09:15:23 +00:00
|
|
|
|
2016-06-09 07:49:52 +00:00
|
|
|
void loadStorage();
|
|
|
|
|
|
|
|
Common::String getStorageConfigName(uint32 index) const;
|
|
|
|
|
2016-05-10 19:10:37 +00:00
|
|
|
public:
|
2016-06-01 10:22:42 +00:00
|
|
|
CloudManager();
|
|
|
|
virtual ~CloudManager();
|
2016-05-18 08:08:05 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-28 18:10:38 +00:00
|
|
|
* Loads all information from configs and creates current Storage instance.
|
|
|
|
*
|
|
|
|
* @note It's called once on startup in scummvm_main().
|
|
|
|
*/
|
2016-06-01 10:22:42 +00:00
|
|
|
void init();
|
2016-05-11 14:24:53 +00:00
|
|
|
|
2016-05-23 05:23:33 +00:00
|
|
|
/**
|
2016-05-28 18:10:38 +00:00
|
|
|
* Saves all information into configuration file.
|
|
|
|
*/
|
2016-06-01 10:22:42 +00:00
|
|
|
void save();
|
2016-05-23 05:23:33 +00:00
|
|
|
|
2016-05-24 10:19:22 +00:00
|
|
|
/**
|
2016-06-09 07:49:52 +00:00
|
|
|
* Replace active Storage.
|
|
|
|
* @note this method automatically saves the changes with ConfMan.
|
2016-05-28 18:10:38 +00:00
|
|
|
*
|
2016-06-09 07:49:52 +00:00
|
|
|
* @param storage Cloud::Storage to replace active storage with.
|
2016-06-12 19:32:29 +00:00
|
|
|
* @param index one of Cloud::StorageID enum values to indicate what storage type is replaced.
|
2016-05-28 18:10:38 +00:00
|
|
|
*/
|
2016-06-09 07:49:52 +00:00
|
|
|
void replaceStorage(Storage *storage, uint32 index);
|
2016-05-24 10:19:22 +00:00
|
|
|
|
2016-05-11 14:24:53 +00:00
|
|
|
/**
|
2016-05-28 18:10:38 +00:00
|
|
|
* Returns active Storage, which could be used to interact
|
|
|
|
* with cloud storage.
|
|
|
|
*
|
|
|
|
* @return active Cloud::Storage or null, if there is no active Storage.
|
|
|
|
*/
|
2016-06-08 12:51:00 +00:00
|
|
|
Cloud::Storage *getCurrentStorage() const;
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Return active Storage's index.
|
|
|
|
*
|
|
|
|
* @return active Storage's index.
|
|
|
|
*/
|
2016-06-08 12:51:00 +00:00
|
|
|
uint32 getStorageIndex() const;
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Return Storages names as list.
|
|
|
|
*
|
|
|
|
* @return a list of Storages names.
|
|
|
|
*/
|
2016-06-08 12:51:00 +00:00
|
|
|
Common::StringArray listStorages() const;
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Changes the storage to the one with given index.
|
|
|
|
*
|
|
|
|
* @param new Storage's index.
|
|
|
|
*/
|
2016-06-08 12:51:00 +00:00
|
|
|
bool switchStorage(uint32 index);
|
2016-05-11 06:31:26 +00:00
|
|
|
|
2016-06-09 06:41:51 +00:00
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Return username used by Storage.
|
|
|
|
*
|
|
|
|
* @param Storage's index.
|
|
|
|
* @returns username or "" if index is invalid (no such Storage).
|
|
|
|
*/
|
2016-06-09 06:41:51 +00:00
|
|
|
Common::String getStorageUsername(uint32 index);
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Return space used by Storage.
|
|
|
|
*
|
|
|
|
* @param Storage's index.
|
|
|
|
* @returns used space in bytes or 0 if index is invalid (no such Storage).
|
|
|
|
*/
|
2016-06-09 06:41:51 +00:00
|
|
|
uint64 getStorageUsedSpace(uint32 index);
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Return Storage's last sync date.
|
|
|
|
*
|
|
|
|
* @param Storage's index.
|
|
|
|
* @returns last sync date or "" if index is invalid (no such Storage).
|
2016-06-09 06:41:51 +00:00
|
|
|
It also returns "" if there never was any sync
|
|
|
|
or if storage is syncing right now.
|
2016-06-10 10:35:23 +00:00
|
|
|
*/
|
2016-06-09 06:41:51 +00:00
|
|
|
Common::String getStorageLastSync(uint32 index);
|
|
|
|
|
2016-06-09 08:23:14 +00:00
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Set Storage's username.
|
|
|
|
* Automatically saves changes to the config.
|
|
|
|
*
|
|
|
|
* @param index Storage's index.
|
|
|
|
* @param name username to set
|
|
|
|
*/
|
2016-06-09 08:23:14 +00:00
|
|
|
void setStorageUsername(uint32 index, Common::String name);
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Set Storage's used space field.
|
|
|
|
* Automatically saves changes to the config.
|
|
|
|
*
|
|
|
|
* @param index Storage's index.
|
|
|
|
* @param used value to set
|
|
|
|
*/
|
2016-06-09 08:23:14 +00:00
|
|
|
void setStorageUsedSpace(uint32 index, uint64 used);
|
|
|
|
|
|
|
|
/**
|
2016-06-10 10:35:23 +00:00
|
|
|
* Set Storage's last sync date.
|
|
|
|
* Automatically saves changes to the config.
|
|
|
|
*
|
|
|
|
* @param index Storage's index.
|
|
|
|
* @param date date to set
|
|
|
|
*/
|
2016-06-09 08:23:14 +00:00
|
|
|
void setStorageLastSync(uint32 index, Common::String date);
|
|
|
|
|
2016-06-10 10:35:23 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2016-06-09 12:49:17 +00:00
|
|
|
/** Returns ListDirectoryResponse with list of files. */
|
|
|
|
Networking::Request *listDirectory(Common::String path, Storage::ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
|
|
|
|
|
2016-07-04 09:11:07 +00:00
|
|
|
/** 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);
|
|
|
|
|
2016-06-09 12:49:17 +00:00
|
|
|
/** 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();
|
|
|
|
|
2016-05-11 14:24:53 +00:00
|
|
|
/**
|
2016-05-28 18:10:38 +00:00
|
|
|
* Starts saves syncing process in currently active storage if there is any.
|
|
|
|
*/
|
2016-06-05 09:22:26 +00:00
|
|
|
SavesSyncRequest *syncSaves(Cloud::Storage::BoolCallback callback = nullptr, Networking::ErrorCallback errorCallback = nullptr);
|
2016-05-31 14:54:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts feature testing (the one I'm working on currently). (Temporary)
|
|
|
|
*/
|
2016-06-01 10:22:42 +00:00
|
|
|
void testFeature();
|
2016-06-05 05:35:18 +00:00
|
|
|
|
|
|
|
/** Returns whether there are any requests running. */
|
|
|
|
bool isWorking();
|
|
|
|
|
2016-07-04 10:14:30 +00:00
|
|
|
///// SavesSyncRequest-related /////
|
|
|
|
|
2016-06-05 05:35:18 +00:00
|
|
|
/** Returns whether there is a SavesSyncRequest running. */
|
|
|
|
bool isSyncing();
|
|
|
|
|
2016-06-05 15:07:55 +00:00
|
|
|
/** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */
|
|
|
|
double getSyncDownloadingProgress();
|
|
|
|
|
2016-06-05 05:35:18 +00:00
|
|
|
/** 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();
|
2016-06-05 14:20:22 +00:00
|
|
|
|
|
|
|
/** Cancels running sync. */
|
|
|
|
void cancelSync();
|
|
|
|
|
|
|
|
/** Sets SavesSyncRequest's target to given CommandReceiver. */
|
|
|
|
void setSyncTarget(GUI::CommandReceiver *target);
|
2016-07-04 10:14:30 +00:00
|
|
|
|
|
|
|
///// 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();
|
2016-07-04 11:11:58 +00:00
|
|
|
|
|
|
|
/** Returns remote directory path. */
|
|
|
|
virtual Common::String getDownloadRemoteDirectory();
|
|
|
|
|
|
|
|
/** Returns local directory path. */
|
|
|
|
virtual Common::String getDownloadLocalDirectory();
|
2016-05-10 19:10:37 +00:00
|
|
|
};
|
|
|
|
|
2016-06-01 10:22:42 +00:00
|
|
|
/** Shortcut for accessing the connection manager. */
|
|
|
|
#define CloudMan Cloud::CloudManager::instance()
|
|
|
|
|
|
|
|
} // End of namespace Cloud
|
2016-05-11 14:24:53 +00:00
|
|
|
|
2016-05-10 19:10:37 +00:00
|
|
|
#endif
|