2016-06-03 15:14:12 +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-06-03 15:14:12 +06:00
|
|
|
|
|
|
|
#ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTORAGE_H
|
|
|
|
#define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTORAGE_H
|
|
|
|
|
2016-07-14 08:50:31 +06:00
|
|
|
#include "backends/cloud/id/idstorage.h"
|
2016-06-03 15:14:12 +06:00
|
|
|
#include "backends/networking/curl/curljsonrequest.h"
|
|
|
|
|
|
|
|
namespace Cloud {
|
|
|
|
namespace GoogleDrive {
|
|
|
|
|
2016-07-14 08:50:31 +06:00
|
|
|
class GoogleDriveStorage: public Id::IdStorage {
|
2016-06-03 15:14:12 +06:00
|
|
|
/** This private constructor is called from loadFromConfig(). */
|
2019-07-27 22:44:15 +07:00
|
|
|
GoogleDriveStorage(Common::String token, Common::String refreshToken, bool enabled);
|
2016-06-03 15:14:12 +06:00
|
|
|
|
|
|
|
/** Constructs StorageInfo based on JSON response from cloud. */
|
|
|
|
void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json);
|
|
|
|
|
2016-06-06 20:04:13 +06:00
|
|
|
/** Returns bool based on JSON response from cloud. */
|
|
|
|
void createDirectoryInnerCallback(BoolCallback outerCallback, Networking::JsonResponse json);
|
|
|
|
|
2016-06-03 15:14:12 +06:00
|
|
|
void printInfo(StorageInfoResponse response);
|
2019-07-15 21:06:00 +07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @return "gdrive"
|
|
|
|
*/
|
|
|
|
virtual Common::String cloudProvider();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return kStorageGoogleDriveId
|
|
|
|
*/
|
|
|
|
virtual uint32 storageIndex();
|
|
|
|
|
2019-07-15 22:14:23 +07:00
|
|
|
virtual bool needsRefreshToken();
|
|
|
|
|
2019-07-16 14:09:38 +07:00
|
|
|
virtual bool canReuseRefreshToken();
|
|
|
|
|
2016-06-10 16:35:23 +06:00
|
|
|
public:
|
|
|
|
/** This constructor uses OAuth code flow to get tokens. */
|
2019-07-18 23:10:49 +07:00
|
|
|
GoogleDriveStorage(Common::String code, Networking::ErrorCallback cb);
|
2016-06-03 15:14:12 +06:00
|
|
|
virtual ~GoogleDriveStorage();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2016-06-08 18:51:00 +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;
|
|
|
|
|
2016-06-03 15:14:12 +06:00
|
|
|
/** Public Cloud API comes down there. */
|
|
|
|
|
2016-06-06 20:04:13 +06:00
|
|
|
/** Returns Array<StorageFile> - the list of files. */
|
|
|
|
virtual Networking::Request *listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback);
|
|
|
|
|
2016-06-03 15:14:12 +06:00
|
|
|
/** Returns UploadStatus struct with info about uploaded file. */
|
|
|
|
virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback);
|
|
|
|
|
|
|
|
/** Returns pointer to Networking::NetworkReadStream. */
|
2016-06-08 13:02:49 +06:00
|
|
|
virtual Networking::Request *streamFileById(Common::String id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback);
|
|
|
|
|
2016-06-06 20:04:13 +06:00
|
|
|
/** Calls the callback when finished. */
|
2017-01-10 05:15:56 +00:00
|
|
|
virtual Networking::Request *createDirectoryWithParentId(Common::String parentId, Common::String directoryName, BoolCallback callback, Networking::ErrorCallback errorCallback);
|
2016-06-06 20:04:13 +06:00
|
|
|
|
2016-06-03 15:14:12 +06:00
|
|
|
/** Returns the StorageInfo struct. */
|
|
|
|
virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback);
|
|
|
|
|
|
|
|
/** Returns storage's saves directory path with the trailing slash. */
|
|
|
|
virtual Common::String savesDirectoryPath();
|
|
|
|
|
|
|
|
/**
|
2016-07-21 11:44:36 +06:00
|
|
|
* Load token and user id from configs and return GoogleDriveStorage for those.
|
2016-06-03 15:14:12 +06:00
|
|
|
* @return pointer to the newly created GoogleDriveStorage or 0 if some problem occured.
|
|
|
|
*/
|
|
|
|
static GoogleDriveStorage *loadFromConfig(Common::String keyPrefix);
|
|
|
|
|
2019-07-18 23:10:49 +07:00
|
|
|
/**
|
|
|
|
* Remove all GoogleDriveStorage-related data from config.
|
|
|
|
*/
|
|
|
|
static void removeFromConfig(Common::String keyPrefix);
|
|
|
|
|
2016-07-14 08:50:31 +06:00
|
|
|
virtual Common::String getRootDirectoryId();
|
|
|
|
|
2016-07-20 18:47:34 +06:00
|
|
|
Common::String accessToken() const { return _token; }
|
2016-06-03 15:14:12 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace GoogleDrive
|
|
|
|
} // End of namespace Cloud
|
|
|
|
|
|
|
|
#endif
|