2015-02-03 03:55:30 +05:30
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2013-11-04 07:23:05 +05:30
|
|
|
*
|
|
|
|
* 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-09 00:50:10 +05:30
|
|
|
#include <QStringList>
|
2013-08-07 05:08:18 +05:30
|
|
|
#include <quazip.h>
|
|
|
|
#include <quazipfile.h>
|
2015-02-05 01:40:10 +05:30
|
|
|
#include <QDebug>
|
2014-05-09 00:50:10 +05:30
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "Env.h"
|
|
|
|
#include "BaseInstance.h"
|
|
|
|
#include "net/URLConstants.h"
|
2015-04-13 02:20:52 +05:30
|
|
|
#include "MMCZip.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
|
2015-07-26 21:25:29 +05:30
|
|
|
#include "LegacyUpdate.h"
|
2016-04-04 04:03:56 +05:30
|
|
|
#include "LegacyModList.h"
|
2015-07-26 21:25:29 +05:30
|
|
|
|
2016-02-28 00:28:40 +05:30
|
|
|
#include "LwjglVersionList.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "minecraft/MinecraftVersionList.h"
|
2016-02-28 00:28:40 +05:30
|
|
|
#include "LegacyInstance.h"
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2013-08-07 05:08:18 +05:30
|
|
|
|
2014-01-27 07:30:49 +05:30
|
|
|
LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
2013-10-06 04:43:40 +05:30
|
|
|
{
|
|
|
|
}
|
2013-08-07 05:08:18 +05:30
|
|
|
|
|
|
|
void LegacyUpdate::executeTask()
|
|
|
|
{
|
2014-04-20 00:54:11 +05:30
|
|
|
fmllibsStart();
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2014-04-20 00:54:11 +05:30
|
|
|
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-05 03:40:59 +05:30
|
|
|
auto & fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
|
2014-04-20 00:54:11 +05:30
|
|
|
if (!fmlLibsMapping.contains(version))
|
|
|
|
{
|
|
|
|
lwjglStart();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &libList = fmlLibsMapping[version];
|
|
|
|
|
|
|
|
// determine if we need some libs for FML or forge
|
|
|
|
setStatus(tr("Checking for FML libraries..."));
|
|
|
|
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-05 05:17:27 +05:30
|
|
|
QFileInfo libInfo(FS::PathCombine(inst->libDir(), lib.filename));
|
2014-04-20 00:54:11 +05:30
|
|
|
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
|
|
|
|
setStatus(tr("Dowloading FML libraries..."));
|
|
|
|
auto dljob = new NetJob("FML libraries");
|
2015-01-31 21:29:03 +05:30
|
|
|
auto metacache = ENV.metacache();
|
2014-04-20 00:54:11 +05:30
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
2014-04-23 05:57:40 +05:30
|
|
|
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;
|
2014-04-20 00:54:11 +05:30
|
|
|
dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry));
|
|
|
|
}
|
|
|
|
|
2015-04-26 17:17:14 +05:30
|
|
|
connect(dljob, &NetJob::succeeded, this, &LegacyUpdate::fmllibsFinished);
|
|
|
|
connect(dljob, &NetJob::failed, this, &LegacyUpdate::fmllibsFailed);
|
|
|
|
connect(dljob, &NetJob::progress, this, &LegacyUpdate::progress);
|
2014-04-20 00:54:11 +05:30
|
|
|
legacyDownloadJob.reset(dljob);
|
|
|
|
legacyDownloadJob->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::fmllibsFinished()
|
|
|
|
{
|
|
|
|
legacyDownloadJob.reset();
|
|
|
|
if(!fmlLibsToProcess.isEmpty())
|
|
|
|
{
|
|
|
|
setStatus(tr("Copying FML libraries into the instance..."));
|
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
2015-01-31 21:29:03 +05:30
|
|
|
auto metacache = ENV.metacache();
|
2014-04-20 00:54:11 +05:30
|
|
|
int index = 0;
|
|
|
|
for (auto &lib : fmlLibsToProcess)
|
|
|
|
{
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
2014-04-23 05:57:40 +05:30
|
|
|
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
2015-10-05 05:17:27 +05:30
|
|
|
auto path = FS::PathCombine(inst->libDir(), lib.filename);
|
|
|
|
if(!FS::ensureFilePathExists(path))
|
2014-04-20 00:54:11 +05:30
|
|
|
{
|
|
|
|
emitFailed(tr("Failed creating FML library folder inside the instance."));
|
|
|
|
return;
|
|
|
|
}
|
2015-10-05 05:17:27 +05:30
|
|
|
if (!QFile::copy(entry->getFullPath(), FS::PathCombine(inst->libDir(), lib.filename)))
|
2014-04-20 00:54:11 +05:30
|
|
|
{
|
2014-04-23 05:57:40 +05:30
|
|
|
emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
|
2014-04-20 00:54:11 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
progress(index, fmlLibsToProcess.size());
|
|
|
|
}
|
|
|
|
lwjglStart();
|
|
|
|
}
|
|
|
|
|
2015-04-26 17:17:14 +05:30
|
|
|
void LegacyUpdate::fmllibsFailed(QString reason)
|
2014-04-20 00:54:11 +05:30
|
|
|
{
|
2015-04-26 17:17:14 +05:30
|
|
|
emitFailed(tr("Game update failed: it was impossible to fetch the required FML libraries. Reason: %1").arg(reason));
|
2014-04-20 00:54:11 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
void LegacyUpdate::lwjglStart()
|
|
|
|
{
|
2013-10-06 04:43:40 +05:30
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
|
|
|
|
|
|
|
lwjglVersion = inst->lwjglVersion();
|
2015-10-05 05:17:27 +05:30
|
|
|
lwjglTargetPath = FS::PathCombine(inst->lwjglFolder(), lwjglVersion);
|
|
|
|
lwjglNativesPath = FS::PathCombine(lwjglTargetPath, "natives");
|
2013-08-09 03:56:35 +05:30
|
|
|
|
|
|
|
// if the 'done' file exists, we don't have to download this again
|
2015-10-05 05:17:27 +05:30
|
|
|
QFileInfo doneFile(FS::PathCombine(lwjglTargetPath, "done"));
|
2013-10-06 04:43:40 +05:30
|
|
|
if (doneFile.exists())
|
2013-08-09 03:56:35 +05:30
|
|
|
{
|
2013-08-12 04:09:19 +05:30
|
|
|
jarStart();
|
2013-08-09 03:56:35 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2015-02-02 05:39:28 +05:30
|
|
|
auto list = std::dynamic_pointer_cast<LWJGLVersionList>(ENV.getVersionList("org.lwjgl.legacy"));
|
2013-10-06 04:43:40 +05:30
|
|
|
if (!list->isLoaded())
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Too soon! Let the LWJGL list load :)");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2013-12-23 21:16:01 +05:30
|
|
|
setStatus(tr("Downloading new LWJGL..."));
|
2015-02-02 05:39:28 +05:30
|
|
|
auto version = std::dynamic_pointer_cast<LWJGLVersion>(list->findVersion(lwjglVersion));
|
2013-10-06 04:43:40 +05:30
|
|
|
if (!version)
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Game update failed: the selected LWJGL version is invalid.");
|
|
|
|
return;
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
QString url = version->url();
|
2013-08-07 05:19:19 +05:30
|
|
|
QUrl realUrl(url);
|
|
|
|
QString hostname = realUrl.host();
|
2015-01-31 21:29:03 +05:30
|
|
|
auto worker = ENV.qnam();
|
2013-08-07 05:19:19 +05:30
|
|
|
QNetworkRequest req(realUrl);
|
|
|
|
req.setRawHeader("Host", hostname.toLatin1());
|
2013-10-10 05:17:48 +05:30
|
|
|
req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
2013-10-06 04:43:40 +05:30
|
|
|
QNetworkReply *rep = worker->get(req);
|
|
|
|
|
|
|
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
2015-04-26 17:17:14 +05:30
|
|
|
connect(rep, &QNetworkReply::downloadProgress, this, &LegacyUpdate::progress);
|
|
|
|
connect(worker.get(), &QNetworkAccessManager::finished, this, &LegacyUpdate::lwjglFinished);
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2013-10-06 04:43:40 +05:30
|
|
|
void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-10-06 04:43:40 +05:30
|
|
|
if (m_reply.get() != reply)
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
if (reply->error() != QNetworkReply::NoError)
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-10-06 04:43:40 +05:30
|
|
|
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-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
2015-01-31 21:29:03 +05:30
|
|
|
auto worker = ENV.qnam();
|
2013-10-06 04:43:40 +05:30
|
|
|
// 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-07 05:08:18 +05:30
|
|
|
{
|
2013-10-06 04:43:40 +05:30
|
|
|
// you must tell which cookie goes with which url
|
2013-09-07 07:30:58 +05:30
|
|
|
worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net"));
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2013-10-06 04:43:40 +05:30
|
|
|
// here you can check for the 302 or whatever other header i need
|
2013-08-07 05:08:18 +05:30
|
|
|
QVariant newLoc = reply->header(QNetworkRequest::LocationHeader);
|
2013-10-06 04:43:40 +05:30
|
|
|
if (newLoc.isValid())
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
|
|
|
QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString();
|
2013-08-07 05:19:19 +05:30
|
|
|
QUrl realUrl(redirectedTo);
|
|
|
|
QString hostname = realUrl.host();
|
2013-08-07 05:08:18 +05:30
|
|
|
QNetworkRequest req(redirectedTo);
|
2013-08-07 05:19:19 +05:30
|
|
|
req.setRawHeader("Host", hostname.toLatin1());
|
2013-10-10 05:17:48 +05:30
|
|
|
req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
2013-10-06 04:43:40 +05:30
|
|
|
QNetworkReply *rep = worker->get(req);
|
2015-04-26 17:17:14 +05:30
|
|
|
connect(rep, &QNetworkReply::downloadProgress, this, &LegacyUpdate::progress);
|
2013-10-06 04:43:40 +05:30
|
|
|
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
QFile saveMe("lwjgl.zip");
|
|
|
|
saveMe.open(QIODevice::WriteOnly);
|
|
|
|
saveMe.write(m_reply->readAll());
|
|
|
|
saveMe.close();
|
2013-12-23 21:16:01 +05:30
|
|
|
setStatus(tr("Installing new LWJGL..."));
|
2013-08-07 05:08:18 +05:30
|
|
|
extractLwjgl();
|
2013-08-12 04:09:19 +05:30
|
|
|
jarStart();
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
void LegacyUpdate::extractLwjgl()
|
|
|
|
{
|
|
|
|
// make sure the directories are there
|
2013-08-09 03:56:35 +05:30
|
|
|
|
2015-10-05 05:17:27 +05:30
|
|
|
bool success = FS::ensureFolderPathExists(lwjglNativesPath);
|
2013-10-06 04:43:40 +05:30
|
|
|
|
|
|
|
if (!success)
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Failed to extract the lwjgl libs - error when creating required folders.");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
QuaZip zip("lwjgl.zip");
|
2013-10-06 04:43:40 +05:30
|
|
|
if (!zip.open(QuaZip::mdUnzip))
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Failed to extract the lwjgl libs - not a valid archive.");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
// and now we are going to access files inside it
|
|
|
|
QuaZipFile file(&zip);
|
2013-10-06 04:43:40 +05:30
|
|
|
const QString jarNames[] = {"jinput.jar", "lwjgl_util.jar", "lwjgl.jar"};
|
|
|
|
for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2013-10-06 04:43:40 +05:30
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
|
|
|
zip.close();
|
2013-08-09 03:56:35 +05:30
|
|
|
emitFailed("Failed to extract the lwjgl libs - error while reading archive.");
|
2013-08-07 05:08:18 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
QuaZipFileInfo info;
|
|
|
|
QString name = file.getActualFileName();
|
2013-10-06 04:43:40 +05:30
|
|
|
if (name.endsWith('/'))
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString destFileName;
|
|
|
|
// Look for the jars
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (name.endsWith(jarNames[i]))
|
|
|
|
{
|
2015-10-05 05:17:27 +05:30
|
|
|
destFileName = FS::PathCombine(lwjglTargetPath, jarNames[i]);
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
// Not found? look for the natives
|
2013-10-06 04:43:40 +05:30
|
|
|
if (destFileName.isEmpty())
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
QString nativesDir = "windows";
|
|
|
|
#else
|
2013-10-06 04:43:40 +05:30
|
|
|
#ifdef Q_OS_MAC
|
2013-08-26 06:23:29 +05:30
|
|
|
QString nativesDir = "macosx";
|
2013-10-06 04:43:40 +05:30
|
|
|
#else
|
2013-08-07 05:08:18 +05:30
|
|
|
QString nativesDir = "linux";
|
2013-10-06 04:43:40 +05:30
|
|
|
#endif
|
2013-08-07 05:08:18 +05:30
|
|
|
#endif
|
|
|
|
if (name.contains(nativesDir))
|
|
|
|
{
|
|
|
|
int lastSlash = name.lastIndexOf('/');
|
2013-09-16 04:24:39 +05:30
|
|
|
int lastBackSlash = name.lastIndexOf('\\');
|
2013-10-06 04:43:40 +05:30
|
|
|
if (lastSlash != -1)
|
|
|
|
name = name.mid(lastSlash + 1);
|
|
|
|
else if (lastBackSlash != -1)
|
|
|
|
name = name.mid(lastBackSlash + 1);
|
2015-10-05 05:17:27 +05:30
|
|
|
destFileName = FS::PathCombine(lwjglNativesPath, name);
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now if destFileName is still empty, go to the next file.
|
|
|
|
if (!destFileName.isEmpty())
|
|
|
|
{
|
2013-12-23 21:16:01 +05:30
|
|
|
setStatus(tr("Installing new LWJGL - extracting ") + name + "...");
|
2013-08-07 05:08:18 +05:30
|
|
|
QFile output(destFileName);
|
|
|
|
output.open(QIODevice::WriteOnly);
|
2015-07-21 12:51:59 +05:30
|
|
|
output.write(file.readAll());
|
2013-08-07 05:08:18 +05:30
|
|
|
output.close();
|
|
|
|
}
|
|
|
|
file.close(); // do not forget to close!
|
|
|
|
}
|
|
|
|
zip.close();
|
2013-10-06 04:43:40 +05:30
|
|
|
m_reply.reset();
|
2015-10-05 05:17:27 +05:30
|
|
|
QFile doneFile(FS::PathCombine(lwjglTargetPath, "done"));
|
2013-08-09 03:56:35 +05:30
|
|
|
doneFile.open(QIODevice::WriteOnly);
|
|
|
|
doneFile.write("done.");
|
|
|
|
doneFile.close();
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2015-04-26 17:17:14 +05:30
|
|
|
void LegacyUpdate::lwjglFailed(QString reason)
|
2013-08-07 05:08:18 +05:30
|
|
|
{
|
2015-04-26 17:17:14 +05:30
|
|
|
emitFailed(tr("Bad stuff happened while trying to get the lwjgl libs: %1").arg(reason));
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2013-08-12 04:09:19 +05:30
|
|
|
void LegacyUpdate::jarStart()
|
|
|
|
{
|
2013-10-06 04:43:40 +05:30
|
|
|
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
|
|
|
if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar())
|
2013-08-12 04:09:19 +05:30
|
|
|
{
|
2015-07-10 03:36:05 +05:30
|
|
|
emitSucceeded();
|
2013-08-12 04:09:19 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2013-12-23 21:16:01 +05:30
|
|
|
setStatus(tr("Checking for jar updates..."));
|
2013-08-12 04:09:19 +05:30
|
|
|
// Make directories
|
|
|
|
QDir binDir(inst->binDir());
|
|
|
|
if (!binDir.exists() && !binDir.mkpath("."))
|
|
|
|
{
|
|
|
|
emitFailed("Failed to create bin folder.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a list of URLs that will need to be downloaded.
|
2013-12-23 21:16:01 +05:30
|
|
|
setStatus(tr("Downloading new minecraft.jar ..."));
|
2013-08-12 04:09:19 +05:30
|
|
|
|
2013-12-11 01:03:24 +05:30
|
|
|
QString version_id = inst->intendedVersionId();
|
2013-10-06 04:43:40 +05:30
|
|
|
|
2013-12-11 01:03:24 +05:30
|
|
|
auto dljob = new NetJob("Minecraft.jar for version " + version_id);
|
|
|
|
|
2015-01-31 21:29:03 +05:30
|
|
|
auto metacache = ENV.metacache();
|
2016-03-26 21:26:57 +05:30
|
|
|
auto entry = metacache->resolveEntry("versions", URLConstants::getJarPath(version_id));
|
|
|
|
dljob->addNetAction(CacheDownload::make(QUrl(URLConstants::getLegacyJarUrl(version_id)), entry));
|
2013-09-08 23:46:38 +05:30
|
|
|
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
|
2015-04-26 17:17:14 +05:30
|
|
|
connect(dljob, SIGNAL(failed(QString)), SLOT(jarFailed(QString)));
|
2013-10-06 04:43:40 +05:30
|
|
|
connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
|
2013-12-11 01:03:24 +05:30
|
|
|
legacyDownloadJob.reset(dljob);
|
2013-09-02 03:55:40 +05:30
|
|
|
legacyDownloadJob->start();
|
2013-08-12 04:09:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LegacyUpdate::jarFinished()
|
|
|
|
{
|
|
|
|
// process the jar
|
2015-07-10 03:36:05 +05:30
|
|
|
emitSucceeded();
|
2013-08-12 04:09:19 +05:30
|
|
|
}
|
|
|
|
|
2015-04-26 17:17:14 +05:30
|
|
|
void LegacyUpdate::jarFailed(QString reason)
|
2013-08-12 04:09:19 +05:30
|
|
|
{
|
|
|
|
// bad, bad
|
2015-04-26 17:17:14 +05:30
|
|
|
emitFailed(tr("Failed to download the minecraft jar: %1.").arg(reason));
|
2013-08-12 04:09:19 +05:30
|
|
|
}
|