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 void IdStorage::printFiles(FileArrayResponse response) {
00039     debug(9, "IdStorage: files:");
00040     Common::Array<StorageFile> &files = response.value;
00041     for (uint32 i = 0; i < files.size(); ++i) {
00042         debug(9, "\t%s%s", files[i].name().c_str(), files[i].isDirectory() ? " (directory)" : "");
00043         debug(9, "\t%s", files[i].path().c_str());
00044         debug(9, "\t%s", files[i].id().c_str());
00045         debug(9, " ");
00046     }
00047 }
00048 
00049 void IdStorage::printBool(BoolResponse response) {
00050     debug(9, "IdStorage: bool: %s", response.value ? "true" : "false");
00051 }
00052 
00053 void IdStorage::printFile(UploadResponse response) {
00054     debug(9, "\nIdStorage: uploaded file info:");
00055     debug(9, "\tid: %s", response.value.path().c_str());
00056     debug(9, "\tname: %s", response.value.name().c_str());
00057     debug(9, "\tsize: %u", response.value.size());
00058     debug(9, "\ttimestamp: %u", response.value.timestamp());
00059 }
00060 
00061 Storage::ListDirectoryCallback IdStorage::getPrintFilesCallback() {
00062     return new Common::Callback<IdStorage, FileArrayResponse>(this, &IdStorage::printFiles);
00063 }
00064 
00065 Networking::Request *IdStorage::resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback) {
00066     if (!errorCallback)
00067         errorCallback = getErrorPrintingCallback();
00068     if (!callback)
00069         callback = new Common::Callback<IdStorage, UploadResponse>(this, &IdStorage::printFile);
00070     return addRequest(new IdResolveIdRequest(this, path, callback, errorCallback));
00071 }
00072 
00073 Networking::Request *IdStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
00074     if (!errorCallback)
00075         errorCallback = getErrorPrintingCallback();
00076     if (!callback)
00077         callback = new Common::Callback<IdStorage, FileArrayResponse>(this, &IdStorage::printFiles);
00078     return addRequest(new IdListDirectoryRequest(this, path, callback, errorCallback, recursive));
00079 }
00080 
00081 Networking::Request *IdStorage::createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) {
00082     if (!errorCallback)
00083         errorCallback = getErrorPrintingCallback();
00084     if (!callback)
00085         callback = new Common::Callback<IdStorage, BoolResponse>(this, &IdStorage::printBool);
00086 
00087     //find out the parent path and directory name
00088     Common::String parentPath = "", directoryName = path;
00089     for (uint32 i = path.size(); i > 0; --i) {
00090         if (path[i - 1] == '/' || path[i - 1] == '\\') {
00091             parentPath = path;
00092             parentPath.erase(i - 1);
00093             directoryName.erase(0, i);
00094             break;
00095         }
00096     }
00097 
00098     return addRequest(new IdCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback));
00099 }
00100 
00101 Networking::Request *IdStorage::streamFile(Common::String path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) {
00102     return addRequest(new IdStreamFileRequest(this, path, outerCallback, errorCallback));
00103 }
00104 
00105 Networking::Request *IdStorage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) {
00106     return addRequest(new IdDownloadRequest(this, remotePath, localPath, callback, errorCallback));
00107 }
00108 
00109 } // End of namespace Id
00110 } // End of namespace Cloud


Generated on Sat Mar 16 2019 05:01:37 for ResidualVM by doxygen 1.7.1
curved edge   curved edge