Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,162 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/cloud/id/idcreatedirectoryrequest.h"
#include "backends/cloud/id/idstorage.h"
#include "common/debug.h"
namespace Cloud {
namespace Id {
IdCreateDirectoryRequest::IdCreateDirectoryRequest(IdStorage *storage, const Common::String &parentPath, const 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();
}
IdCreateDirectoryRequest::~IdCreateDirectoryRequest() {
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
delete _boolCallback;
}
void IdCreateDirectoryRequest::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<IdCreateDirectoryRequest, const Storage::BoolResponse &>(this, &IdCreateDirectoryRequest::createdBaseDirectoryCallback);
Networking::ErrorCallback failureCallback = new Common::Callback<IdCreateDirectoryRequest, const Networking::ErrorResponse &>(this, &IdCreateDirectoryRequest::createdBaseDirectoryErrorCallback);
_workingRequest = _storage->createDirectory("ScummVM", callback, failureCallback);
return;
}
resolveId();
}
void IdCreateDirectoryRequest::createdBaseDirectoryCallback(const Storage::BoolResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (response.request)
_date = response.request->date();
resolveId();
}
void IdCreateDirectoryRequest::createdBaseDirectoryErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (error.request)
_date = error.request->date();
finishError(error);
}
void IdCreateDirectoryRequest::resolveId() {
//check whether such folder already exists
Storage::UploadCallback innerCallback = new Common::Callback<IdCreateDirectoryRequest, const Storage::UploadResponse &>(this, &IdCreateDirectoryRequest::idResolvedCallback);
Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdCreateDirectoryRequest, const Networking::ErrorResponse &>(this, &IdCreateDirectoryRequest::idResolveFailedCallback);
Common::String path = _requestedParentPath;
if (_requestedParentPath != "")
path += "/";
path += _requestedDirectoryName;
_workingRequest = _storage->resolveFileId(path, innerCallback, innerErrorCallback);
}
void IdCreateDirectoryRequest::idResolvedCallback(const Storage::UploadResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (response.request)
_date = response.request->date();
//resolved => folder already exists
finishCreation(false);
}
void IdCreateDirectoryRequest::idResolveFailedCallback(const 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<IdCreateDirectoryRequest, const Storage::BoolResponse &>(this, &IdCreateDirectoryRequest::createdDirectoryCallback);
Networking::ErrorCallback failureCallback = new Common::Callback<IdCreateDirectoryRequest, const Networking::ErrorResponse &>(this, &IdCreateDirectoryRequest::createdDirectoryErrorCallback);
_workingRequest = _storage->createDirectoryWithParentId(parentId, _requestedDirectoryName, callback, failureCallback);
return;
}
finishError(error);
}
void IdCreateDirectoryRequest::createdDirectoryCallback(const Storage::BoolResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (response.request)
_date = response.request->date();
finishCreation(response.value);
}
void IdCreateDirectoryRequest::createdDirectoryErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (error.request)
_date = error.request->date();
finishError(error);
}
void IdCreateDirectoryRequest::handle() {}
void IdCreateDirectoryRequest::restart() { start(); }
Common::String IdCreateDirectoryRequest::date() const { return _date; }
void IdCreateDirectoryRequest::finishCreation(bool success) {
Request::finishSuccess();
if (_boolCallback)
(*_boolCallback)(Storage::BoolResponse(this, success));
}
} // End of namespace Id
} // End of namespace Cloud

View File

@@ -0,0 +1,64 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKENDS_CLOUD_ID_IDCREATEDIRECTORYREQUEST_H
#define BACKENDS_CLOUD_ID_IDCREATEDIRECTORYREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/http/request.h"
#include "common/callback.h"
namespace Cloud {
namespace Id {
class IdStorage;
class IdCreateDirectoryRequest: public Networking::Request {
Common::String _requestedParentPath;
Common::String _requestedDirectoryName;
IdStorage *_storage;
Storage::BoolCallback _boolCallback;
Request *_workingRequest;
bool _ignoreCallback;
Common::String _date;
void start();
void createdBaseDirectoryCallback(const Storage::BoolResponse &response);
void createdBaseDirectoryErrorCallback(const Networking::ErrorResponse &error);
void resolveId();
void idResolvedCallback(const Storage::UploadResponse &response);
void idResolveFailedCallback(const Networking::ErrorResponse &error);
void createdDirectoryCallback(const Storage::BoolResponse &response);
void createdDirectoryErrorCallback(const Networking::ErrorResponse &error);
void finishCreation(bool success);
public:
IdCreateDirectoryRequest(IdStorage *storage, const Common::String &parentPath, const Common::String &directoryName, Storage::BoolCallback cb, Networking::ErrorCallback ecb);
~IdCreateDirectoryRequest() override;
void handle() override;
void restart() override;
Common::String date() const override;
};
} // End of namespace Id
} // End of namespace Cloud
#endif

