MCPcopy Create free account
hub / github.com/LeFroid/Viper-Browser / loadDependencies

Method loadDependencies

src/core/user_scripts/UserScriptModel.cpp:253–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void UserScriptModel::loadDependencies(int scriptIdx)
254{
255 if (scriptIdx < 0 || scriptIdx >= static_cast<int>(m_scripts.size()))
256 return;
257
258 UserScript &script = m_scripts.at(scriptIdx);
259
260 for (const QString &depFile : script.m_dependencies)
261 {
262 QString localFilePath;
263 if (!depFile.contains("://"))
264 continue;
265
266 localFilePath = QString("%1/%2").arg(m_scriptDepDir).arg(depFile.mid(depFile.lastIndexOf('/') + 1));
267 QFile f(localFilePath);
268 if (!f.exists() || !f.open(QIODevice::ReadOnly))
269 {
270 DownloadManager *downloadMgr = sBrowserApplication->getDownloadManager();
271
272 QNetworkRequest request;
273 request.setUrl(QUrl(depFile));
274 InternalDownloadItem *item = downloadMgr->downloadInternal(request, m_scriptDepDir, false);
275 connect(item, &InternalDownloadItem::downloadFinished, [=](const QString &filePath){
276 QFile tmp(filePath);
277 QByteArray tmpData;
278 if (tmp.open(QIODevice::ReadOnly))
279 {
280 tmpData = tmp.readAll();
281 m_scripts[scriptIdx].m_dependencyData.append(tmpData);
282 tmp.close();
283 }
284 item->deleteLater();
285 });
286 }
287 else
288 {
289 script.m_dependencyData.append(f.readAll());
290 f.close();
291 }
292 }
293}
294
295void UserScriptModel::save()
296{

Callers 1

pdf.jsFile · 0.80

Calls 4

getDownloadManagerMethod · 0.80
setUrlMethod · 0.80
downloadInternalMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected