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
|
|
|
#include "backends/cloud/manager.h"
|
|
|
|
#include "backends/cloud/dropbox/dropboxstorage.h"
|
2016-05-18 14:08:05 +06:00
|
|
|
#include "common/config-manager.h"
|
2016-05-24 16:19:22 +06:00
|
|
|
#include "onedrive/onedrivestorage.h"
|
2016-05-11 01:10:37 +06:00
|
|
|
|
2016-05-11 20:24:53 +06:00
|
|
|
namespace Cloud {
|
2016-05-11 15:15:23 +06:00
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
Manager::Manager(): _currentStorageIndex(0) {}
|
2016-05-11 15:15:23 +06:00
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
Manager::~Manager() {
|
|
|
|
//TODO: do we have to save storages on manager destruction?
|
|
|
|
for (uint32 i = 0; i < _storages.size(); ++i)
|
|
|
|
delete _storages[i];
|
|
|
|
_storages.clear();
|
|
|
|
}
|
2016-05-11 15:15:23 +06:00
|
|
|
|
2016-05-18 14:08:05 +06:00
|
|
|
void Manager::init() {
|
2016-05-23 11:23:33 +06:00
|
|
|
bool offerDropbox = false;
|
2016-05-24 16:19:22 +06:00
|
|
|
bool offerOneDrive = true;
|
2016-05-23 11:23:33 +06:00
|
|
|
|
|
|
|
if (ConfMan.hasKey("storages_number", "cloud")) {
|
|
|
|
int storages = ConfMan.getInt("storages_number", "cloud");
|
|
|
|
for (int i = 1; i <= storages; ++i) {
|
|
|
|
Storage *loaded = 0;
|
|
|
|
Common::String keyPrefix = Common::String::format("storage%d_", i);
|
|
|
|
if (ConfMan.hasKey(keyPrefix + "type", "cloud")) {
|
|
|
|
Common::String storageType = ConfMan.get(keyPrefix + "type", "cloud");
|
|
|
|
if (storageType == "Dropbox") loaded = Dropbox::DropboxStorage::loadFromConfig(keyPrefix);
|
2016-05-24 16:19:22 +06:00
|
|
|
else if (storageType == "OneDrive") {
|
|
|
|
loaded = OneDrive::OneDriveStorage::loadFromConfig(keyPrefix);
|
|
|
|
offerOneDrive = false;
|
|
|
|
} else warning("Unknown cloud storage type '%s' passed", storageType.c_str());
|
2016-05-23 11:23:33 +06:00
|
|
|
} else {
|
|
|
|
warning("Cloud storage #%d (out of %d) is missing.", i, storages);
|
|
|
|
}
|
|
|
|
if (loaded) _storages.push_back(loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 index = 0;
|
|
|
|
if (ConfMan.hasKey("current_storage", "cloud")) {
|
|
|
|
index = ConfMan.getInt("current_storage", "cloud") - 1; //count from 1, all for UX
|
|
|
|
}
|
|
|
|
if (index >= _storages.size()) index = 0;
|
|
|
|
_currentStorageIndex = index;
|
|
|
|
|
|
|
|
if (_storages.size() == 0) offerDropbox = true;
|
|
|
|
} else {
|
|
|
|
offerDropbox = true;
|
2016-05-18 14:08:05 +06:00
|
|
|
}
|
2016-05-23 11:23:33 +06:00
|
|
|
|
|
|
|
if (offerDropbox) {
|
2016-05-24 16:19:22 +06:00
|
|
|
//this is temporary console offer to auth with Dropbox
|
2016-05-18 14:08:05 +06:00
|
|
|
Dropbox::DropboxStorage::authThroughConsole();
|
2016-05-24 16:19:22 +06:00
|
|
|
} else if(offerOneDrive) {
|
|
|
|
//OneDrive time
|
|
|
|
OneDrive::OneDriveStorage::authThroughConsole();
|
2016-05-18 14:08:05 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
void Manager::save() {
|
|
|
|
ConfMan.set("storages_number", Common::String::format("%d", _storages.size()), "cloud");
|
|
|
|
ConfMan.set("current_storage", Common::String::format("%d", _currentStorageIndex + 1), "cloud");
|
|
|
|
for (uint32 i = 0; i < _storages.size(); ++i)
|
|
|
|
_storages[i]->saveConfig(Common::String::format("storage%d_", i+1));
|
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:19:22 +06:00
|
|
|
void Manager::addStorage(Cloud::Storage *storage, bool makeCurrent, bool saveConfig) {
|
|
|
|
if (!storage) error("Cloud::Manager: NULL storage passed");
|
|
|
|
_storages.push_back(storage);
|
|
|
|
if (makeCurrent) _currentStorageIndex = _storages.size() - 1;
|
|
|
|
if (saveConfig) save();
|
|
|
|
}
|
|
|
|
|
2016-05-23 11:23:33 +06:00
|
|
|
Storage *Manager::getCurrentStorage() {
|
|
|
|
if (_currentStorageIndex < _storages.size())
|
|
|
|
return _storages[_currentStorageIndex];
|
2016-05-28 19:52:56 +02:00
|
|
|
return nullptr;
|
2016-05-11 20:24:53 +06:00
|
|
|
}
|
2016-05-11 12:31:26 +06:00
|
|
|
|
2016-05-22 00:04:00 +06:00
|
|
|
void Manager::syncSaves(Storage::BoolCallback callback) {
|
2016-05-23 11:23:33 +06:00
|
|
|
Storage *storage = getCurrentStorage();
|
2016-05-21 00:44:09 +06:00
|
|
|
if (storage) storage->syncSaves(callback);
|
2016-05-11 20:24:53 +06:00
|
|
|
}
|
2016-05-11 01:10:37 +06:00
|
|
|
|
2016-05-28 20:10:38 +02:00
|
|
|
} // End of namespace Cloud
|