QScriptValue PHILinkItem::url( const QScriptValue &v ) { if ( !isServerItem() ) return QScriptValue( QScriptValue::UndefinedValue ); if ( !v.isValid() ) return realUrl(); setUrl( v.toString() ); return self(); }
void LegacyUpdate::lwjglStart() { LegacyInstance *inst = (LegacyInstance *)m_inst; lwjglVersion = inst->lwjglVersion(); lwjglTargetPath = PathCombine(MMC->settings()->get("LWJGLDir").toString(), lwjglVersion); lwjglNativesPath = PathCombine(lwjglTargetPath, "natives"); // if the 'done' file exists, we don't have to download this again QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); if (doneFile.exists()) { jarStart(); return; } auto list = MMC->lwjgllist(); if (!list->isLoaded()) { emitFailed("Too soon! Let the LWJGL list load :)"); return; } setStatus(tr("Downloading new LWJGL...")); auto version = list->getVersion(lwjglVersion); if (!version) { emitFailed("Game update failed: the selected LWJGL version is invalid."); return; } QString url = version->url(); QUrl realUrl(url); QString hostname = realUrl.host(); auto worker = MMC->qnam(); QNetworkRequest req(realUrl); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); QNetworkReply *rep = worker->get(req); m_reply = std::shared_ptr<QNetworkReply>(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); connect(worker.get(), SIGNAL(finished(QNetworkReply *)), SLOT(lwjglFinished(QNetworkReply *))); // connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), // SLOT(downloadError(QNetworkReply::NetworkError))); }
void LegacyUpdate::lwjglFinished(QNetworkReply *reply) { if (m_reply.get() != reply) { return; } if (reply->error() != QNetworkReply::NoError) { emitFailed("Failed to download: " + reply->errorString() + "\nSometimes you have to wait a bit if you download many LWJGL versions in " "a row. YMMV"); return; } auto worker = MMC->qnam(); // Here i check if there is a cookie for me in the reply and extract it QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie>>(reply->header(QNetworkRequest::SetCookieHeader)); if (cookies.count() != 0) { // you must tell which cookie goes with which url worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); } // here you can check for the 302 or whatever other header i need QVariant newLoc = reply->header(QNetworkRequest::LocationHeader); if (newLoc.isValid()) { QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString(); QUrl realUrl(redirectedTo); QString hostname = realUrl.host(); QNetworkRequest req(redirectedTo); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); QNetworkReply *rep = worker->get(req); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); m_reply = std::shared_ptr<QNetworkReply>(rep); return; } QFile saveMe("lwjgl.zip"); saveMe.open(QIODevice::WriteOnly); saveMe.write(m_reply->readAll()); saveMe.close(); setStatus(tr("Installing new LWJGL...")); extractLwjgl(); jarStart(); }