mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:58:07 +02:00
Downloading blocks from marketplace in own asset folder
This commit is contained in:
parent
17acf0520d
commit
1ac9536f95
4 changed files with 29 additions and 37 deletions
|
@ -2780,9 +2780,8 @@ bool Application::importFromZIP(const QString& filePath) {
|
||||||
// handle Blocks download from Marketplace
|
// handle Blocks download from Marketplace
|
||||||
if (filePath.contains("vr.google.com/downloads")) {
|
if (filePath.contains("vr.google.com/downloads")) {
|
||||||
addAssetToWorldFromURL(filePath);
|
addAssetToWorldFromURL(filePath);
|
||||||
//qApp->getFileDownloadInterface()->runUnzip("", filePath, true, true);
|
|
||||||
} else {
|
} else {
|
||||||
qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true);
|
qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6227,9 +6226,8 @@ void Application::addAssetToWorldFromURL(QString url) {
|
||||||
filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL.
|
filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL.
|
||||||
}
|
}
|
||||||
if (url.contains("vr.google.com/downloads")) {
|
if (url.contains("vr.google.com/downloads")) {
|
||||||
QRegExp blocksName("\/.*\.zip");
|
filename = url.section('/', -1);
|
||||||
//filename = url.section(blocksName);
|
filename.remove(".zip?noDownload=false");
|
||||||
filename = "blocks";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
||||||
|
@ -6252,13 +6250,15 @@ void Application::addAssetToWorldFromURLRequestFinished() {
|
||||||
auto result = request->getResult();
|
auto result = request->getResult();
|
||||||
|
|
||||||
QString filename;
|
QString filename;
|
||||||
|
bool isBlocks = false;
|
||||||
|
|
||||||
if (url.contains("filename")) {
|
if (url.contains("filename")) {
|
||||||
filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL.
|
filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL.
|
||||||
}
|
}
|
||||||
if (url.contains("vr.google.com/downloads")) {
|
if (url.contains("vr.google.com/downloads")) {
|
||||||
QRegExp blocksName("\/.*\.zip");
|
filename = url.section('/', -1);
|
||||||
//filename = url.section(blocksName);
|
filename.remove(".zip?noDownload=false");
|
||||||
filename = "blocks";
|
isBlocks = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == ResourceRequest::Success) {
|
if (result == ResourceRequest::Success) {
|
||||||
|
@ -6274,7 +6274,7 @@ void Application::addAssetToWorldFromURLRequestFinished() {
|
||||||
if (tempFile.open(QIODevice::WriteOnly)) {
|
if (tempFile.open(QIODevice::WriteOnly)) {
|
||||||
tempFile.write(request->getData());
|
tempFile.write(request->getData());
|
||||||
addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key.
|
addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key.
|
||||||
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false);
|
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false, isBlocks);
|
||||||
} else {
|
} else {
|
||||||
QString errorInfo = "Couldn't open temporary file for download";
|
QString errorInfo = "Couldn't open temporary file for download";
|
||||||
qWarning(interfaceapp) << errorInfo;
|
qWarning(interfaceapp) << errorInfo;
|
||||||
|
@ -6304,7 +6304,7 @@ void Application::addAssetToWorldUnzipFailure(QString filePath) {
|
||||||
addAssetToWorldError(filename, "Couldn't unzip file " + filename + ".");
|
addAssetToWorldError(filename, "Couldn't unzip file " + filename + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip) {
|
void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip, bool isBlocks) {
|
||||||
// Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget().
|
// Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget().
|
||||||
QString mapping;
|
QString mapping;
|
||||||
QString path = filePath;
|
QString path = filePath;
|
||||||
|
@ -6313,6 +6313,11 @@ void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip)
|
||||||
QString assetFolder = zipFile.section("/", -1);
|
QString assetFolder = zipFile.section("/", -1);
|
||||||
assetFolder.remove(".zip");
|
assetFolder.remove(".zip");
|
||||||
mapping = "/" + assetFolder + "/" + filename;
|
mapping = "/" + assetFolder + "/" + filename;
|
||||||
|
} else if (isBlocks) {
|
||||||
|
qCDebug(interfaceapp) << "Path to asset folder: " << zipFile;
|
||||||
|
QString assetFolder = zipFile.section('/', -1);
|
||||||
|
assetFolder.remove(".zip?noDownload=false");
|
||||||
|
mapping = "/" + assetFolder + "/" + filename;
|
||||||
} else {
|
} else {
|
||||||
mapping = "/" + filename;
|
mapping = "/" + filename;
|
||||||
}
|
}
|
||||||
|
@ -6692,12 +6697,12 @@ void Application::onAssetToWorldMessageBoxClosed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Application::handleUnzip(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip) {
|
void Application::handleUnzip(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip, bool isBlocks) {
|
||||||
if (autoAdd) {
|
if (autoAdd) {
|
||||||
if (!unzipFile.isEmpty()) {
|
if (!unzipFile.isEmpty()) {
|
||||||
for (int i = 0; i < unzipFile.length(); i++) {
|
for (int i = 0; i < unzipFile.length(); i++) {
|
||||||
qCDebug(interfaceapp) << "Preparing file for asset server: " << unzipFile.at(i);
|
qCDebug(interfaceapp) << "Preparing file for asset server: " << unzipFile.at(i);
|
||||||
addAssetToWorld(unzipFile.at(i), zipFile, isZip);
|
addAssetToWorld(unzipFile.at(i), zipFile, isZip, isBlocks);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addAssetToWorldUnzipFailure(zipFile);
|
addAssetToWorldUnzipFailure(zipFile);
|
||||||
|
|
|
@ -331,14 +331,14 @@ public slots:
|
||||||
// FIXME: Move addAssetToWorld* methods to own class?
|
// FIXME: Move addAssetToWorld* methods to own class?
|
||||||
void addAssetToWorldFromURL(QString url);
|
void addAssetToWorldFromURL(QString url);
|
||||||
void addAssetToWorldFromURLRequestFinished();
|
void addAssetToWorldFromURLRequestFinished();
|
||||||
void addAssetToWorld(QString filePath, QString zipFile, bool isZip);
|
void addAssetToWorld(QString filePath, QString zipFile, bool isZip, bool isBlocks);
|
||||||
void addAssetToWorldUnzipFailure(QString filePath);
|
void addAssetToWorldUnzipFailure(QString filePath);
|
||||||
void addAssetToWorldWithNewMapping(QString filePath, QString mapping, int copy);
|
void addAssetToWorldWithNewMapping(QString filePath, QString mapping, int copy);
|
||||||
void addAssetToWorldUpload(QString filePath, QString mapping);
|
void addAssetToWorldUpload(QString filePath, QString mapping);
|
||||||
void addAssetToWorldSetMapping(QString filePath, QString mapping, QString hash);
|
void addAssetToWorldSetMapping(QString filePath, QString mapping, QString hash);
|
||||||
void addAssetToWorldAddEntity(QString filePath, QString mapping);
|
void addAssetToWorldAddEntity(QString filePath, QString mapping);
|
||||||
|
|
||||||
void handleUnzip(QString sourceFile, QStringList destinationFile, bool autoAdd, bool isZip);
|
void handleUnzip(QString sourceFile, QStringList destinationFile, bool autoAdd, bool isZip, bool isBlocks);
|
||||||
|
|
||||||
FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; }
|
FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; }
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,11 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent
|
||||||
// nothing for now
|
// nothing for now
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isZip) {
|
void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks) {
|
||||||
qCDebug(scriptengine) << "Url that was downloaded: " + url.toString();
|
qCDebug(scriptengine) << "Url that was downloaded: " + url.toString();
|
||||||
/*if ((url.toString()).contains("vr.google.com/downloads")) {
|
|
||||||
|
|
||||||
path = downloadBlocksZip(url);
|
|
||||||
}*/
|
|
||||||
qCDebug(scriptengine) << "Path where download is saved: " + path;
|
qCDebug(scriptengine) << "Path where download is saved: " + path;
|
||||||
QString fileName = "/" + path.section("/", -1);
|
QString fileName = "/" + path.section("/", -1);
|
||||||
|
qCDebug(scriptengine) << "Filename: " << fileName;
|
||||||
QString tempDir = path;
|
QString tempDir = path;
|
||||||
if (!isZip) {
|
if (!isZip) {
|
||||||
tempDir.remove(fileName);
|
tempDir.remove(fileName);
|
||||||
|
@ -60,11 +57,14 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool
|
||||||
|
|
||||||
if (!fileList.isEmpty()) {
|
if (!fileList.isEmpty()) {
|
||||||
qCDebug(scriptengine) << "File to upload: " + fileList.first();
|
qCDebug(scriptengine) << "File to upload: " + fileList.first();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
qCDebug(scriptengine) << "Unzip failed";
|
qCDebug(scriptengine) << "Unzip failed";
|
||||||
}
|
}
|
||||||
emit unzipResult(path, fileList, autoAdd, isZip);
|
|
||||||
|
if (path.contains("vr.google.com/downloads")) {
|
||||||
|
isZip = true;
|
||||||
|
}
|
||||||
|
emit unzipResult(path, fileList, autoAdd, isZip, isBlocks);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,18 +115,6 @@ QString FileScriptingInterface::convertUrlToPath(QUrl url) {
|
||||||
return newUrl;
|
return newUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handles a download from Blocks in the marketplace
|
|
||||||
QString FileScriptingInterface::downloadBlocksZip(QUrl url) {
|
|
||||||
qCDebug(scriptengine) << "Made it to the download blocks! " << url.toString();
|
|
||||||
|
|
||||||
/*auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
|
||||||
connect(request, &ResourceRequest::finished, this, [this, url] {
|
|
||||||
unzipFile(url, ""); // so intellisense isn't mad
|
|
||||||
});
|
|
||||||
request->send();*/
|
|
||||||
return url.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// this function is not in use
|
// this function is not in use
|
||||||
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
||||||
QUrl url = QUrl(link);
|
QUrl url = QUrl(link);
|
||||||
|
|
|
@ -24,17 +24,16 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QString convertUrlToPath(QUrl url);
|
QString convertUrlToPath(QUrl url);
|
||||||
void runUnzip(QString path, QUrl url, bool autoAdd, bool isZip);
|
void runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks);
|
||||||
QString getTempDir();
|
QString getTempDir();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void unzipResult(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip);
|
void unzipResult(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip, bool isBlocks);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isTempDir(QString tempDir);
|
bool isTempDir(QString tempDir);
|
||||||
QStringList unzipFile(QString path, QString tempDir);
|
QStringList unzipFile(QString path, QString tempDir);
|
||||||
void recursiveFileScan(QFileInfo file, QString* dirName);
|
void recursiveFileScan(QFileInfo file, QString* dirName);
|
||||||
QString downloadBlocksZip(QUrl url);
|
|
||||||
void downloadZip(QString path, const QString link);
|
void downloadZip(QString path, const QString link);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue