ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

idstorage.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #define FORBIDDEN_SYMBOL_ALLOW_ALL
00024 
00025 #include "backends/cloud/id/idstorage.h"
00026 #include "backends/cloud/id/idcreatedirectoryrequest.h"
00027 #include "backends/cloud/id/iddownloadrequest.h"
00028 #include "backends/cloud/id/idlistdirectoryrequest.h"
00029 #include "backends/cloud/id/idresolveidrequest.h"
00030 #include "backends/cloud/id/idstreamfilerequest.h"
00031 #include "common/debug.h"
00032 
00033 namespace Cloud {
00034 namespace Id {
00035 
00036 IdStorage::IdStorage() {}
00037 
00038 IdStorage::IdStorage(Common::String token, Common::String refreshToken, bool enabled):
00039     BaseStorage(token, refreshToken, enabled) {}
00040 
00041 IdStorage::~IdStorage() {}
00042 
00043 void IdStorage::printFiles(FileArrayResponse response) {
00044     debug(9, "IdStorage: files:");
00045     Common::Array<StorageFile> &files = response.value;
00046     for (uint32 i = 0; i < files.size(); ++i) {
00047         debug(9, "\t%s%s", files[i].name().c_str(), files[i].isDirectory() ? " (directory)" : "");
00048         debug(9, "\t%s", files[i].path().c_str());
00049         debug(9, "\t%s", files[i].id().c_str());
00050         debug(9, " ");
00051     }
00052 }
00053 
00054 void IdStorage::printBool(BoolResponse response) {
00055     debug(9, "IdStorage: bool: %s", response.value ? "true" : "false");
00056 }
00057 
00058 void IdStorage::printFile(UploadResponse response) {
00059     debug(9, "\nIdStorage: uploaded file info:");
00060     debug(9, "\tid: %s", response.value.path().c_str());
00061     debug(9, "\tname: %s", response.value.name().c_str());
00062     debug(9, "\tsize: %u", response.value.size());
00063     debug(9, "\ttimestamp: %u", response.value.timestamp());
00064 }
00065 
00066 Storage::ListDirectoryCallback IdStorage::getPrintFilesCallback() {
00067     return new Common::Callback<IdStorage, FileArrayResponse>(this, &IdStorage::printFiles);
00068 }
00069 
00070 Networking::Request *IdStorage::resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback) {
00071     if (!errorCallback)
00072         errorCallback = getErrorPrintingCallback();
00073     if (!callback)
00074         callback = new Common::Callback<IdStorage, UploadResponse>(this, &IdStorage::printFile);
00075     return addRequest(new IdResolveIdRequest(this, path, callback, errorCallback));
00076 }
00077 
00078 Networking::Request *IdStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
00079     if (!errorCallback)
00080         errorCallback = getErrorPrintingCallback();
00081     if (!callback)
00082         callback = new Common::Callback<IdStorage, FileArrayResponse>(this, &IdStorage::printFiles);
00083     return addRequest(new IdListDirectoryRequest(this, path, callback, errorCallback, recursive));
00084 }
00085 
00086 Networking::Request *IdStorage::createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) {
00087     if (!errorCallback)
00088         errorCallback = getErrorPrintingCallback();
00089     if (!callback)
00090         callback = new Common::Callback<IdStorage, BoolResponse>(this, &IdStorage::printBool);
00091 
00092     //find out the parent path and directory name
00093     Common::String parentPath = "", directoryName = path;
00094     for (uint32 i = path.size(); i > 0; --i) {
00095         if (path[i - 1] == '/' || path[i - 1] == '\\') {
00096             parentPath = path;
00097             parentPath.erase(i - 1);
00098             directoryName.erase(0, i);
00099             break;
00100         }
00101     }
00102 
00103     return addRequest(new IdCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback));
00104 }
00105 
00106 Networking::Request *IdStorage::streamFile(Common::String path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) {
00107     return addRequest(new IdStreamFileRequest(this, path, outerCallback, errorCallback));
00108 }
00109 
00110 Networking::Request *IdStorage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) {
00111     return addRequest(new IdDownloadRequest(this, remotePath, localPath, callback, errorCallback));
00112 }
00113 
00114 } // End of namespace Id
00115 } // End of namespace Cloud


Generated on Sat May 30 2020 05:00:30 for ResidualVM by doxygen 1.7.1
curved edge   curved edge