View File

@@ -0,0 +1,107 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/cloud/id/iddownloadrequest.h"
#include "backends/cloud/id/idstorage.h"
#include "backends/cloud/downloadrequest.h"
namespace Cloud {
namespace Id {
IdDownloadRequest::IdDownloadRequest(IdStorage *storage, const Common::String &remotePath, const Common::Path &localPath, Storage::BoolCallback cb, Networking::ErrorCallback ecb):
Networking::Request(nullptr, ecb), _requestedFile(remotePath), _requestedLocalFile(localPath), _storage(storage), _boolCallback(cb),
_workingRequest(nullptr), _ignoreCallback(false) {
start();
}
IdDownloadRequest::~IdDownloadRequest() {
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
delete _boolCallback;
}
void IdDownloadRequest::start() {
//cleanup
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
_workingRequest = nullptr;
_ignoreCallback = false;
//find file's id
Storage::UploadCallback innerCallback = new Common::Callback<IdDownloadRequest, const Storage::UploadResponse &>(this, &IdDownloadRequest::idResolvedCallback);
Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdDownloadRequest, const Networking::ErrorResponse &>(this, &IdDownloadRequest::idResolveFailedCallback);
_workingRequest = _storage->resolveFileId(_requestedFile, innerCallback, innerErrorCallback);
}
void IdDownloadRequest::idResolvedCallback(const Storage::UploadResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
Storage::BoolCallback innerCallback = new Common::Callback<IdDownloadRequest, const Storage::BoolResponse &>(this, &IdDownloadRequest::downloadCallback);
Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdDownloadRequest, const Networking::ErrorResponse &>(this, &IdDownloadRequest::downloadErrorCallback);
_workingRequest = _storage->downloadById(response.value.id(), _requestedLocalFile, innerCallback, innerErrorCallback);
}
void IdDownloadRequest::idResolveFailedCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishError(error);
}
void IdDownloadRequest::downloadCallback(const Storage::BoolResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishDownload(response.value);
}
void IdDownloadRequest::downloadErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishError(error);
}
void IdDownloadRequest::handle() {}
void IdDownloadRequest::restart() { start(); }
void IdDownloadRequest::finishDownload(bool success) {
Request::finishSuccess();
if (_boolCallback)
(*_boolCallback)(Storage::BoolResponse(this, success));
}
double IdDownloadRequest::getProgress() const {
DownloadRequest *downloadRequest = dynamic_cast<DownloadRequest *>(_workingRequest);
if (downloadRequest == nullptr)
return 0; // resolving id still
// id resolve is 10 % and download is the other 90 %
return 0.1 + 0.9 * downloadRequest->getProgress(); // downloading
}
} // End of namespace Id
} // End of namespace Cloud

View File

@@ -0,0 +1,62 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKENDS_CLOUD_ID_IDDOWNLOADREQUEST_H
#define BACKENDS_CLOUD_ID_IDDOWNLOADREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/http/request.h"
#include "common/callback.h"
namespace Cloud {
namespace Id {
class IdStorage;
class IdDownloadRequest: public Networking::Request {
Common::String _requestedFile;
Common::Path _requestedLocalFile;
IdStorage *_storage;
Storage::BoolCallback _boolCallback;
Request *_workingRequest;
bool _ignoreCallback;
void start();
void idResolvedCallback(const Storage::UploadResponse &response);
void idResolveFailedCallback(const Networking::ErrorResponse &error);
void downloadCallback(const Storage::BoolResponse &response);
void downloadErrorCallback(const Networking::ErrorResponse &error);
void finishDownload(bool success);
public:
IdDownloadRequest(IdStorage *storage, const Common::String &remotePath, const Common::Path &localPath, Storage::BoolCallback cb, Networking::ErrorCallback ecb);
~IdDownloadRequest() override;
void handle() override;
void restart() override;
/** Returns a number in range [0, 1], where 1 is "complete". */
double getProgress() const;
};
} // End of namespace Id
} // End of namespace Cloud
#endif

