2017-01-08 03:58:05 +00:00
|
|
|
/* Copyright 2013-2017 MultiMC Contributors
|
2013-11-04 01:53:05 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-05-08 19:20:10 +00:00
|
|
|
#include <QStringList>
|
2013-08-06 23:38:18 +00:00
|
|
|
#include <quazip.h>
|
|
|
|
#include <quazipfile.h>
|
2015-02-04 20:10:10 +00:00
|
|
|
#include <QDebug>
|
2014-05-08 19:20:10 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "Env.h"
|
|
|
|
#include "BaseInstance.h"
|
|
|
|
#include "net/URLConstants.h"
|
2015-04-12 20:50:52 +00:00
|
|
|
#include "MMCZip.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
|
2015-07-26 15:55:29 +00:00
|
|
|
#include "LegacyUpdate.h"
|
2016-04-03 22:33:56 +00:00
|
|
|
#include "LegacyModList.h"
|
2015-07-26 15:55:29 +00:00
|
|
|
|
2016-02-27 18:58:40 +00:00
|
|
|
#include "LwjglVersionList.h"
|
|
|
|
#include "LegacyInstance.h"
|
2015-10-04 23:47:27 +00:00
|
|
|
#include <FileSystem.h>
|
2013-08-06 23:38:18 +00:00
|
|
|
|
2014-01-27 02:00:49 +00:00
|
|
|
LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
2013-10-05 23:13:40 +00:00
|
|
|
{
|
|
|
|
}
|
2013-08-06 23:38:18 +00:00
|
|
|
|
|
|
|
void LegacyUpdate::executeTask()
|
|
|
|
{
|
2014-04-19 19:24:11 +00:00
|
|
|
fmllibsStart();
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 19:24:11 +00:00
|
|
|
void LegacyUpdate::fmllibsStart()
|
|
|
|
{
|
|
|
|
// Get the mod list
|
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
|
|
|
auto modList = inst->jarModList();
|
|
|
|
|
|
|
|
bool forge_present = false;
|
|
|
|
|
|
|
|
QString version = inst->intendedVersionId();
|
2014-05-04 22:10:59 +00:00
|
|
|
auto & fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
|
2014-04-19 19:24:11 +00:00
|
|
|
if (!fmlLibsMapping.contains(version))
|
|
|
|
{
|
|
|
|
lwjglStart();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &libList = fmlLibsMapping[version];
|
|
|
|
|
|
|
|
// determine if we need some libs for FML or forge
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Checking for FML libraries..."));
|
2014-04-19 19:24:11 +00:00
|
|
|
for (unsigned i = 0; i < modList->size(); i++)
|
|
|
|
{
|
|
|
|
auto &mod = modList->operator[](i);
|
|
|
|
|
|
|
|
// do not use disabled mods.
|
|
|
|
if (!mod.enabled())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mod.type() != Mod::MOD_ZIPFILE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mod.mmc_id().contains("forge", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
forge_present = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mod.mmc_id().contains("fml", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
forge_present = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// we don't...
|
|
|
|
if (!forge_present)
|
|
|
|
{
|
|
|
|
lwjglStart();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check the lib folder inside the instance for files.
|
|
|
|
for (auto &lib : libList)
|
|
|
|
{
|
2015-10-04 23:47:27 +00:00
|
|
|
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
|
2014-04-19 19:24:11 +00:00
|
|
|
if (libInfo.exists())
|
|
|
|
continue;
|
|
|
|
fmlLibsToProcess.append(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if everything is in place, there's nothing to do here...
|
|
|
|
if (fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
|
|
|
lwjglStart();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// download missing libs to our place
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Dowloading FML libraries..."));
|
2014-04-19 19:24:11 +00:00
|
|
|
auto dljob = new NetJob("FML libraries");
|
2015-01-31 15:59:03 +00:00
|
|
|
auto metacache = ENV.metacache();
|
2014-04-19 19:24:11 +00:00
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
2014-04-23 00:27:40 +00:00
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
|
|
|
QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.filename
|
|
|
|
: URLConstants::FMLLIBS_FORGE_BASE_URL + lib.filename;
|
2016-05-28 17:54:17 +00:00
|
|
|
dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry));
|
2014-04-19 19:24:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 11:47:14 +00:00
|
|
|
connect(dljob, &NetJob::succeeded, this, &LegacyUpdate::fmllibsFinished);
|
|
|
|
connect(dljob, &NetJob::failed, this, &LegacyUpdate::fmllibsFailed);
|
|
|
|
connect(dljob, &NetJob::progress, this, &LegacyUpdate::progress);
|
2014-04-19 19:24:11 +00:00
|
|
|
legacyDownloadJob.reset(dljob);
|
|
|
|
legacyDownloadJob->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::fmllibsFinished()
|
|
|
|
{
|
|
|
|
legacyDownloadJob.reset();
|
|
|
|
if(!fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Copying FML libraries into the instance..."));
|
2014-04-19 19:24:11 +00:00
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
2015-01-31 15:59:03 +00:00
|
|
|
auto metacache = ENV.metacache();
|
2014-04-19 19:24:11 +00:00
|
|
|
int index = 0;
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
2014-04-23 00:27:40 +00:00
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
2015-10-04 23:47:27 +00:00
|
|
|
auto path = FS::PathCombine(inst->libDir(), lib.filename);
|
|
|
|
if(!FS::ensureFilePathExists(path))
|
2014-04-19 19:24:11 +00:00
|
|
|
{
|
|
|
|
emitFailed(tr("Failed creating FML library folder inside the instance."));
|
|
|
|
return;
|
|
|
|
}
|
2015-10-04 23:47:27 +00:00
|
|
|
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
|
2014-04-19 19:24:11 +00:00
|
|
|
{
|
2014-04-23 00:27:40 +00:00
|
|
|
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
|
2014-04-19 19:24:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
}
|
|
|
|
lwjglStart();
|
|
|
|
}
|
|
|
|
|
2015-04-26 11:47:14 +00:00
|
|
|
void LegacyUpdate::fmllibsFailed(QString reason)
|
2014-04-19 19:24:11 +00:00
|
|
|
{
|
2015-04-26 11:47:14 +00:00
|
|
|
emitFailed(tr("Game update failed: it was impossible to fetch the required FML libraries. Reason: %1").arg(reason));
|
2014-04-19 19:24:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-06 23:38:18 +00:00
|
|
|
void LegacyUpdate::lwjglStart()
|
|
|
|
{
|
2013-10-05 23:13:40 +00:00
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
|
|
|
|
|
|
|
lwjglVersion = inst->lwjglVersion();
|
2015-10-04 23:47:27 +00:00
|
|
|
lwjglTargetPath = FS::PathCombine(inst->lwjglFolder(), lwjglVersion);
|
|
|
|
lwjglNativesPath = FS::PathCombine(lwjglTargetPath, "natives");
|
2013-08-08 22:26:35 +00:00
|
|
|
|
|
|
|
// if the 'done' file exists, we don't have to download this again
|
2015-10-04 23:47:27 +00:00
|
|
|
QFileInfo doneFile(FS::PathCombine(lwjglTargetPath, "done"));
|
2013-10-05 23:13:40 +00:00
|
|
|
if (doneFile.exists())
|
2013-08-08 22:26:35 +00:00
|
|
|
{
|
2013-08-11 22:39:19 +00:00
|
|
|
jarStart();
|
2013-08-08 22:26:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2015-02-02 00:09:28 +00:00
|
|
|
auto list = std::dynamic_pointer_cast<LWJGLVersionList>(ENV.getVersionList("org.lwjgl.legacy"));
|
2013-10-05 23:13:40 +00:00
|
|
|
if (!list->isLoaded())
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-08-08 22:26:35 +00:00
|
|
|
emitFailed("Too soon! Let the LWJGL list load :)");
|
2013-08-06 23:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Downloading new LWJGL..."));
|
2015-02-02 00:09:28 +00:00
|
|
|
auto version = std::dynamic_pointer_cast<LWJGLVersion>(list->findVersion(lwjglVersion));
|
2013-10-05 23:13:40 +00:00
|
|
|
if (!version)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-08-08 22:26:35 +00:00
|
|
|
emitFailed("Game update failed: the selected LWJGL version is invalid.");
|
|
|
|
return;
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2013-08-06 23:38:18 +00:00
|
|
|
QString url = version->url();
|
2013-08-06 23:49:19 +00:00
|
|
|
QUrl realUrl(url);
|
|
|
|
QString hostname = realUrl.host();
|
2016-11-06 20:58:54 +00:00
|
|
|
auto worker = &ENV.qnam();
|
2013-08-06 23:49:19 +00:00
|
|
|
QNetworkRequest req(realUrl);
|
|
|
|
req.setRawHeader("Host", hostname.toLatin1());
|
2013-10-09 23:47:48 +00:00
|
|
|
req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
2013-10-05 23:13:40 +00:00
|
|
|
QNetworkReply *rep = worker->get(req);
|
|
|
|
|
|
|
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
2015-04-26 11:47:14 +00:00
|
|
|
connect(rep, &QNetworkReply::downloadProgress, this, &LegacyUpdate::progress);
|
2016-11-06 20:58:54 +00:00
|
|
|
connect(worker, &QNetworkAccessManager::finished, this, &LegacyUpdate::lwjglFinished);
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 23:13:40 +00:00
|
|
|
void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-10-05 23:13:40 +00:00
|
|
|
if (m_reply.get() != reply)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
if (reply->error() != QNetworkReply::NoError)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-10-05 23:13:40 +00:00
|
|
|
emitFailed("Failed to download: " + reply->errorString() +
|
|
|
|
"\nSometimes you have to wait a bit if you download many LWJGL versions in "
|
|
|
|
"a row. YMMV");
|
2013-08-06 23:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-11-06 20:58:54 +00:00
|
|
|
auto worker = &ENV.qnam();
|
2013-10-05 23:13:40 +00:00
|
|
|
// 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)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-10-05 23:13:40 +00:00
|
|
|
// you must tell which cookie goes with which url
|
2013-09-07 02:00:58 +00:00
|
|
|
worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net"));
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 23:13:40 +00:00
|
|
|
// here you can check for the 302 or whatever other header i need
|
2013-08-06 23:38:18 +00:00
|
|
|
QVariant newLoc = reply->header(QNetworkRequest::LocationHeader);
|
2013-10-05 23:13:40 +00:00
|
|
|
if (newLoc.isValid())
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
|
|
|
QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString();
|
2013-08-06 23:49:19 +00:00
|
|
|
QUrl realUrl(redirectedTo);
|
|
|
|
QString hostname = realUrl.host();
|
2013-08-06 23:38:18 +00:00
|
|
|
QNetworkRequest req(redirectedTo);
|
2013-08-06 23:49:19 +00:00
|
|
|
req.setRawHeader("Host", hostname.toLatin1());
|
2013-10-09 23:47:48 +00:00
|
|
|
req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
2013-10-05 23:13:40 +00:00
|
|
|
QNetworkReply *rep = worker->get(req);
|
2015-04-26 11:47:14 +00:00
|
|
|
connect(rep, &QNetworkReply::downloadProgress, this, &LegacyUpdate::progress);
|
2013-10-05 23:13:40 +00:00
|
|
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
2013-08-06 23:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QFile saveMe("lwjgl.zip");
|
|
|
|
saveMe.open(QIODevice::WriteOnly);
|
|
|
|
saveMe.write(m_reply->readAll());
|
|
|
|
saveMe.close();
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Installing new LWJGL..."));
|
2013-08-06 23:38:18 +00:00
|
|
|
extractLwjgl();
|
2013-08-11 22:39:19 +00:00
|
|
|
jarStart();
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
void LegacyUpdate::extractLwjgl()
|
|
|
|
{
|
|
|
|
// make sure the directories are there
|
2013-08-08 22:26:35 +00:00
|
|
|
|
2015-10-04 23:47:27 +00:00
|
|
|
bool success = FS::ensureFolderPathExists(lwjglNativesPath);
|
2013-10-05 23:13:40 +00:00
|
|
|
|
|
|
|
if (!success)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-08-08 22:26:35 +00:00
|
|
|
emitFailed("Failed to extract the lwjgl libs - error when creating required folders.");
|
2013-08-06 23:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2013-08-06 23:38:18 +00:00
|
|
|
QuaZip zip("lwjgl.zip");
|
2013-10-05 23:13:40 +00:00
|
|
|
if (!zip.open(QuaZip::mdUnzip))
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-08-08 22:26:35 +00:00
|
|
|
emitFailed("Failed to extract the lwjgl libs - not a valid archive.");
|
2013-08-06 23:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2013-08-06 23:38:18 +00:00
|
|
|
// and now we are going to access files inside it
|
|
|
|
QuaZipFile file(&zip);
|
2013-10-05 23:13:40 +00:00
|
|
|
const QString jarNames[] = {"jinput.jar", "lwjgl_util.jar", "lwjgl.jar"};
|
|
|
|
for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2013-10-05 23:13:40 +00:00
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
|
|
|
zip.close();
|
2013-08-08 22:26:35 +00:00
|
|
|
emitFailed("Failed to extract the lwjgl libs - error while reading archive.");
|
2013-08-06 23:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QuaZipFileInfo info;
|
|
|
|
QString name = file.getActualFileName();
|
2013-10-05 23:13:40 +00:00
|
|
|
if (name.endsWith('/'))
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString destFileName;
|
|
|
|
// Look for the jars
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (name.endsWith(jarNames[i]))
|
|
|
|
{
|
2015-10-04 23:47:27 +00:00
|
|
|
destFileName = FS::PathCombine(lwjglTargetPath, jarNames[i]);
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Not found? look for the natives
|
2013-10-05 23:13:40 +00:00
|
|
|
if (destFileName.isEmpty())
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
QString nativesDir = "windows";
|
|
|
|
#else
|
2013-10-05 23:13:40 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2013-08-26 00:53:29 +00:00
|
|
|
QString nativesDir = "macosx";
|
2013-10-05 23:13:40 +00:00
|
|
|
#else
|
2013-08-06 23:38:18 +00:00
|
|
|
QString nativesDir = "linux";
|
2013-10-05 23:13:40 +00:00
|
|
|
#endif
|
2013-08-06 23:38:18 +00:00
|
|
|
#endif
|
|
|
|
if (name.contains(nativesDir))
|
|
|
|
{
|
|
|
|
int lastSlash = name.lastIndexOf('/');
|
2013-09-15 22:54:39 +00:00
|
|
|
int lastBackSlash = name.lastIndexOf('\\');
|
2013-10-05 23:13:40 +00:00
|
|
|
if (lastSlash != -1)
|
|
|
|
name = name.mid(lastSlash + 1);
|
|
|
|
else if (lastBackSlash != -1)
|
|
|
|
name = name.mid(lastBackSlash + 1);
|
2015-10-04 23:47:27 +00:00
|
|
|
destFileName = FS::PathCombine(lwjglNativesPath, name);
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now if destFileName is still empty, go to the next file.
|
|
|
|
if (!destFileName.isEmpty())
|
|
|
|
{
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Installing new LWJGL - extracting ") + name + "...");
|
2013-08-06 23:38:18 +00:00
|
|
|
QFile output(destFileName);
|
|
|
|
output.open(QIODevice::WriteOnly);
|
2015-07-21 07:21:59 +00:00
|
|
|
output.write(file.readAll());
|
2013-08-06 23:38:18 +00:00
|
|
|
output.close();
|
|
|
|
}
|
|
|
|
file.close(); // do not forget to close!
|
|
|
|
}
|
|
|
|
zip.close();
|
2013-10-05 23:13:40 +00:00
|
|
|
m_reply.reset();
|
2015-10-04 23:47:27 +00:00
|
|
|
QFile doneFile(FS::PathCombine(lwjglTargetPath, "done"));
|
2013-08-08 22:26:35 +00:00
|
|
|
doneFile.open(QIODevice::WriteOnly);
|
|
|
|
doneFile.write("done.");
|
|
|
|
doneFile.close();
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 11:47:14 +00:00
|
|
|
void LegacyUpdate::lwjglFailed(QString reason)
|
2013-08-06 23:38:18 +00:00
|
|
|
{
|
2015-04-26 11:47:14 +00:00
|
|
|
emitFailed(tr("Bad stuff happened while trying to get the lwjgl libs: %1").arg(reason));
|
2013-08-06 23:38:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-11 22:39:19 +00:00
|
|
|
void LegacyUpdate::jarStart()
|
|
|
|
{
|
2013-10-05 23:13:40 +00:00
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
|
|
|
if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar())
|
2013-08-11 22:39:19 +00:00
|
|
|
{
|
2015-07-09 22:06:05 +00:00
|
|
|
emitSucceeded();
|
2013-08-11 22:39:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Checking for jar updates..."));
|
2013-08-11 22:39:19 +00:00
|
|
|
// Make directories
|
2017-01-10 22:03:00 +00:00
|
|
|
QDir binDir(inst->binRoot());
|
2013-08-11 22:39:19 +00:00
|
|
|
if (!binDir.exists() && !binDir.mkpath("."))
|
|
|
|
{
|
|
|
|
emitFailed("Failed to create bin folder.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a list of URLs that will need to be downloaded.
|
2017-05-03 21:11:52 +00:00
|
|
|
setStatus(tr("Downloading new minecraft.jar ..."));
|
2013-08-11 22:39:19 +00:00
|
|
|
|
2013-12-10 19:33:24 +00:00
|
|
|
QString version_id = inst->intendedVersionId();
|
2013-10-05 23:13:40 +00:00
|
|
|
|
2013-12-10 19:33:24 +00:00
|
|
|
auto dljob = new NetJob("Minecraft.jar for version " + version_id);
|
|
|
|
|
2015-01-31 15:59:03 +00:00
|
|
|
auto metacache = ENV.metacache();
|
2016-03-26 15:56:57 +00:00
|
|
|
auto entry = metacache->resolveEntry("versions", URLConstants::getJarPath(version_id));
|
2016-05-28 17:54:17 +00:00
|
|
|
dljob->addNetAction(Net::Download::makeCached(QUrl(URLConstants::getLegacyJarUrl(version_id)), entry));
|
2013-09-08 18:16:38 +00:00
|
|
|
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
|
2015-04-26 11:47:14 +00:00
|
|
|
connect(dljob, SIGNAL(failed(QString)), SLOT(jarFailed(QString)));
|
2013-10-05 23:13:40 +00:00
|
|
|
connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
|
2013-12-10 19:33:24 +00:00
|
|
|
legacyDownloadJob.reset(dljob);
|
2013-09-01 22:25:40 +00:00
|
|
|
legacyDownloadJob->start();
|
2013-08-11 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::jarFinished()
|
|
|
|
{
|
|
|
|
// process the jar
|
2015-07-09 22:06:05 +00:00
|
|
|
emitSucceeded();
|
2013-08-11 22:39:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 11:47:14 +00:00
|
|
|
void LegacyUpdate::jarFailed(QString reason)
|
2013-08-11 22:39:19 +00:00
|
|
|
{
|
|
|
|
// bad, bad
|
2015-04-26 11:47:14 +00:00
|
|
|
emitFailed(tr("Failed to download the minecraft jar: %1.").arg(reason));
|
2013-08-11 22:39:19 +00:00
|
|
|
}
|