diff options
Diffstat (limited to 'backends')
14 files changed, 19 insertions, 1005 deletions
diff --git a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp deleted file mode 100644 index 9e339fd999..0000000000 --- a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* 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. -* -*/ - -#include "backends/cloud/googledrive/googledrivecreatedirectoryrequest.h" -#include "backends/cloud/googledrive/googledrivestorage.h" -#include "common/debug.h" - -namespace Cloud { -namespace GoogleDrive { - -GoogleDriveCreateDirectoryRequest::GoogleDriveCreateDirectoryRequest(GoogleDriveStorage *storage, Common::String parentPath, Common::String directoryName, Storage::BoolCallback cb, Networking::ErrorCallback ecb): - Networking::Request(nullptr, ecb), - _requestedParentPath(parentPath), _requestedDirectoryName(directoryName), _storage(storage), _boolCallback(cb), - _workingRequest(nullptr), _ignoreCallback(false) { - start(); -} - -GoogleDriveCreateDirectoryRequest::~GoogleDriveCreateDirectoryRequest() { - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - delete _boolCallback; -} - -void GoogleDriveCreateDirectoryRequest::start() { - //cleanup - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - _workingRequest = nullptr; - _ignoreCallback = false; - - //the only exception when we create parent folder - is when it's ScummVM/ base folder - Common::String prefix = _requestedParentPath; - if (prefix.size() > 7) prefix.erase(7); - if (prefix.equalsIgnoreCase("ScummVM")) { - Storage::BoolCallback callback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Storage::BoolResponse>(this, &GoogleDriveCreateDirectoryRequest::createdBaseDirectoryCallback); - Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveCreateDirectoryRequest::createdBaseDirectoryErrorCallback); - _workingRequest = _storage->createDirectory("ScummVM", callback, failureCallback); - return; - } - - resolveId(); -} - -void GoogleDriveCreateDirectoryRequest::createdBaseDirectoryCallback(Storage::BoolResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (response.request) _date = response.request->date(); - resolveId(); -} - -void GoogleDriveCreateDirectoryRequest::createdBaseDirectoryErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (error.request) _date = error.request->date(); - finishError(error); -} - -void GoogleDriveCreateDirectoryRequest::resolveId() { - //check whether such folder already exists - Storage::UploadCallback innerCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Storage::UploadResponse>(this, &GoogleDriveCreateDirectoryRequest::idResolvedCallback); - Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveCreateDirectoryRequest::idResolveFailedCallback); - Common::String path = _requestedParentPath; - if (_requestedParentPath != "") path += "/"; - path += _requestedDirectoryName; - _workingRequest = _storage->resolveFileId(path, innerCallback, innerErrorCallback); -} - -void GoogleDriveCreateDirectoryRequest::idResolvedCallback(Storage::UploadResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (response.request) _date = response.request->date(); - - //resolved => folder already exists - finishCreation(false); -} - -void GoogleDriveCreateDirectoryRequest::idResolveFailedCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (error.request) _date = error.request->date(); - - //not resolved => folder not exists - if (error.response.contains("no such file found in its parent directory")) { - //parent's id after the '\n' - Common::String parentId = error.response; - for (uint32 i = 0; i < parentId.size(); ++i) - if (parentId[i] == '\n') { - parentId.erase(0, i+1); - break; - } - - Storage::BoolCallback callback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Storage::BoolResponse>(this, &GoogleDriveCreateDirectoryRequest::createdDirectoryCallback); - Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveCreateDirectoryRequest::createdDirectoryErrorCallback); - _workingRequest = _storage->createDirectoryWithParentId(parentId, _requestedDirectoryName, callback, failureCallback); - return; - } - - finishError(error); -} - -void GoogleDriveCreateDirectoryRequest::createdDirectoryCallback(Storage::BoolResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (response.request) _date = response.request->date(); - finishCreation(response.value); -} - -void GoogleDriveCreateDirectoryRequest::createdDirectoryErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (error.request) _date = error.request->date(); - finishError(error); -} - -void GoogleDriveCreateDirectoryRequest::handle() {} - -void GoogleDriveCreateDirectoryRequest::restart() { start(); } - -Common::String GoogleDriveCreateDirectoryRequest::date() const { return _date; } - -void GoogleDriveCreateDirectoryRequest::finishCreation(bool success) { - Request::finishSuccess(); - if (_boolCallback) (*_boolCallback)(Storage::BoolResponse(this, success)); -} - -} // End of namespace GoogleDrive -} // End of namespace Cloud diff --git a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h deleted file mode 100644 index 7a6ffaca1b..0000000000 --- a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h +++ /dev/null @@ -1,65 +0,0 @@ -/* 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. -* -*/ - -#ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVECREATEDIRECTORYREQUEST_H -#define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVECREATEDIRECTORYREQUEST_H - -#include "backends/cloud/storage.h" -#include "backends/networking/curl/request.h" -#include "common/callback.h" - -namespace Cloud { -namespace GoogleDrive { - -class GoogleDriveStorage; - -class GoogleDriveCreateDirectoryRequest: public Networking::Request { - Common::String _requestedParentPath; - Common::String _requestedDirectoryName; - GoogleDriveStorage *_storage; - Storage::BoolCallback _boolCallback; - Request *_workingRequest; - bool _ignoreCallback; - Common::String _date; - - void start(); - void createdBaseDirectoryCallback(Storage::BoolResponse response); - void createdBaseDirectoryErrorCallback(Networking::ErrorResponse error); - void resolveId(); - void idResolvedCallback(Storage::UploadResponse response); - void idResolveFailedCallback(Networking::ErrorResponse error); - void createdDirectoryCallback(Storage::BoolResponse response); - void createdDirectoryErrorCallback(Networking::ErrorResponse error); - void finishCreation(bool success); -public: - GoogleDriveCreateDirectoryRequest(GoogleDriveStorage *storage, Common::String parentPath, Common::String directoryName, Storage::BoolCallback cb, Networking::ErrorCallback ecb); - virtual ~GoogleDriveCreateDirectoryRequest(); - - virtual void handle(); - virtual void restart(); - virtual Common::String date() const; -}; - -} // End of namespace GoogleDrive -} // End of namespace Cloud - -#endif diff --git a/backends/cloud/googledrive/googledrivedownloadrequest.cpp b/backends/cloud/googledrive/googledrivedownloadrequest.cpp deleted file mode 100644 index df28c8b27f..0000000000 --- a/backends/cloud/googledrive/googledrivedownloadrequest.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* 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. -* -*/ - -#include "backends/cloud/googledrive/googledrivedownloadrequest.h" -#include "backends/cloud/googledrive/googledrivestorage.h" - -namespace Cloud { -namespace GoogleDrive { - -GoogleDriveDownloadRequest::GoogleDriveDownloadRequest(GoogleDriveStorage *storage, Common::String remotePath, Common::String localPath, Storage::BoolCallback cb, Networking::ErrorCallback ecb): - Networking::Request(nullptr, ecb), _requestedFile(remotePath), _requestedLocalFile(localPath), _storage(storage), _boolCallback(cb), - _workingRequest(nullptr), _ignoreCallback(false) { - start(); -} - -GoogleDriveDownloadRequest::~GoogleDriveDownloadRequest() { - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - delete _boolCallback; -} - -void GoogleDriveDownloadRequest::start() { - //cleanup - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - _workingRequest = nullptr; - _ignoreCallback = false; - - //find file's id - Storage::UploadCallback innerCallback = new Common::Callback<GoogleDriveDownloadRequest, Storage::UploadResponse>(this, &GoogleDriveDownloadRequest::idResolvedCallback); - Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveDownloadRequest, Networking::ErrorResponse>(this, &GoogleDriveDownloadRequest::idResolveFailedCallback); - _workingRequest = _storage->resolveFileId(_requestedFile, innerCallback, innerErrorCallback); -} - -void GoogleDriveDownloadRequest::idResolvedCallback(Storage::UploadResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - - Storage::BoolCallback innerCallback = new Common::Callback<GoogleDriveDownloadRequest, Storage::BoolResponse>(this, &GoogleDriveDownloadRequest::downloadCallback); - Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveDownloadRequest, Networking::ErrorResponse>(this, &GoogleDriveDownloadRequest::downloadErrorCallback); - _workingRequest = _storage->downloadById(response.value.id(), _requestedLocalFile, innerCallback, innerErrorCallback); -} - -void GoogleDriveDownloadRequest::idResolveFailedCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishError(error); -} - -void GoogleDriveDownloadRequest::downloadCallback(Storage::BoolResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishDownload(response.value); -} - -void GoogleDriveDownloadRequest::downloadErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishError(error); -} - -void GoogleDriveDownloadRequest::handle() {} - -void GoogleDriveDownloadRequest::restart() { start(); } - -void GoogleDriveDownloadRequest::finishDownload(bool success) { - Request::finishSuccess(); - if (_boolCallback) (*_boolCallback)(Storage::BoolResponse(this, success)); -} - -} // End of namespace GoogleDrive -} // End of namespace Cloud diff --git a/backends/cloud/googledrive/googledrivedownloadrequest.h b/backends/cloud/googledrive/googledrivedownloadrequest.h deleted file mode 100644 index 202a393d7a..0000000000 --- a/backends/cloud/googledrive/googledrivedownloadrequest.h +++ /dev/null @@ -1,59 +0,0 @@ -/* 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. -* -*/ - -#ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVEDOWNLOADREQUEST_H -#define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVEDOWNLOADREQUEST_H - -#include "backends/cloud/storage.h" -#include "backends/networking/curl/request.h" -#include "common/callback.h" - -namespace Cloud { -namespace GoogleDrive { - -class GoogleDriveStorage; - -class GoogleDriveDownloadRequest: public Networking::Request { - Common::String _requestedFile, _requestedLocalFile; - GoogleDriveStorage *_storage; - Storage::BoolCallback _boolCallback; - Request *_workingRequest; - bool _ignoreCallback; - - void start(); - void idResolvedCallback(Storage::UploadResponse response); - void idResolveFailedCallback(Networking::ErrorResponse error); - void downloadCallback(Storage::BoolResponse response); - void downloadErrorCallback(Networking::ErrorResponse error); - void finishDownload(bool success); -public: - GoogleDriveDownloadRequest(GoogleDriveStorage *storage, Common::String remotePath, Common::String localPath, Storage::BoolCallback cb, Networking::ErrorCallback ecb); - virtual ~GoogleDriveDownloadRequest(); - - virtual void handle(); - virtual void restart(); -}; - -} // End of namespace GoogleDrive -} // End of namespace Cloud - -#endif diff --git a/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp b/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp deleted file mode 100644 index f645041eb3..0000000000 --- a/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* 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. -* -*/ - -#include "backends/cloud/googledrive/googledrivelistdirectoryrequest.h" -#include "backends/cloud/googledrive/googledrivestorage.h" - -namespace Cloud { -namespace GoogleDrive { - -GoogleDriveListDirectoryRequest::GoogleDriveListDirectoryRequest(GoogleDriveStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive): - Networking::Request(nullptr, ecb), - _requestedPath(path), _requestedRecursive(recursive), _storage(storage), _listDirectoryCallback(cb), - _workingRequest(nullptr), _ignoreCallback(false) { - start(); -} - -GoogleDriveListDirectoryRequest::~GoogleDriveListDirectoryRequest() { - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - delete _listDirectoryCallback; -} - -void GoogleDriveListDirectoryRequest::start() { - //cleanup - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - _workingRequest = nullptr; - _files.clear(); - _directoriesQueue.clear(); - _currentDirectory = StorageFile(); - _ignoreCallback = false; - - //find out that directory's id - Storage::UploadCallback innerCallback = new Common::Callback<GoogleDriveListDirectoryRequest, Storage::UploadResponse>(this, &GoogleDriveListDirectoryRequest::idResolvedCallback); - Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveListDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveListDirectoryRequest::idResolveErrorCallback); - _workingRequest = _storage->resolveFileId(_requestedPath, innerCallback, innerErrorCallback); -} - -void GoogleDriveListDirectoryRequest::idResolvedCallback(Storage::UploadResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (response.request) _date = response.request->date(); - - StorageFile directory = response.value; - directory.setPath(_requestedPath); - _directoriesQueue.push_back(directory); - listNextDirectory(); -} - -void GoogleDriveListDirectoryRequest::idResolveErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (error.request) _date = error.request->date(); - finishError(error); -} - -void GoogleDriveListDirectoryRequest::listNextDirectory() { - if (_directoriesQueue.empty()) { - finishListing(_files); - return; - } - - _currentDirectory = _directoriesQueue.back(); - _directoriesQueue.pop_back(); - - Storage::FileArrayCallback callback = new Common::Callback<GoogleDriveListDirectoryRequest, Storage::FileArrayResponse>(this, &GoogleDriveListDirectoryRequest::listedDirectoryCallback); - Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveListDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveListDirectoryRequest::listedDirectoryErrorCallback); - _workingRequest = _storage->listDirectoryById(_currentDirectory.id(), callback, failureCallback); -} - -void GoogleDriveListDirectoryRequest::listedDirectoryCallback(Storage::FileArrayResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (response.request) _date = response.request->date(); - - for (uint32 i = 0; i < response.value.size(); ++i) { - StorageFile &file = response.value[i]; - Common::String path = _currentDirectory.path(); - if (path.size() && path.lastChar() != '/' && path.lastChar() != '\\') path += '/'; - path += file.name(); - file.setPath(path); - _files.push_back(file); - if (_requestedRecursive && file.isDirectory()) { - _directoriesQueue.push_back(file); - } - } - - listNextDirectory(); -} - -void GoogleDriveListDirectoryRequest::listedDirectoryErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - if (error.request) _date = error.request->date(); - finishError(error); -} - -void GoogleDriveListDirectoryRequest::handle() {} - -void GoogleDriveListDirectoryRequest::restart() { start(); } - -Common::String GoogleDriveListDirectoryRequest::date() const { return _date; } - -void GoogleDriveListDirectoryRequest::finishListing(Common::Array<StorageFile> &files) { - Request::finishSuccess(); - if (_listDirectoryCallback) (*_listDirectoryCallback)(Storage::ListDirectoryResponse(this, files)); -} - -} // End of namespace GoogleDrive -} // End of namespace Cloud diff --git a/backends/cloud/googledrive/googledrivelistdirectoryrequest.h b/backends/cloud/googledrive/googledrivelistdirectoryrequest.h deleted file mode 100644 index d76338b7fc..0000000000 --- a/backends/cloud/googledrive/googledrivelistdirectoryrequest.h +++ /dev/null @@ -1,67 +0,0 @@ -/* 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. -* -*/ - -#ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVELISTDIRECTORYREQUEST_H -#define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVELISTDIRECTORYREQUEST_H - -#include "backends/cloud/storage.h" -#include "backends/networking/curl/curljsonrequest.h" -#include "backends/networking/curl/request.h" -#include "common/callback.h" - -namespace Cloud { -namespace GoogleDrive { - -class GoogleDriveStorage; - -class GoogleDriveListDirectoryRequest: public Networking::Request { - Common::String _requestedPath; - bool _requestedRecursive; - GoogleDriveStorage *_storage; - Storage::ListDirectoryCallback _listDirectoryCallback; - Common::Array<StorageFile> _files; - Common::Array<StorageFile> _directoriesQueue; - StorageFile _currentDirectory; - Request *_workingRequest; - bool _ignoreCallback; - Common::String _date; - - void start(); - void idResolvedCallback(Storage::UploadResponse response); - void idResolveErrorCallback(Networking::ErrorResponse error); - void listNextDirectory(); - void listedDirectoryCallback(Storage::FileArrayResponse response); - void listedDirectoryErrorCallback(Networking::ErrorResponse error); - void finishListing(Common::Array<StorageFile> &files); -public: - GoogleDriveListDirectoryRequest(GoogleDriveStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive = false); - virtual ~GoogleDriveListDirectoryRequest(); - - virtual void handle(); - virtual void restart(); - virtual Common::String date() const; -}; - -} // End of namespace GoogleDrive -} // End of namespace Cloud - -#endif diff --git a/backends/cloud/googledrive/googledriveresolveidrequest.cpp b/backends/cloud/googledrive/googledriveresolveidrequest.cpp deleted file mode 100644 index 6d8da8383d..0000000000 --- a/backends/cloud/googledrive/googledriveresolveidrequest.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* 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. -* -*/ - -#include "backends/cloud/googledrive/googledriveresolveidrequest.h" -#include "backends/cloud/googledrive/googledrivestorage.h" -#include "backends/cloud/googledrive/googledrivetokenrefresher.h" -#include "backends/cloud/iso8601.h" -#include "backends/networking/curl/connectionmanager.h" -#include "backends/networking/curl/networkreadstream.h" -#include "common/json.h" - -namespace Cloud { -namespace GoogleDrive { - -GoogleDriveResolveIdRequest::GoogleDriveResolveIdRequest(GoogleDriveStorage *storage, Common::String path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive): - Networking::Request(nullptr, ecb), - _requestedPath(path), _storage(storage), _uploadCallback(cb), - _workingRequest(nullptr), _ignoreCallback(false) { - start(); -} - -GoogleDriveResolveIdRequest::~GoogleDriveResolveIdRequest() { - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - delete _uploadCallback; -} - -void GoogleDriveResolveIdRequest::start() { - //cleanup - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - _workingRequest = nullptr; - _currentDirectory = ""; - _currentDirectoryId = "root"; - _ignoreCallback = false; - - listNextDirectory(StorageFile(_currentDirectoryId, 0, 0, true)); -} - -void GoogleDriveResolveIdRequest::listNextDirectory(StorageFile fileToReturn) { - if (_currentDirectory.equalsIgnoreCase(_requestedPath)) { - finishFile(fileToReturn); - return; - } - - Storage::FileArrayCallback callback = new Common::Callback<GoogleDriveResolveIdRequest, Storage::FileArrayResponse>(this, &GoogleDriveResolveIdRequest::listedDirectoryCallback); - Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveResolveIdRequest, Networking::ErrorResponse>(this, &GoogleDriveResolveIdRequest::listedDirectoryErrorCallback); - _workingRequest = _storage->listDirectoryById(_currentDirectoryId, callback, failureCallback); -} - -void GoogleDriveResolveIdRequest::listedDirectoryCallback(Storage::FileArrayResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - - Common::String currentLevelName = _requestedPath; - ///debug("'%s'", currentLevelName.c_str()); - if (_currentDirectory.size()) currentLevelName.erase(0, _currentDirectory.size()); - if (currentLevelName.size() && (currentLevelName[0] == '/' || currentLevelName[0] == '\\')) currentLevelName.erase(0, 1); - ///debug("'%s'", currentLevelName.c_str()); - for (uint32 i = 0; i < currentLevelName.size(); ++i) { - if (currentLevelName[i] == '/' || currentLevelName[i] == '\\') { - currentLevelName.erase(i); - ///debug("'%s'", currentLevelName.c_str()); - break; - } - } - - Common::String path = _currentDirectory; - if (path != "") path += "/"; - path += currentLevelName; - bool lastLevel = (path.equalsIgnoreCase(_requestedPath)); - - ///debug("so, searching for '%s' in '%s'", currentLevelName.c_str(), _currentDirectory.c_str()); - - Common::Array<StorageFile> &files = response.value; - bool found = false; - for (uint32 i = 0; i < files.size(); ++i) { - if ((files[i].isDirectory() || lastLevel) && files[i].name().equalsIgnoreCase(currentLevelName)) { - if (_currentDirectory != "") _currentDirectory += "/"; - _currentDirectory += files[i].name(); - _currentDirectoryId = files[i].id(); - ///debug("found it! new directory and its id: '%s', '%s'", _currentDirectory.c_str(), _currentDirectoryId.c_str()); - listNextDirectory(files[i]); - found = true; - break; - } - } - - if (!found) { - if (lastLevel) finishError(Networking::ErrorResponse(this, false, true, Common::String("no such file found in its parent directory\n")+_currentDirectoryId, 404)); - else finishError(Networking::ErrorResponse(this, false, true, "subdirectory not found", 400)); - } -} - -void GoogleDriveResolveIdRequest::listedDirectoryErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishError(error); -} - -void GoogleDriveResolveIdRequest::handle() {} - -void GoogleDriveResolveIdRequest::restart() { start(); } - -void GoogleDriveResolveIdRequest::finishFile(StorageFile file) { - Request::finishSuccess(); - if (_uploadCallback) (*_uploadCallback)(Storage::UploadResponse(this, file)); -} - -} // End of namespace GoogleDrive -} // End of namespace Cloud diff --git a/backends/cloud/googledrive/googledriveresolveidrequest.h b/backends/cloud/googledrive/googledriveresolveidrequest.h deleted file mode 100644 index cd6f244a94..0000000000 --- a/backends/cloud/googledrive/googledriveresolveidrequest.h +++ /dev/null @@ -1,61 +0,0 @@ -/* 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. -* -*/ - -#ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVERESOLVEIDREQUEST_H -#define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVERESOLVEIDREQUEST_H - -#include "backends/cloud/storage.h" -#include "backends/networking/curl/curljsonrequest.h" -#include "backends/networking/curl/request.h" -#include "common/callback.h" - -namespace Cloud { -namespace GoogleDrive { - -class GoogleDriveStorage; - -class GoogleDriveResolveIdRequest: public Networking::Request { - Common::String _requestedPath; - GoogleDriveStorage *_storage; - Storage::UploadCallback _uploadCallback; - Common::String _currentDirectory; - Common::String _currentDirectoryId; - Request *_workingRequest; - bool _ignoreCallback; - - void start(); - void listNextDirectory(StorageFile fileToReturn); - void listedDirectoryCallback(Storage::FileArrayResponse response); - void listedDirectoryErrorCallback(Networking::ErrorResponse error); - void finishFile(StorageFile file); -public: - GoogleDriveResolveIdRequest(GoogleDriveStorage *storage, Common::String path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive = false); //TODO: why upload? - virtual ~GoogleDriveResolveIdRequest(); - - virtual void handle(); - virtual void restart(); -}; - -} // End of namespace GoogleDrive -} // End of namespace Cloud - -#endif diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index 327c9ee8eb..eeae2f2ee3 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -24,20 +24,15 @@ #include "backends/cloud/googledrive/googledrivestorage.h" #include "backends/cloud/cloudmanager.h" #include "backends/cloud/googledrive/googledrivetokenrefresher.h" +#include "backends/cloud/googledrive/googledrivelistdirectorybyidrequest.h" +#include "backends/cloud/googledrive/googledriveuploadrequest.h" #include "backends/networking/curl/connectionmanager.h" #include "backends/networking/curl/curljsonrequest.h" #include "backends/networking/curl/networkreadstream.h" +#include "common/config-manager.h" #include "common/debug.h" #include "common/json.h" #include <curl/curl.h> -#include "googledrivelistdirectorybyidrequest.h" -#include "googledriveresolveidrequest.h" -#include "googledrivecreatedirectoryrequest.h" -#include "googledrivelistdirectoryrequest.h" -#include "googledrivestreamfilerequest.h" -#include "googledrivedownloadrequest.h" -#include "googledriveuploadrequest.h" -#include "common/config-manager.h" namespace Cloud { namespace GoogleDrive { @@ -198,29 +193,6 @@ void GoogleDriveStorage::createDirectoryInnerCallback(BoolCallback outerCallback delete json; } -void GoogleDriveStorage::printJson(Networking::JsonResponse response) { - Common::JSONValue *json = response.value; - if (!json) { - warning("printJson: NULL"); - return; - } - - debug("%s", json->stringify().c_str()); - delete json; -} - -Networking::Request *GoogleDriveStorage::resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback) { - if (!errorCallback) errorCallback = getErrorPrintingCallback(); - if (!callback) callback = new Common::Callback<GoogleDriveStorage, UploadResponse>(this, &GoogleDriveStorage::printFile); - return addRequest(new GoogleDriveResolveIdRequest(this, path, callback, errorCallback)); -} - -Networking::Request *GoogleDriveStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) { - if (!errorCallback) errorCallback = getErrorPrintingCallback(); - if (!callback) callback = new Common::Callback<GoogleDriveStorage, FileArrayResponse>(this, &GoogleDriveStorage::printFiles); - return addRequest(new GoogleDriveListDirectoryRequest(this, path, callback, errorCallback, recursive)); -} - Networking::Request *GoogleDriveStorage::listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback) { if (!errorCallback) errorCallback = getErrorPrintingCallback(); if (!callback) callback = new Common::Callback<GoogleDriveStorage, FileArrayResponse>(this, &GoogleDriveStorage::printFiles); @@ -231,10 +203,6 @@ Networking::Request *GoogleDriveStorage::upload(Common::String path, Common::See return addRequest(new GoogleDriveUploadRequest(this, path, contents, callback, errorCallback)); } -Networking::Request *GoogleDriveStorage::streamFile(Common::String path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) { - return addRequest(new GoogleDriveStreamFileRequest(this, path, outerCallback, errorCallback)); -} - Networking::Request *GoogleDriveStorage::streamFileById(Common::String id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) { if (callback) { Common::String url = "https://www.googleapis.com/drive/v3/files/" + ConnMan.urlEncode(id) + "?alt=media"; @@ -248,38 +216,11 @@ Networking::Request *GoogleDriveStorage::streamFileById(Common::String id, Netwo return nullptr; } -Networking::Request *GoogleDriveStorage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) { - return addRequest(new GoogleDriveDownloadRequest(this, remotePath, localPath, callback, errorCallback)); -} - void GoogleDriveStorage::fileDownloaded(BoolResponse response) { if (response.value) debug("file downloaded!"); else debug("download failed!"); } -void GoogleDriveStorage::printFiles(FileArrayResponse response) { - debug("files:"); - Common::Array<StorageFile> &files = response.value; - for (uint32 i = 0; i < files.size(); ++i) { - debug("\t%s%s", files[i].name().c_str(), files[i].isDirectory() ? " (directory)" : ""); - debug("\t%s", files[i].path().c_str()); - debug("\t%s", files[i].id().c_str()); - debug(" "); - } -} - -void GoogleDriveStorage::printBool(BoolResponse response) { - debug("bool: %s", response.value ? "true" : "false"); -} - -void GoogleDriveStorage::printFile(UploadResponse response) { - debug("\nuploaded file info:"); - debug("\tid: %s", response.value.path().c_str()); - debug("\tname: %s", response.value.name().c_str()); - debug("\tsize: %u", response.value.size()); - debug("\ttimestamp: %u", response.value.timestamp()); -} - void GoogleDriveStorage::printInfo(StorageInfoResponse response) { debug("\nuser info:"); debug("\tname: %s", response.value.name().c_str()); @@ -287,24 +228,6 @@ void GoogleDriveStorage::printInfo(StorageInfoResponse response) { debug("\tdisk usage: %llu/%llu", response.value.used(), response.value.available()); } -Networking::Request *GoogleDriveStorage::createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { - if (!errorCallback) errorCallback = getErrorPrintingCallback(); - if (!callback) callback = new Common::Callback<GoogleDriveStorage, BoolResponse>(this, &GoogleDriveStorage::printBool); - - //find out the parent path and directory name - Common::String parentPath = "", directoryName = path; - for (uint32 i = path.size(); i > 0; --i) { - if (path[i-1] == '/' || path[i-1] == '\\') { - parentPath = path; - parentPath.erase(i-1); - directoryName.erase(0, i); - break; - } - } - - return addRequest(new GoogleDriveCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback)); -} - Networking::Request *GoogleDriveStorage::createDirectoryWithParentId(Common::String parentId, Common::String name, BoolCallback callback, Networking::ErrorCallback errorCallback) { if (!errorCallback) errorCallback = getErrorPrintingCallback(); @@ -366,6 +289,11 @@ Common::String GoogleDriveStorage::getAuthLink() { return url; } +Common::String GoogleDriveStorage::getRootDirectoryId() { + return "root"; +} + + void GoogleDriveStorage::authThroughConsole() { if (!ConfMan.hasKey("GOOGLE_DRIVE_KEY", ConfMan.kCloudDomain) || !ConfMan.hasKey("GOOGLE_DRIVE_SECRET", ConfMan.kCloudDomain)) { warning("No Google Drive keys available, cannot do auth"); diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h index 8093ef1938..435f9998a3 100644 --- a/backends/cloud/googledrive/googledrivestorage.h +++ b/backends/cloud/googledrive/googledrivestorage.h @@ -23,14 +23,14 @@ #ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTORAGE_H #define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTORAGE_H -#include "backends/cloud/storage.h" +#include "backends/cloud/id/idstorage.h" #include "common/callback.h" #include "backends/networking/curl/curljsonrequest.h" namespace Cloud { namespace GoogleDrive { -class GoogleDriveStorage: public Cloud::Storage { +class GoogleDriveStorage: public Id::IdStorage { static char *KEY, *SECRET; static void loadKeyAndSecret(); @@ -49,11 +49,7 @@ class GoogleDriveStorage: public Cloud::Storage { /** Returns bool based on JSON response from cloud. */ void createDirectoryInnerCallback(BoolCallback outerCallback, Networking::JsonResponse json); - void printJson(Networking::JsonResponse response); void fileDownloaded(BoolResponse response); - void printFiles(FileArrayResponse response); - void printBool(BoolResponse response); - void printFile(UploadResponse response); void printInfo(StorageInfoResponse response); public: /** This constructor uses OAuth code flow to get tokens. */ @@ -81,12 +77,6 @@ public: /** Public Cloud API comes down there. */ - /** Returns StorageFile with the resolved file's id. */ - virtual Networking::Request *resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback); - - /** Returns Array<StorageFile> - the list of files. */ - virtual Networking::Request *listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false); - /** Returns Array<StorageFile> - the list of files. */ virtual Networking::Request *listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback); @@ -94,19 +84,12 @@ public: virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback); /** Returns pointer to Networking::NetworkReadStream. */ - 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); /** Calls the callback when finished. */ - virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback); - - /** Calls the callback when finished. */ virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO /** Calls the callback when finished. */ - virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback); - - /** Calls the callback when finished. */ virtual Networking::Request *createDirectoryWithParentId(Common::String parentId, Common::String name, BoolCallback callback, Networking::ErrorCallback errorCallback); /** Returns the StorageInfo struct. */ @@ -126,6 +109,8 @@ public: */ static Common::String getAuthLink(); + virtual Common::String getRootDirectoryId(); + /** * Show message with GoogleDrive auth instructions. (Temporary) */ diff --git a/backends/cloud/googledrive/googledrivestreamfilerequest.cpp b/backends/cloud/googledrive/googledrivestreamfilerequest.cpp deleted file mode 100644 index 424e52c6cb..0000000000 --- a/backends/cloud/googledrive/googledrivestreamfilerequest.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* 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. -* -*/ - -#include "backends/cloud/googledrive/googledrivestreamfilerequest.h" -#include "backends/cloud/googledrive/googledrivestorage.h" - -namespace Cloud { -namespace GoogleDrive { - -GoogleDriveStreamFileRequest::GoogleDriveStreamFileRequest(GoogleDriveStorage *storage, Common::String path, Networking::NetworkReadStreamCallback cb, Networking::ErrorCallback ecb): - Networking::Request(nullptr, ecb), _requestedFile(path), _storage(storage), _streamCallback(cb), - _workingRequest(nullptr), _ignoreCallback(false) { - start(); -} - -GoogleDriveStreamFileRequest::~GoogleDriveStreamFileRequest() { - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - delete _streamCallback; -} - -void GoogleDriveStreamFileRequest::start() { - //cleanup - _ignoreCallback = true; - if (_workingRequest) _workingRequest->finish(); - _workingRequest = nullptr; - _ignoreCallback = false; - - //find file's id - Storage::UploadCallback innerCallback = new Common::Callback<GoogleDriveStreamFileRequest, Storage::UploadResponse>(this, &GoogleDriveStreamFileRequest::idResolvedCallback); - Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveStreamFileRequest, Networking::ErrorResponse>(this, &GoogleDriveStreamFileRequest::idResolveFailedCallback); - _workingRequest = _storage->resolveFileId(_requestedFile, innerCallback, innerErrorCallback); -} - -void GoogleDriveStreamFileRequest::idResolvedCallback(Storage::UploadResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - - Networking::NetworkReadStreamCallback innerCallback = new Common::Callback<GoogleDriveStreamFileRequest, Networking::NetworkReadStreamResponse>(this, &GoogleDriveStreamFileRequest::streamFileCallback); - Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveStreamFileRequest, Networking::ErrorResponse>(this, &GoogleDriveStreamFileRequest::streamFileErrorCallback); - _workingRequest = _storage->streamFileById(response.value.id(), innerCallback, innerErrorCallback); -} - -void GoogleDriveStreamFileRequest::idResolveFailedCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishError(error); -} - -void GoogleDriveStreamFileRequest::streamFileCallback(Networking::NetworkReadStreamResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishStream(response.value); -} - -void GoogleDriveStreamFileRequest::streamFileErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - finishError(error); -} - -void GoogleDriveStreamFileRequest::handle() {} - -void GoogleDriveStreamFileRequest::restart() { start(); } - -void GoogleDriveStreamFileRequest::finishStream(Networking::NetworkReadStream *stream) { - Request::finishSuccess(); - if (_streamCallback) (*_streamCallback)(Networking::NetworkReadStreamResponse(this, stream)); -} - -} // End of namespace GoogleDrive -} // End of namespace Cloud diff --git a/backends/cloud/googledrive/googledrivestreamfilerequest.h b/backends/cloud/googledrive/googledrivestreamfilerequest.h deleted file mode 100644 index aa5596154e..0000000000 --- a/backends/cloud/googledrive/googledrivestreamfilerequest.h +++ /dev/null @@ -1,59 +0,0 @@ -/* 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. -* -*/ - -#ifndef BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTREAMFILEREQUEST_H -#define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTREAMFILEREQUEST_H - -#include "backends/cloud/storage.h" -#include "backends/networking/curl/request.h" -#include "common/callback.h" - -namespace Cloud { -namespace GoogleDrive { - -class GoogleDriveStorage; - -class GoogleDriveStreamFileRequest: public Networking::Request { - Common::String _requestedFile; - GoogleDriveStorage *_storage; - Networking::NetworkReadStreamCallback _streamCallback; - Request *_workingRequest; - bool _ignoreCallback; - - void start(); - void idResolvedCallback(Storage::UploadResponse response); - void idResolveFailedCallback(Networking::ErrorResponse error); - void streamFileCallback(Networking::NetworkReadStreamResponse response); - void streamFileErrorCallback(Networking::ErrorResponse error); - void finishStream(Networking::NetworkReadStream *stream); -public: - GoogleDriveStreamFileRequest(GoogleDriveStorage *storage, Common::String path, Networking::NetworkReadStreamCallback cb, Networking::ErrorCallback ecb); - virtual ~GoogleDriveStreamFileRequest(); - - virtual void handle(); - virtual void restart(); -}; - -} // End of namespace GoogleDrive -} // End of namespace Cloud - -#endif diff --git a/backends/cloud/googledrive/googledriveuploadrequest.cpp b/backends/cloud/googledrive/googledriveuploadrequest.cpp index d9ba2815e0..ce7d59a50c 100644 --- a/backends/cloud/googledrive/googledriveuploadrequest.cpp +++ b/backends/cloud/googledrive/googledriveuploadrequest.cpp @@ -198,11 +198,15 @@ void GoogleDriveUploadRequest::uploadNextPart() { byte *buffer = new byte[UPLOAD_PER_ONE_REQUEST]; uint32 size = _contentsStream->read(buffer, UPLOAD_PER_ONE_REQUEST); - request->setBuffer(buffer, size); + if (size != 0) request->setBuffer(buffer, size); //request->addHeader(Common::String::format("Content-Length: %u", size)); - if (_uploadUrl != "") - request->addHeader(Common::String::format("Content-Range: bytes %u-%u/%u", oldPos, _contentsStream->pos()-1, _contentsStream->size())); ; + if (_uploadUrl != "") { + if (_contentsStream->pos() == 0) + request->addHeader(Common::String::format("Content-Length: 0")); + else + request->addHeader(Common::String::format("Content-Range: bytes %u-%u/%u", oldPos, _contentsStream->pos() - 1, _contentsStream->size())); + } _workingRequest = ConnMan.addRequest(request); } diff --git a/backends/module.mk b/backends/module.mk index 2d0a61bba5..1881cc2f59 100644 --- a/backends/module.mk +++ b/backends/module.mk @@ -36,13 +36,8 @@ MODULE_OBJS += \ cloud/dropbox/dropboxcreatedirectoryrequest.o \ cloud/dropbox/dropboxlistdirectoryrequest.o \ cloud/dropbox/dropboxuploadrequest.o \ - cloud/googledrive/googledrivecreatedirectoryrequest.o \ - cloud/googledrive/googledrivedownloadrequest.o \ cloud/googledrive/googledrivelistdirectorybyidrequest.o \ - cloud/googledrive/googledrivelistdirectoryrequest.o \ - cloud/googledrive/googledriveresolveidrequest.o \ cloud/googledrive/googledrivestorage.o \ - cloud/googledrive/googledrivestreamfilerequest.o \ cloud/googledrive/googledrivetokenrefresher.o \ cloud/googledrive/googledriveuploadrequest.o \ cloud/id/idstorage.o \ |