From b180c73675846f45abab2190b39e0b9d0d6addbf Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 20 Jul 2016 18:47:34 +0600 Subject: CLOUD: Do some refactoring/cleanup Nothing really major. --- backends/cloud/box/boxstorage.cpp | 4 +- backends/cloud/box/boxstorage.h | 2 +- backends/cloud/box/boxtokenrefresher.cpp | 6 +-- backends/cloud/box/boxuploadrequest.cpp | 1 - backends/cloud/cloudmanager.cpp | 44 +++++++++------------- backends/cloud/cloudmanager.h | 41 +++++++++----------- backends/cloud/downloadrequest.cpp | 1 - backends/cloud/dropbox/dropboxstorage.cpp | 4 +- backends/cloud/dropbox/dropboxuploadrequest.cpp | 2 +- backends/cloud/folderdownloadrequest.cpp | 2 +- backends/cloud/folderdownloadrequest.h | 5 +-- backends/cloud/googledrive/googledrivestorage.cpp | 12 +++--- backends/cloud/googledrive/googledrivestorage.h | 6 +-- .../googledrive/googledrivetokenrefresher.cpp | 6 +-- .../cloud/googledrive/googledriveuploadrequest.cpp | 2 - backends/cloud/id/idstorage.cpp | 22 +++++------ backends/cloud/onedrive/onedrivestorage.cpp | 12 +++--- backends/cloud/onedrive/onedrivestorage.h | 2 +- backends/cloud/onedrive/onedrivetokenrefresher.cpp | 6 +-- backends/cloud/onedrive/onedriveuploadrequest.cpp | 3 +- backends/cloud/savessyncrequest.cpp | 32 ++++++---------- backends/cloud/savessyncrequest.h | 4 +- backends/cloud/storage.cpp | 4 +- backends/cloud/storage.h | 10 +++-- base/main.cpp | 1 - 25 files changed, 101 insertions(+), 133 deletions(-) diff --git a/backends/cloud/box/boxstorage.cpp b/backends/cloud/box/boxstorage.cpp index 8162af299c..c31c72b49f 100644 --- a/backends/cloud/box/boxstorage.cpp +++ b/backends/cloud/box/boxstorage.cpp @@ -278,12 +278,12 @@ BoxStorage *BoxStorage::loadFromConfig(Common::String keyPrefix) { if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); - return 0; + return nullptr; } if (!ConfMan.hasKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain)) { warning("No refresh_token found"); - return 0; + return nullptr; } Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); diff --git a/backends/cloud/box/boxstorage.h b/backends/cloud/box/boxstorage.h index 826d6bef4e..1373c2fbeb 100644 --- a/backends/cloud/box/boxstorage.h +++ b/backends/cloud/box/boxstorage.h @@ -111,7 +111,7 @@ public: */ void getAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback = nullptr, Common::String code = ""); - Common::String accessToken() { return _token; } + Common::String accessToken() const { return _token; } }; } // End of namespace Box diff --git a/backends/cloud/box/boxtokenrefresher.cpp b/backends/cloud/box/boxtokenrefresher.cpp index 9dfbef537f..f100e186be 100644 --- a/backends/cloud/box/boxtokenrefresher.cpp +++ b/backends/cloud/box/boxtokenrefresher.cpp @@ -69,7 +69,7 @@ void BoxTokenRefresher::finishJson(Common::JSONValue *json) { long httpCode = -1; if (_stream) { httpCode = _stream->httpResponseCode(); - debug("code %ld", httpCode); + debug(9, "code %ld", httpCode); } bool irrecoverable = true; @@ -77,12 +77,12 @@ void BoxTokenRefresher::finishJson(Common::JSONValue *json) { Common::String code, message; if (result.contains("code")) { code = result.getVal("code")->asString(); - debug("code = %s", code.c_str()); + debug(9, "code = %s", code.c_str()); } if (result.contains("message")) { message = result.getVal("message")->asString(); - debug("message = %s", message.c_str()); + debug(9, "message = %s", message.c_str()); } //TODO: decide when token refreshment will help diff --git a/backends/cloud/box/boxuploadrequest.cpp b/backends/cloud/box/boxuploadrequest.cpp index c94494efac..c81a3ab439 100644 --- a/backends/cloud/box/boxuploadrequest.cpp +++ b/backends/cloud/box/boxuploadrequest.cpp @@ -29,7 +29,6 @@ #include "backends/networking/curl/curljsonrequest.h" #include "backends/networking/curl/networkreadstream.h" #include "common/json.h" -#include "common/debug.h" namespace Cloud { namespace Box { diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index 3e1c94f909..55dbb2b42d 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -25,7 +25,6 @@ #include "backends/cloud/dropbox/dropboxstorage.h" #include "backends/cloud/onedrive/onedrivestorage.h" #include "backends/cloud/googledrive/googledrivestorage.h" -#include "common/debug.h" #include "common/translation.h" #include "common/config-manager.h" #include "common/str.h" @@ -243,10 +242,6 @@ void CloudManager::connectStorage(uint32 index, Common::String code) { // thus, no memory leak happens } -void CloudManager::printBool(Storage::BoolResponse response) const { - debug("bool = %s", (response.value ? "true" : "false")); -} - Networking::Request *CloudManager::listDirectory(Common::String path, Storage::ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) { Storage *storage = getCurrentStorage(); if (storage) return storage->listDirectory(path, callback, errorCallback, recursive); @@ -295,12 +290,7 @@ SavesSyncRequest *CloudManager::syncSaves(Storage::BoolCallback callback, Networ return nullptr; } -void CloudManager::testFeature() { - //Storage *storage = getCurrentStorage(); - //if (storage) storage->info(nullptr, nullptr); -} - -bool CloudManager::isWorking() { +bool CloudManager::isWorking() const { Storage *storage = getCurrentStorage(); if (storage) return storage->isWorking(); return false; @@ -308,95 +298,95 @@ bool CloudManager::isWorking() { ///// SavesSyncRequest-related ///// -bool CloudManager::isSyncing() { +bool CloudManager::isSyncing() const { Storage *storage = getCurrentStorage(); if (storage) return storage->isSyncing(); return false; } -double CloudManager::getSyncDownloadingProgress() { +double CloudManager::getSyncDownloadingProgress() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getSyncDownloadingProgress(); return 1; } -double CloudManager::getSyncProgress() { +double CloudManager::getSyncProgress() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getSyncProgress(); return 1; } -Common::Array CloudManager::getSyncingFiles() { +Common::Array CloudManager::getSyncingFiles() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getSyncingFiles(); return Common::Array(); } -void CloudManager::cancelSync() { +void CloudManager::cancelSync() const { Storage *storage = getCurrentStorage(); if (storage) storage->cancelSync(); } -void CloudManager::setSyncTarget(GUI::CommandReceiver *target) { +void CloudManager::setSyncTarget(GUI::CommandReceiver *target) const { Storage *storage = getCurrentStorage(); if (storage) storage->setSyncTarget(target); } ///// DownloadFolderRequest-related ///// -bool CloudManager::startDownload(Common::String remotePath, Common::String localPath) { +bool CloudManager::startDownload(Common::String remotePath, Common::String localPath) const { Storage *storage = getCurrentStorage(); if (storage) return storage->startDownload(remotePath, localPath); return false; } -void CloudManager::cancelDownload() { +void CloudManager::cancelDownload() const { Storage *storage = getCurrentStorage(); if (storage) storage->cancelDownload(); } -void CloudManager::setDownloadTarget(GUI::CommandReceiver *target) { +void CloudManager::setDownloadTarget(GUI::CommandReceiver *target) const { Storage *storage = getCurrentStorage(); if (storage) storage->setDownloadTarget(target); } -bool CloudManager::isDownloading() { +bool CloudManager::isDownloading() const { Storage *storage = getCurrentStorage(); if (storage) return storage->isDownloading(); return false; } -double CloudManager::getDownloadingProgress() { +double CloudManager::getDownloadingProgress() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getDownloadingProgress(); return 1; } -uint64 CloudManager::getDownloadBytesNumber() { +uint64 CloudManager::getDownloadBytesNumber() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getDownloadBytesNumber(); return 0; } -uint64 CloudManager::getDownloadTotalBytesNumber() { +uint64 CloudManager::getDownloadTotalBytesNumber() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getDownloadTotalBytesNumber(); return 0; } -uint64 CloudManager::getDownloadSpeed() { +uint64 CloudManager::getDownloadSpeed() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getDownloadSpeed(); return 0; } -Common::String CloudManager::getDownloadRemoteDirectory() { +Common::String CloudManager::getDownloadRemoteDirectory() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getDownloadRemoteDirectory(); return ""; } -Common::String CloudManager::getDownloadLocalDirectory() { +Common::String CloudManager::getDownloadLocalDirectory() const { Storage *storage = getCurrentStorage(); if (storage) return storage->getDownloadLocalDirectory(); return ""; diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index 4442b9bfbe..2941ea6331 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -61,8 +61,6 @@ class CloudManager : public Common::Singleton { Storage *_activeStorage; Common::Array _storagesToRemove; - void printBool(Cloud::Storage::BoolResponse response) const; - void loadStorage(); Common::String getStorageConfigName(uint32 index) const; @@ -206,65 +204,60 @@ public: */ SavesSyncRequest *syncSaves(Cloud::Storage::BoolCallback callback = nullptr, Networking::ErrorCallback errorCallback = nullptr); - /** - * Starts feature testing (the one I'm working on currently). (Temporary) - */ - void testFeature(); - /** Returns whether there are any requests running. */ - bool isWorking(); + bool isWorking() const; ///// SavesSyncRequest-related ///// /** Returns whether there is a SavesSyncRequest running. */ - bool isSyncing(); + bool isSyncing() const; /** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */ - double getSyncDownloadingProgress(); + double getSyncDownloadingProgress() const; /** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */ - double getSyncProgress(); + double getSyncProgress() const; /** Returns an array of saves names which are not yet synced (thus cannot be used). */ - Common::Array getSyncingFiles(); + Common::Array getSyncingFiles() const; /** Cancels running sync. */ - void cancelSync(); + void cancelSync() const; /** Sets SavesSyncRequest's target to given CommandReceiver. */ - void setSyncTarget(GUI::CommandReceiver *target); + void setSyncTarget(GUI::CommandReceiver *target) const; ///// DownloadFolderRequest-related ///// /** Starts a folder download. */ - bool startDownload(Common::String remotePath, Common::String localPath); + bool startDownload(Common::String remotePath, Common::String localPath) const; /** Cancels running download. */ - void cancelDownload(); + void cancelDownload() const; /** Sets FolderDownloadRequest's target to given CommandReceiver. */ - void setDownloadTarget(GUI::CommandReceiver *target); + void setDownloadTarget(GUI::CommandReceiver *target) const; /** Returns whether there is a FolderDownloadRequest running. */ - bool isDownloading(); + bool isDownloading() const; /** Returns a number in [0, 1] range which represents current download progress (1 = complete). */ - double getDownloadingProgress(); + double getDownloadingProgress() const; /** Returns a number of bytes that is downloaded in current download progress. */ - uint64 getDownloadBytesNumber(); + uint64 getDownloadBytesNumber() const; /** Returns a total number of bytes to be downloaded in current download progress. */ - uint64 getDownloadTotalBytesNumber(); + uint64 getDownloadTotalBytesNumber() const; /** Returns download speed of current download progress. */ - uint64 getDownloadSpeed(); + uint64 getDownloadSpeed() const; /** Returns remote directory path. */ - virtual Common::String getDownloadRemoteDirectory(); + Common::String getDownloadRemoteDirectory() const; /** Returns local directory path. */ - virtual Common::String getDownloadLocalDirectory(); + Common::String getDownloadLocalDirectory() const; }; /** Shortcut for accessing the connection manager. */ diff --git a/backends/cloud/downloadrequest.cpp b/backends/cloud/downloadrequest.cpp index 5efb87e0c8..e8c410ae3e 100644 --- a/backends/cloud/downloadrequest.cpp +++ b/backends/cloud/downloadrequest.cpp @@ -22,7 +22,6 @@ #include "backends/cloud/downloadrequest.h" #include "backends/networking/curl/connectionmanager.h" -#include "common/debug.h" #include "common/textconsole.h" namespace Cloud { diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index d7aea012af..7e3521f40e 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -155,12 +155,12 @@ DropboxStorage *DropboxStorage::loadFromConfig(Common::String keyPrefix) { if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); - return 0; + return nullptr; } if (!ConfMan.hasKey(keyPrefix + "user_id", ConfMan.kCloudDomain)) { warning("No user_id found"); - return 0; + return nullptr; } Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); diff --git a/backends/cloud/dropbox/dropboxuploadrequest.cpp b/backends/cloud/dropbox/dropboxuploadrequest.cpp index ee6f665665..29b7f60c8a 100644 --- a/backends/cloud/dropbox/dropboxuploadrequest.cpp +++ b/backends/cloud/dropbox/dropboxuploadrequest.cpp @@ -118,7 +118,7 @@ void DropboxUploadRequest::uploadNextPart() { } void DropboxUploadRequest::partUploadedCallback(Networking::JsonResponse response) { - debug("partUploadedCallback"); + debug(9, "partUploadedCallback"); _workingRequest = nullptr; if (_ignoreCallback) return; diff --git a/backends/cloud/folderdownloadrequest.cpp b/backends/cloud/folderdownloadrequest.cpp index d506d80c48..9e05202bf7 100644 --- a/backends/cloud/folderdownloadrequest.cpp +++ b/backends/cloud/folderdownloadrequest.cpp @@ -132,7 +132,7 @@ void FolderDownloadRequest::downloadNextFile() { else localPath = _localDirectoryPath + "/" + localPath; } - debug("%s -> %s", remotePath.c_str(), localPath.c_str()); + debug(9, "%s -> %s", remotePath.c_str(), localPath.c_str()); _workingRequest = _storage->downloadById( _currentFile.id(), localPath, new Common::Callback(this, &FolderDownloadRequest::fileDownloadedCallback), diff --git a/backends/cloud/folderdownloadrequest.h b/backends/cloud/folderdownloadrequest.h index 9d8dea4d20..08fa193e07 100644 --- a/backends/cloud/folderdownloadrequest.h +++ b/backends/cloud/folderdownloadrequest.h @@ -24,7 +24,6 @@ #define BACKENDS_CLOUD_FOLDERDOWNLOADREQUEST_H #include "backends/networking/curl/request.h" -#include "backends/networking/curl/networkreadstream.h" #include "backends/cloud/storage.h" #include "gui/object.h" @@ -69,10 +68,10 @@ public: uint64 getDownloadSpeed() const; /** Returns remote directory path. */ - Common::String getRemotePath() { return _remoteDirectoryPath; } + Common::String getRemotePath() const { return _remoteDirectoryPath; } /** Returns local directory path. */ - Common::String getLocalPath() { return _localDirectoryPath; } + Common::String getLocalPath() const { return _localDirectoryPath; } }; } // End of namespace Cloud diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index c4264099fd..77ac8989f1 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -229,10 +229,10 @@ Networking::Request *GoogleDriveStorage::streamFileById(Common::String id, Netwo } void GoogleDriveStorage::printInfo(StorageInfoResponse response) { - debug("\nuser info:"); - debug("\tname: %s", response.value.name().c_str()); - debug("\temail: %s", response.value.email().c_str()); - debug("\tdisk usage: %llu/%llu", response.value.used(), response.value.available()); + debug(9, "\nuser info:"); + debug(9, "\tname: %s", response.value.name().c_str()); + debug(9, "\temail: %s", response.value.email().c_str()); + debug(9, "\tdisk usage: %llu/%llu", response.value.used(), response.value.available()); } Networking::Request *GoogleDriveStorage::createDirectoryWithParentId(Common::String parentId, Common::String name, BoolCallback callback, Networking::ErrorCallback errorCallback) { @@ -273,12 +273,12 @@ GoogleDriveStorage *GoogleDriveStorage::loadFromConfig(Common::String keyPrefix) if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); - return 0; + return nullptr; } if (!ConfMan.hasKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain)) { warning("No refresh_token found"); - return 0; + return nullptr; } Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h index eee4de90b0..4c164dd91d 100644 --- a/backends/cloud/googledrive/googledrivestorage.h +++ b/backends/cloud/googledrive/googledrivestorage.h @@ -24,7 +24,6 @@ #define BACKENDS_CLOUD_GOOGLEDRIVE_GOOGLEDRIVESTORAGE_H #include "backends/cloud/id/idstorage.h" -#include "common/callback.h" #include "backends/networking/curl/curljsonrequest.h" namespace Cloud { @@ -86,9 +85,6 @@ public: /** Returns pointer to Networking::NetworkReadStream. */ virtual Networking::Request *streamFileById(Common::String id, Networking::NetworkReadStreamCallback 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 *createDirectoryWithParentId(Common::String parentId, Common::String name, BoolCallback callback, Networking::ErrorCallback errorCallback); @@ -113,7 +109,7 @@ public: */ void getAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback = nullptr, Common::String code = ""); - Common::String accessToken() { return _token; } + Common::String accessToken() const { return _token; } }; } // End of namespace GoogleDrive diff --git a/backends/cloud/googledrive/googledrivetokenrefresher.cpp b/backends/cloud/googledrive/googledrivetokenrefresher.cpp index 3dfb8436e9..9e26e62149 100644 --- a/backends/cloud/googledrive/googledrivetokenrefresher.cpp +++ b/backends/cloud/googledrive/googledrivetokenrefresher.cpp @@ -67,7 +67,7 @@ void GoogleDriveTokenRefresher::finishJson(Common::JSONValue *json) { if (result.contains("error")) { //new token needed => request token & then retry original request if (_stream) { - debug("code %ld", _stream->httpResponseCode()); + debug(9, "code %ld", _stream->httpResponseCode()); } Common::JSONObject error = result.getVal("error")->asObject(); @@ -77,12 +77,12 @@ void GoogleDriveTokenRefresher::finishJson(Common::JSONValue *json) { Common::String message; if (error.contains("code") && error.getVal("code")->isIntegerNumber()) { code = error.getVal("code")->asIntegerNumber(); - debug("code = %u", code); + debug(9, "code = %u", code); } if (error.contains("message")) { message = error.getVal("message")->asString(); - debug("message = %s", message.c_str()); + debug(9, "message = %s", message.c_str()); } if (code == 401 || message == "Invalid Credentials") diff --git a/backends/cloud/googledrive/googledriveuploadrequest.cpp b/backends/cloud/googledrive/googledriveuploadrequest.cpp index dfff46c0d2..b63e989df8 100644 --- a/backends/cloud/googledrive/googledriveuploadrequest.cpp +++ b/backends/cloud/googledrive/googledriveuploadrequest.cpp @@ -28,7 +28,6 @@ #include "backends/networking/curl/curljsonrequest.h" #include "backends/networking/curl/networkreadstream.h" #include "common/json.h" -#include "common/debug.h" #include "googledrivetokenrefresher.h" namespace Cloud { @@ -201,7 +200,6 @@ void GoogleDriveUploadRequest::uploadNextPart() { uint32 size = _contentsStream->read(buffer, UPLOAD_PER_ONE_REQUEST); if (size != 0) request->setBuffer(buffer, size); - //request->addHeader(Common::String::format("Content-Length: %u", size)); if (_uploadUrl != "") { if (_contentsStream->pos() == 0) request->addHeader(Common::String::format("Content-Length: 0")); diff --git a/backends/cloud/id/idstorage.cpp b/backends/cloud/id/idstorage.cpp index 28f880522e..5b0f9db347 100644 --- a/backends/cloud/id/idstorage.cpp +++ b/backends/cloud/id/idstorage.cpp @@ -36,26 +36,26 @@ namespace Id { IdStorage::~IdStorage() {} void IdStorage::printFiles(FileArrayResponse response) { - debug("files:"); + debug(9, "files:"); Common::Array &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(" "); + debug(9, "\t%s%s", files[i].name().c_str(), files[i].isDirectory() ? " (directory)" : ""); + debug(9, "\t%s", files[i].path().c_str()); + debug(9, "\t%s", files[i].id().c_str()); + debug(9, " "); } } void IdStorage::printBool(BoolResponse response) { - debug("bool: %s", response.value ? "true" : "false"); + debug(9, "bool: %s", response.value ? "true" : "false"); } void IdStorage::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()); + debug(9, "\nuploaded file info:"); + debug(9, "\tid: %s", response.value.path().c_str()); + debug(9, "\tname: %s", response.value.name().c_str()); + debug(9, "\tsize: %u", response.value.size()); + debug(9, "\ttimestamp: %u", response.value.timestamp()); } Storage::ListDirectoryCallback IdStorage::getPrintFilesCallback() { diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index e9165943af..39213e82ed 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -189,7 +189,7 @@ void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Netwo void OneDriveStorage::fileInfoCallback(Networking::NetworkReadStreamCallback outerCallback, Networking::JsonResponse response) { if (!response.value) { warning("fileInfoCallback: NULL"); - if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, 0)); + if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, nullptr)); return; } @@ -199,12 +199,12 @@ void OneDriveStorage::fileInfoCallback(Networking::NetworkReadStreamCallback out if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse( response.request, - new Networking::NetworkReadStream(url, 0, "") + new Networking::NetworkReadStream(url, nullptr, "") )); } else { warning("downloadUrl not found in passed JSON"); debug("%s", response.value->stringify().c_str()); - if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, 0)); + if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, nullptr)); } delete response.value; } @@ -244,17 +244,17 @@ OneDriveStorage *OneDriveStorage::loadFromConfig(Common::String keyPrefix) { if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); - return 0; + return nullptr; } if (!ConfMan.hasKey(keyPrefix + "user_id", ConfMan.kCloudDomain)) { warning("No user_id found"); - return 0; + return nullptr; } if (!ConfMan.hasKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain)) { warning("No refresh_token found"); - return 0; + return nullptr; } Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h index 8ceaaf107e..60817e6084 100644 --- a/backends/cloud/onedrive/onedrivestorage.h +++ b/backends/cloud/onedrive/onedrivestorage.h @@ -104,7 +104,7 @@ public: */ void getAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback = nullptr, Common::String code = ""); - Common::String accessToken() { return _token; } + Common::String accessToken() const { return _token; } }; } // End of namespace OneDrive diff --git a/backends/cloud/onedrive/onedrivetokenrefresher.cpp b/backends/cloud/onedrive/onedrivetokenrefresher.cpp index 04e155c084..9afea3d5bd 100644 --- a/backends/cloud/onedrive/onedrivetokenrefresher.cpp +++ b/backends/cloud/onedrive/onedrivetokenrefresher.cpp @@ -67,7 +67,7 @@ void OneDriveTokenRefresher::finishJson(Common::JSONValue *json) { if (result.contains("error")) { //new token needed => request token & then retry original request if (_stream) { - debug("code %ld", _stream->httpResponseCode()); + debug(9, "code %ld", _stream->httpResponseCode()); } Common::JSONObject error = result.getVal("error")->asObject(); @@ -76,12 +76,12 @@ void OneDriveTokenRefresher::finishJson(Common::JSONValue *json) { Common::String code, message; if (error.contains("code")) { code = error.getVal("code")->asString(); - debug("code = %s", code.c_str()); + debug(9, "code = %s", code.c_str()); } if (error.contains("message")) { message = error.getVal("message")->asString(); - debug("message = %s", message.c_str()); + debug(9, "message = %s", message.c_str()); } //determine whether token refreshing would help in this situation diff --git a/backends/cloud/onedrive/onedriveuploadrequest.cpp b/backends/cloud/onedrive/onedriveuploadrequest.cpp index 500f875b9d..569809d16b 100644 --- a/backends/cloud/onedrive/onedriveuploadrequest.cpp +++ b/backends/cloud/onedrive/onedriveuploadrequest.cpp @@ -28,7 +28,6 @@ #include "backends/networking/curl/curljsonrequest.h" #include "backends/networking/curl/networkreadstream.h" #include "common/json.h" -#include "common/debug.h" #include "onedrivetokenrefresher.h" namespace Cloud { @@ -135,7 +134,7 @@ void OneDriveUploadRequest::partUploadedCallback(Networking::JsonResponse respon if (object.contains("id") && object.contains("name")) { //finished - Common::String path = _savePath; //object.getVal("name")->asString();; //object.getVal("id")->asString(); + Common::String path = _savePath; uint32 size = object.getVal("size")->asIntegerNumber(); uint32 timestamp = ISO8601::convertToTimestamp(object.getVal("lastModifiedDateTime")->asString()); finishUpload(StorageFile(path, size, timestamp, false)); diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp index 32b22edcaa..014e6a0ae6 100644 --- a/backends/cloud/savessyncrequest.cpp +++ b/backends/cloud/savessyncrequest.cpp @@ -117,17 +117,15 @@ void SavesSyncRequest::directoryListedCallback(Storage::ListDirectoryResponse re if (i->_value) _filesToUpload.push_back(i->_key); } - /////// - debug("\ndownload files:"); + debug(9, "\ndownload files:"); for (uint32 i = 0; i < _filesToDownload.size(); ++i) { - debug("%s", _filesToDownload[i].name().c_str()); + debug(9, "%s", _filesToDownload[i].name().c_str()); } - debug("\nupload files:"); + debug(9, "\nupload files:"); for (uint32 i = 0; i < _filesToUpload.size(); ++i) { - debug("%s", _filesToUpload[i].c_str()); + debug(9, "%s", _filesToUpload[i].c_str()); } _totalFilesToHandle = _filesToDownload.size() + _filesToUpload.size(); - /////// //start downloading files downloadNextFile(); @@ -162,13 +160,11 @@ void SavesSyncRequest::directoryListedErrorCallback(Networking::ErrorResponse er } } } - - //TODO: Google Drive-related JSON error } delete value; } - //Google Drive-related ScummVM-based error + //Google Drive and Box-related ScummVM-based error if (error.response.contains("subdirectory not found")) { irrecoverable = false; //base "/ScummVM/" folder not found } else if (error.response.contains("no such file found in its parent directory")) { @@ -184,7 +180,7 @@ void SavesSyncRequest::directoryListedErrorCallback(Networking::ErrorResponse er //we're lucky - user just lacks his "/cloud/" folder - let's create one Common::String dir = _storage->savesDirectoryPath(); if (dir.lastChar() == '/') dir.deleteLastChar(); - debug("creating %s", dir.c_str()); + debug(9, "creating %s", dir.c_str()); _workingRequest = _storage->createDirectory(dir, new Common::Callback(this, &SavesSyncRequest::directoryCreatedCallback), new Common::Callback(this, &SavesSyncRequest::directoryCreatedErrorCallback) @@ -227,10 +223,8 @@ void SavesSyncRequest::downloadNextFile() { _filesToDownload.pop_back(); sendCommand(GUI::kSavesSyncProgressCmd, (int)(getDownloadingProgress() * 100)); - - /////// - debug("downloading %s (%d %%)", _currentDownloadingFile.name().c_str(), (int)(getProgress() * 100)); - /////// + + debug(9, "downloading %s (%d %%)", _currentDownloadingFile.name().c_str(), (int)(getProgress() * 100)); _workingRequest = _storage->downloadById(_currentDownloadingFile.id(), DefaultSaveFileManager::concatWithSavesPath(_currentDownloadingFile.name()), new Common::Callback(this, &SavesSyncRequest::fileDownloadedCallback), new Common::Callback(this, &SavesSyncRequest::fileDownloadedErrorCallback) @@ -275,10 +269,8 @@ void SavesSyncRequest::uploadNextFile() { _currentUploadingFile = _filesToUpload.back(); _filesToUpload.pop_back(); - - /////// - debug("uploading %s (%d %%)", _currentUploadingFile.c_str(), (int)(getProgress()*100)); - /////// + + debug(9, "uploading %s (%d %%)", _currentUploadingFile.c_str(), (int)(getProgress()*100)); if (_storage->uploadStreamSupported()) { _workingRequest = _storage->upload(_storage->savesDirectoryPath() + _currentUploadingFile, g_system->getSavefileManager()->openRawFile(_currentUploadingFile), new Common::Callback(this, &SavesSyncRequest::fileUploadedCallback), @@ -318,7 +310,7 @@ void SavesSyncRequest::handle() {} void SavesSyncRequest::restart() { start(); } -double SavesSyncRequest::getDownloadingProgress() { +double SavesSyncRequest::getDownloadingProgress() const { if (_totalFilesToHandle == 0) { if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon return 0; //directory not listed yet @@ -331,7 +323,7 @@ double SavesSyncRequest::getDownloadingProgress() { return (double)(totalFilesToDownload - filesLeftToDownload) / (double)(totalFilesToDownload); } -double SavesSyncRequest::getProgress() { +double SavesSyncRequest::getProgress() const { if (_totalFilesToHandle == 0) { if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon return 0; //directory not listed yet diff --git a/backends/cloud/savessyncrequest.h b/backends/cloud/savessyncrequest.h index d1a9d4a44c..304c44407c 100644 --- a/backends/cloud/savessyncrequest.h +++ b/backends/cloud/savessyncrequest.h @@ -66,10 +66,10 @@ public: virtual void restart(); /** Returns a number in range [0, 1], where 1 is "complete". */ - double getDownloadingProgress(); + double getDownloadingProgress() const; /** Returns a number in range [0, 1], where 1 is "complete". */ - double getProgress(); + double getProgress() const; /** Returns an array of saves names which are not downloaded yet. */ Common::Array getFilesToDownload(); diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index d4548b84cb..100d72b5be 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -49,7 +49,7 @@ void Storage::printErrorResponse(Networking::ErrorResponse error) { Networking::Request *Storage::addRequest(Networking::Request *request) { _runningRequestsMutex.lock(); ++_runningRequestsCount; - if (_runningRequestsCount == 1) debug("Storage is working now"); + if (_runningRequestsCount == 1) debug(9, "Storage is working now"); _runningRequestsMutex.unlock(); return ConnMan.addRequest(request, new Common::Callback(this, &Storage::requestFinishedCallback)); } @@ -62,7 +62,7 @@ void Storage::requestFinishedCallback(Networking::Request *invalidRequestPointer _savesSyncRequest = nullptr; --_runningRequestsCount; if (_syncRestartRequestsed) restartSync = true; - if (_runningRequestsCount == 0 && !restartSync) debug("Storage is not working now"); + if (_runningRequestsCount == 0 && !restartSync) debug(9, "Storage is not working now"); _runningRequestsMutex.unlock(); if (restartSync) diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index b33d69e411..eaa6e9cea0 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -62,8 +62,12 @@ protected: /** Keeps track of running requests. */ uint32 _runningRequestsCount; Common::Mutex _runningRequestsMutex; + + /** SavesSyncRequest-related */ SavesSyncRequest *_savesSyncRequest; bool _syncRestartRequestsed; + + /** FolderDownloadRequest-related */ FolderDownloadRequest *_downloadFolderRequest; /** Returns default error callback (printErrorResponse). */ @@ -122,7 +126,7 @@ public: /** Returns ListDirectoryResponse with list of files. */ virtual Networking::Request *listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false) = 0; - /** Returns UploadStatus struct with info about uploaded file. */ + /** Returns StorageFile with info about uploaded file. */ virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback) = 0; virtual Networking::Request *upload(Common::String remotePath, Common::String localPath, UploadCallback callback, Networking::ErrorCallback errorCallback); @@ -147,8 +151,8 @@ public: virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0; /** - * Return the StorageInfo struct via . - * Call the if failed to get information. + * Returns the StorageInfo struct via . + * Calls the if failed to get information. * * @note on success Storage should also call * CloudMan.setStorageUsername(). diff --git a/base/main.cpp b/base/main.cpp index dd2c3f54e6..6b6868b78a 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -486,7 +486,6 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { #ifdef USE_LIBCURL CloudMan.init(); CloudMan.syncSaves(); - CloudMan.testFeature(); //TODO: remove later #endif // Unless a game was specified, show the launcher dialog -- cgit v1.2.3