View File

@@ -0,0 +1,140 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/cloud/id/idlistdirectoryrequest.h"
#include "backends/cloud/id/idstorage.h"
namespace Cloud {
namespace Id {
IdListDirectoryRequest::IdListDirectoryRequest(IdStorage *storage, const 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();
}
IdListDirectoryRequest::~IdListDirectoryRequest() {
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
delete _listDirectoryCallback;
}
void IdListDirectoryRequest::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<IdListDirectoryRequest, const Storage::UploadResponse &>(this, &IdListDirectoryRequest::idResolvedCallback);
Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdListDirectoryRequest, const Networking::ErrorResponse &>(this, &IdListDirectoryRequest::idResolveErrorCallback);
_workingRequest = _storage->resolveFileId(_requestedPath, innerCallback, innerErrorCallback);
}
void IdListDirectoryRequest::idResolvedCallback(const 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 IdListDirectoryRequest::idResolveErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (error.request)
_date = error.request->date();
finishError(error);
}
void IdListDirectoryRequest::listNextDirectory() {
if (_directoriesQueue.empty()) {
finishListing(_files);
return;
}
_currentDirectory = _directoriesQueue.back();
_directoriesQueue.pop_back();
Storage::FileArrayCallback callback = new Common::Callback<IdListDirectoryRequest, const Storage::FileArrayResponse &>(this, &IdListDirectoryRequest::listedDirectoryCallback);
Networking::ErrorCallback failureCallback = new Common::Callback<IdListDirectoryRequest, const Networking::ErrorResponse &>(this, &IdListDirectoryRequest::listedDirectoryErrorCallback);
_workingRequest = _storage->listDirectoryById(_currentDirectory.id(), callback, failureCallback);
}
void IdListDirectoryRequest::listedDirectoryCallback(const 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 IdListDirectoryRequest::listedDirectoryErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
if (error.request)
_date = error.request->date();
finishError(error);
}
void IdListDirectoryRequest::handle() {}
void IdListDirectoryRequest::restart() { start(); }
Common::String IdListDirectoryRequest::date() const { return _date; }
void IdListDirectoryRequest::finishListing(const Common::Array<StorageFile> &files) {
Request::finishSuccess();
if (_listDirectoryCallback)
(*_listDirectoryCallback)(Storage::ListDirectoryResponse(this, files));
}
} // End of namespace Id
} // End of namespace Cloud

View File

@@ -0,0 +1,65 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKENDS_CLOUD_ID_IDLISTDIRECTORYREQUEST_H
#define BACKENDS_CLOUD_ID_IDLISTDIRECTORYREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/http/request.h"
#include "common/callback.h"
namespace Cloud {
namespace Id {
class IdStorage;
class IdListDirectoryRequest: public Networking::Request {
Common::String _requestedPath;
bool _requestedRecursive;
IdStorage *_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(const Storage::UploadResponse &response);
void idResolveErrorCallback(const Networking::ErrorResponse &error);
void listNextDirectory();
void listedDirectoryCallback(const Storage::FileArrayResponse &response);
void listedDirectoryErrorCallback(const Networking::ErrorResponse &error);
void finishListing(const Common::Array<StorageFile> &files);
public:
IdListDirectoryRequest(IdStorage *storage, const Common::String &path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive = false);
~IdListDirectoryRequest() override;
void handle() override;
void restart() override;
Common::String date() const override;
};
} // End of namespace Id
} // End of namespace Cloud
#endif

View File

