// // BatchLoader.cpp // libraries/script-engine/src // // Created by Ryan Huffman on 01/22/15 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include #include #include #include #include "ScriptEngineLogging.h" #include "BatchLoader.h" #include #include #include "ResourceManager.h" #include "ScriptEngines.h" #include "ScriptCache.h" BatchLoader::BatchLoader(const QList& urls) : QObject(), _started(false), _finished(false), _urls(urls.toSet()), _data() { qRegisterMetaType>("QMap"); } void BatchLoader::start() { if (_started) { return; } _started = true; for (const auto& rawURL : _urls) { QUrl url = expandScriptUrl(normalizeScriptURL(rawURL)); qCDebug(scriptengine) << "Loading script at " << url; QPointer self = this; DependencyManager::get()->getScriptContents(url.toString(), [this, self](const QString& url, const QString& contents, bool isURL, bool success) { if (!self) { return; } if (isURL && success) { _data.insert(url, contents); qCDebug(scriptengine) << "Loaded: " << url; } else { _data.insert(url, QString()); qCDebug(scriptengine) << "Could not load" << url; } checkFinished(); }, false); } checkFinished(); } void BatchLoader::checkFinished() { if (!_finished && _urls.size() == _data.size()) { _finished = true; emit finished(_data); } }