Пример #1
0
void LegacyUpdate::fmllibsFinished()
{
	legacyDownloadJob.reset();
	if(!fmlLibsToProcess.isEmpty())
	{
		setStatus(tr("Copying FML libraries into the instance..."));
		LegacyInstance *inst = (LegacyInstance *)m_inst;
		auto metacache = MMC->metacache();
		int index = 0;
		for (auto &lib : fmlLibsToProcess)
		{
			progress(index, fmlLibsToProcess.size());
			auto entry = metacache->resolveEntry("fmllibs", lib.name);
			auto path = PathCombine(inst->libDir(), lib.name);
			if(!ensureFilePathExists(path))
			{
				emitFailed(tr("Failed creating FML library folder inside the instance."));
				return;
			}
			if (!QFile::copy(entry->getFullPath(), PathCombine(inst->libDir(), lib.name)))
			{
				emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.name));
				return;
			}
			index++;
		}
		progress(index, fmlLibsToProcess.size());
	}
	lwjglStart();
}
Пример #2
0
void CacheDownload::start()
{
    if (!m_entry->stale)
    {
        emit succeeded(index_within_job);
        return;
    }
    m_output_file.setFileName(m_target_path);
    // if there already is a file and md5 checking is in effect and it can be opened
    if (!ensureFilePathExists(m_target_path))
    {
        emit failed(index_within_job);
        return;
    }
    QLOG_INFO() << "Downloading " << m_url.toString();
    QNetworkRequest request(m_url);
    if (m_entry->remote_changed_timestamp.size())
        request.setRawHeader(QString("If-Modified-Since").toLatin1(),
                             m_entry->remote_changed_timestamp.toLatin1());
    if (m_entry->etag.size())
        request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());

    request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");

    auto worker = MMC->qnam();
    QNetworkReply *rep = worker->get(request);

    m_reply = std::shared_ptr<QNetworkReply>(rep);
    connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
            SLOT(downloadProgress(qint64, qint64)));
    connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
    connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
            SLOT(downloadError(QNetworkReply::NetworkError)));
    connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
}
Пример #3
0
void OneSixUpdate::versionFileFinished()
{
	NetActionPtr DlJob = specificVersionDownloadJob->first();
	OneSixInstance *inst = (OneSixInstance *)m_inst;

	QString version_id = targetVersion->descriptor();
	QString inst_dir = m_inst->instanceRoot();
	// save the version file in $instanceId/version.json
	{
		QString version1 = PathCombine(inst_dir, "/version.json");
		ensureFilePathExists(version1);
		// FIXME: detect errors here, download to a temp file, swap
		QSaveFile vfile1(version1);
		if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly))
		{
			emitFailed("Can't open " + version1 + " for writing.");
			return;
		}
		auto data = std::dynamic_pointer_cast<ByteArrayDownload>(DlJob)->m_data;
		qint64 actual = 0;
		if ((actual = vfile1.write(data)) != data.size())
		{
			emitFailed("Failed to write into " + version1 + ". Written " + actual + " out of " +
					   data.size() + '.');
			return;
		}
		if (!vfile1.commit())
		{
			emitFailed("Can't commit changes to " + version1);
			return;
		}
	}

	// the version is downloaded safely. update is 'done' at this point
	m_inst->setShouldUpdate(false);

	// delete any custom version inside the instance (it's no longer relevant, we did an update)
	QString custom = PathCombine(inst_dir, "/custom.json");
	QFile finfo(custom);
	if (finfo.exists())
	{
		finfo.remove();
	}
	inst->reloadFullVersion();

	jarlibStart();
}