@@ -0,0 +1,135 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/cloud/id/idresolveidrequest.h"
#include "backends/cloud/id/idstorage.h"
namespace Cloud {
namespace Id {
IdResolveIdRequest::IdResolveIdRequest(IdStorage *storage, const 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();
}
IdResolveIdRequest::~IdResolveIdRequest() {
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
delete _uploadCallback;
}
void IdResolveIdRequest::start() {
//cleanup
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
_workingRequest = nullptr;
_currentDirectory = "";
_currentDirectoryId = _storage->getRootDirectoryId();
_ignoreCallback = false;
listNextDirectory(StorageFile(_currentDirectoryId, 0, 0, true));
}
void IdResolveIdRequest::listNextDirectory(const StorageFile &fileToReturn) {
if (_currentDirectory.equalsIgnoreCase(_requestedPath)) {
finishFile(fileToReturn);
return;
}
Storage::FileArrayCallback callback = new Common::Callback<IdResolveIdRequest, const Storage::FileArrayResponse &>(this, &IdResolveIdRequest::listedDirectoryCallback);
Networking::ErrorCallback failureCallback = new Common::Callback<IdResolveIdRequest, const Networking::ErrorResponse &>(this, &IdResolveIdRequest::listedDirectoryErrorCallback);
_workingRequest = _storage->listDirectoryById(_currentDirectoryId, callback, failureCallback);
}
void IdResolveIdRequest::listedDirectoryCallback(const Storage::FileArrayResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
Common::String currentLevelName = _requestedPath;
///debug(9, "'%s'", currentLevelName.c_str());
if (_currentDirectory.size())
currentLevelName.erase(0, _currentDirectory.size());
if (currentLevelName.size() && (currentLevelName[0] == '/' || currentLevelName[0] == '\\'))
currentLevelName.erase(0, 1);
///debug(9, "'%s'", currentLevelName.c_str());
for (uint32 i = 0; i < currentLevelName.size(); ++i) {
if (currentLevelName[i] == '/' || currentLevelName[i] == '\\') {
currentLevelName.erase(i);
///debug(9, "'%s'", currentLevelName.c_str());
break;
}
}
Common::String path = _currentDirectory;
if (path != "")
path += "/";
path += currentLevelName;
bool lastLevel = (path.equalsIgnoreCase(_requestedPath));
///debug(9, "IdResolveIdRequest: searching for '%s' in '%s'", currentLevelName.c_str(), _currentDirectory.c_str());
const 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(9, "IdResolveIdRequest: 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 IdResolveIdRequest::listedDirectoryErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishError(error);
}
void IdResolveIdRequest::handle() {}
void IdResolveIdRequest::restart() { start(); }
void IdResolveIdRequest::finishFile(const StorageFile &file) {
Request::finishSuccess();
if (_uploadCallback)
(*_uploadCallback)(Storage::UploadResponse(this, file));
}
} // End of namespace Id
} // End of namespace Cloud

View File

@@ -0,0 +1,59 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKENDS_CLOUD_ID_IDRESOLVEIDREQUEST_H
#define BACKENDS_CLOUD_ID_IDRESOLVEIDREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/http/request.h"
#include "common/callback.h"
namespace Cloud {
namespace Id {
class IdStorage;
class IdResolveIdRequest: public Networking::Request {
Common::String _requestedPath;
IdStorage *_storage;
Storage::UploadCallback _uploadCallback;
Common::String _currentDirectory;
Common::String _currentDirectoryId;
Request *_workingRequest;
bool _ignoreCallback;
void start();
void listNextDirectory(const StorageFile &fileToReturn);
void listedDirectoryCallback(const Storage::FileArrayResponse &response);
void listedDirectoryErrorCallback(const Networking::ErrorResponse &error);
void finishFile(const StorageFile &file);
public:
IdResolveIdRequest(IdStorage *storage, const Common::String &path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive = false); //TODO: why upload?
~IdResolveIdRequest() override;
void handle() override;
void restart() override;
};
} // End of namespace Id
} // End of namespace Cloud
#endif

View File

@@ -0,0 +1,112 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/cloud/id/idstorage.h"
#include "backends/cloud/id/idcreatedirectoryrequest.h"
#include "backends/cloud/id/iddownloadrequest.h"
#include "backends/cloud/id/idlistdirectoryrequest.h"
#include "backends/cloud/id/idresolveidrequest.h"
#include "backends/cloud/id/idstreamfilerequest.h"
#include "common/debug.h"
namespace Cloud {
namespace Id {
IdStorage::IdStorage() {}
IdStorage::IdStorage(const Common::String &token, const Common::String &refreshToken, bool enabled):
BaseStorage(token, refreshToken, enabled) {}
IdStorage::~IdStorage() {}
void IdStorage::printFiles(const FileArrayResponse &response) {
debug(9, "IdStorage: files:");
const Common::Array<StorageFile> &files = response.value;
for (uint32 i = 0; i < files.size(); ++i) {
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(const BoolResponse &response) {
debug(9, "IdStorage: bool: %s", response.value ? "true" : "false");
}
void IdStorage::printFile(const UploadResponse &response) {
debug(9, "\nIdStorage: uploaded 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() {
return new Common::Callback<IdStorage, const FileArrayResponse &>(this, &IdStorage::printFiles);
}
Networking::Request *IdStorage::resolveFileId(const Common::String &path, UploadCallback callback, Networking::ErrorCallback errorCallback) {
if (!errorCallback)
errorCallback = getErrorPrintingCallback();
if (!callback)
callback = new Common::Callback<IdStorage, const UploadResponse &>(this, &IdStorage::printFile);
return addRequest(new IdResolveIdRequest(this, path, callback, errorCallback));
}
Networking::Request *IdStorage::listDirectory(const Common::String &path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
if (!errorCallback)
errorCallback = getErrorPrintingCallback();
if (!callback)
callback = new Common::Callback<IdStorage, const FileArrayResponse &>(this, &IdStorage::printFiles);
return addRequest(new IdListDirectoryRequest(this, path, callback, errorCallback, recursive));
}
Networking::Request *IdStorage::createDirectory(const Common::String &path, BoolCallback callback, Networking::ErrorCallback errorCallback) {
if (!errorCallback)
errorCallback = getErrorPrintingCallback();
if (!callback)
callback = new Common::Callback<IdStorage, const BoolResponse &>(this, &IdStorage::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 IdCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback));
}
Networking::Request *IdStorage::streamFile(const Common::String &path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) {
return addRequest(new IdStreamFileRequest(this, path, outerCallback, errorCallback));
}
Networking::Request *IdStorage::download(const Common::String &remotePath, const Common::Path &localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) {
return addRequest(new IdDownloadRequest(this, remotePath, localPath, callback, errorCallback));
}
} // End of namespace Id
} // End of namespace Cloud

View File

@@ -0,0 +1,84 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKENDS_CLOUD_ID_IDSTORAGE_H
#define BACKENDS_CLOUD_ID_IDSTORAGE_H
#include "backends/cloud/basestorage.h"
#include "backends/networking/http/httpjsonrequest.h"
/*
* Id::IdStorage is a special base class, which is created
* to simplify adding new storages which use ids instead of
* paths in their API.
*
* Some Requests are already implemented, and Storage based
* on IdStorage needs to override/implement a few basic things.
*
* For example, ListDirectoryRequest and ResolveIdRequests are
* based on listDirectoryById() and getRootDirectoryId() methods.
* Implementing these you'll get id resolving and directory
* listing by path.
*/
namespace Cloud {
namespace Id {
class IdStorage: public Cloud::BaseStorage {
protected:
void printFiles(const FileArrayResponse &response);
void printBool(const BoolResponse &response);
void printFile(const UploadResponse &response);
ListDirectoryCallback getPrintFilesCallback();
public:
IdStorage();
IdStorage(const Common::String &token, const Common::String &refreshToken, bool enabled);
~IdStorage() override;
/** Public Cloud API comes down there. */
/** Returns StorageFile with the resolved file's id. */
virtual Networking::Request *resolveFileId(const Common::String &path, UploadCallback callback, Networking::ErrorCallback errorCallback);
/** Returns ListDirectoryStatus struct with list of files. */
Networking::Request *listDirectory(const Common::String &path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false) override;
virtual Networking::Request *listDirectoryById(const Common::String &id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback) = 0;
/** Calls the callback when finished. */
Networking::Request *createDirectory(const Common::String &path, BoolCallback callback, Networking::ErrorCallback errorCallback) override;
virtual Networking::Request *createDirectoryWithParentId(const Common::String &parentId, const Common::String &name, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;
/** Returns pointer to Networking::NetworkReadStream. */
Networking::Request *streamFile(const Common::String &path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) override;
virtual Networking::Request *streamFileById(const Common::String &id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) override = 0;
/** Calls the callback when finished. */
Networking::Request *download(const Common::String &remotePath, const Common::Path &localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) override;
virtual Common::String getRootDirectoryId() = 0;
};
} // End of namespace Id
} // End of namespace Cloud
#endif

View File

@@ -0,0 +1,97 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/cloud/id/idstreamfilerequest.h"
#include "backends/cloud/id/idstorage.h"
namespace Cloud {
namespace Id {
IdStreamFileRequest::IdStreamFileRequest(IdStorage *storage, const Common::String &path, Networking::NetworkReadStreamCallback cb, Networking::ErrorCallback ecb):
Networking::Request(nullptr, ecb), _requestedFile(path), _storage(storage), _streamCallback(cb),
_workingRequest(nullptr), _ignoreCallback(false) {
start();
}
IdStreamFileRequest::~IdStreamFileRequest() {
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
delete _streamCallback;
}
void IdStreamFileRequest::start() {
//cleanup
_ignoreCallback = true;
if (_workingRequest)
_workingRequest->finish();
_workingRequest = nullptr;
_ignoreCallback = false;
//find file's id
Storage::UploadCallback innerCallback = new Common::Callback<IdStreamFileRequest, const Storage::UploadResponse &>(this, &IdStreamFileRequest::idResolvedCallback);
Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdStreamFileRequest, const Networking::ErrorResponse &>(this, &IdStreamFileRequest::idResolveFailedCallback);
_workingRequest = _storage->resolveFileId(_requestedFile, innerCallback, innerErrorCallback);
}
void IdStreamFileRequest::idResolvedCallback(const Storage::UploadResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
Networking::NetworkReadStreamCallback innerCallback = new Common::Callback<IdStreamFileRequest, const Networking::NetworkReadStreamResponse &>(this, &IdStreamFileRequest::streamFileCallback);
Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdStreamFileRequest, const Networking::ErrorResponse &>(this, &IdStreamFileRequest::streamFileErrorCallback);
_workingRequest = _storage->streamFileById(response.value.id(), innerCallback, innerErrorCallback);
}
void IdStreamFileRequest::idResolveFailedCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishError(error);
}
void IdStreamFileRequest::streamFileCallback(const Networking::NetworkReadStreamResponse &response) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishStream(response.value);
}
void IdStreamFileRequest::streamFileErrorCallback(const Networking::ErrorResponse &error) {
_workingRequest = nullptr;
if (_ignoreCallback)
return;
finishError(error);
}
void IdStreamFileRequest::handle() {}
void IdStreamFileRequest::restart() { start(); }
void IdStreamFileRequest::finishStream(Networking::NetworkReadStream *stream) {
Request::finishSuccess();
if (_streamCallback)
(*_streamCallback)(Networking::NetworkReadStreamResponse(this, stream));
}
} // End of namespace Id
} // End of namespace Cloud

View File

@@ -0,0 +1,58 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKENDS_CLOUD_ID_IDSTREAMFILEREQUEST_H
#define BACKENDS_CLOUD_ID_IDSTREAMFILEREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/http/request.h"
#include "common/callback.h"
namespace Cloud {
namespace Id {
class IdStorage;
class IdStreamFileRequest: public Networking::Request {
Common::String _requestedFile;
IdStorage *_storage;
Networking::NetworkReadStreamCallback _streamCallback;
Request *_workingRequest;
bool _ignoreCallback;
void start();
void idResolvedCallback(const Storage::UploadResponse &response);
void idResolveFailedCallback(const Networking::ErrorResponse &error);
void streamFileCallback(const Networking::NetworkReadStreamResponse &response);
void streamFileErrorCallback(const Networking::ErrorResponse &error);
void finishStream(Networking::NetworkReadStream *stream);
public:
IdStreamFileRequest(IdStorage *storage, const Common::String &path, Networking::NetworkReadStreamCallback cb, Networking::ErrorCallback ecb);
~IdStreamFileRequest() override;
void handle() override;
void restart() override;
};
} // End of namespace Id
} // End of namespace Cloud
#endif