NOISSUE Revert all recent changes to NetAction and NetJob
This commit is contained in:
		| @@ -26,7 +26,7 @@ InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, BaseInstanceProvi | |||||||
|  |  | ||||||
| void InstanceCopyTask::executeTask() | void InstanceCopyTask::executeTask() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Copying instance %1").arg(m_origInstance->name())); | 	setStatus(tr("Copying instance %1").arg(m_origInstance->name())); | ||||||
| 	m_stagingPath = m_target->getStagedInstancePath(); | 	m_stagingPath = m_target->getStagedInstancePath(); | ||||||
| 	FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath); | 	FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath); | ||||||
| 	folderCopy.followSymlinks(false).blacklist(m_matcher.get()); | 	folderCopy.followSymlinks(false).blacklist(m_matcher.get()); | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInsta | |||||||
|  |  | ||||||
| void InstanceCreationTask::executeTask() | void InstanceCreationTask::executeTask() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Creating instance from version %1").arg(m_version->name())); | 	setStatus(tr("Creating instance from version %1").arg(m_version->name())); | ||||||
|     /* |     /* | ||||||
| 	auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_version); | 	auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_version); | ||||||
| 	if(!minecraftVersion) | 	if(!minecraftVersion) | ||||||
|   | |||||||
| @@ -38,7 +38,7 @@ void InstanceImportTask::executeTask() | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		setStatusText(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString())); | 		setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString())); | ||||||
| 		m_downloadRequired = true; | 		m_downloadRequired = true; | ||||||
|  |  | ||||||
| 		const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path(); | 		const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path(); | ||||||
| @@ -94,7 +94,7 @@ static QFileInfo findRecursive(const QString &dir, const QString &name) | |||||||
|  |  | ||||||
| void InstanceImportTask::extractAndTweak() | void InstanceImportTask::extractAndTweak() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Extracting modpack")); | 	setStatus(tr("Extracting modpack")); | ||||||
| 	m_stagingPath = m_target->getStagedInstancePath(); | 	m_stagingPath = m_target->getStagedInstancePath(); | ||||||
| 	QDir extractDir(m_stagingPath); | 	QDir extractDir(m_stagingPath); | ||||||
| 	qDebug() << "Attempting to create instance from" << m_archivePath; | 	qDebug() << "Attempting to create instance from" << m_archivePath; | ||||||
| @@ -321,7 +321,7 @@ void InstanceImportTask::processFlame(const QFileInfo & manifest) | |||||||
| 		{ | 		{ | ||||||
| 			setProgress(current, total); | 			setProgress(current, total); | ||||||
| 		}); | 		}); | ||||||
| 		setStatusText(tr("Downloading mods...")); | 		setStatus(tr("Downloading mods...")); | ||||||
| 		m_filesNetJob->start(); | 		m_filesNetJob->start(); | ||||||
| 	} | 	} | ||||||
| 	); | 	); | ||||||
| @@ -337,7 +337,7 @@ void InstanceImportTask::processFlame(const QFileInfo & manifest) | |||||||
| 	}); | 	}); | ||||||
| 	connect(m_modIdResolver.get(), &Flame::FileResolvingTask::status, [&](QString status) | 	connect(m_modIdResolver.get(), &Flame::FileResolvingTask::status, [&](QString status) | ||||||
| 	{ | 	{ | ||||||
| 		setStatusText(status); | 		setStatus(status); | ||||||
| 	}); | 	}); | ||||||
| 	m_modIdResolver->start(); | 	m_modIdResolver->start(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -144,7 +144,7 @@ JavaListLoadTask::~JavaListLoadTask() | |||||||
|  |  | ||||||
| void JavaListLoadTask::executeTask() | void JavaListLoadTask::executeTask() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Detecting Java installations...")); | 	setStatus(tr("Detecting Java installations...")); | ||||||
|  |  | ||||||
| 	JavaUtils ju; | 	JavaUtils ju; | ||||||
| 	QList<QString> candidate_paths = ju.FindJavaPaths(); | 	QList<QString> candidate_paths = ju.FindJavaPaths(); | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ void Update::executeTask() | |||||||
| 	{ | 	{ | ||||||
| 		connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished())); | 		connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished())); | ||||||
| 		connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress); | 		connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress); | ||||||
| 		connect(m_updateTask.get(), &Task::status, this, &Task::setStatusText); | 		connect(m_updateTask.get(), &Task::status, this, &Task::setStatus); | ||||||
| 		emit progressReportingRequest(); | 		emit progressReportingRequest(); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -199,7 +199,7 @@ NetActionPtr AssetObject::getDownloadAction() | |||||||
| 			auto rawHash = QByteArray::fromHex(hash.toLatin1()); | 			auto rawHash = QByteArray::fromHex(hash.toLatin1()); | ||||||
| 			objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash)); | 			objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash)); | ||||||
| 		} | 		} | ||||||
| 		objectDL->setProgress(0, size); | 		objectDL->m_total_progress = size; | ||||||
| 		return objectDL; | 		return objectDL; | ||||||
| 	} | 	} | ||||||
| 	return nullptr; | 	return nullptr; | ||||||
|   | |||||||
| @@ -51,7 +51,7 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| QList<NetActionPtr> Library::getDownloads(OpSys system, class HttpMetaCache* cache, | QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class HttpMetaCache* cache, | ||||||
| 															QStringList& failedFiles, const QString & overridePath) const | 															QStringList& failedFiles, const QString & overridePath) const | ||||||
| { | { | ||||||
| 	QList<NetActionPtr> out; | 	QList<NetActionPtr> out; | ||||||
|   | |||||||
| @@ -43,7 +43,7 @@ void SkinUpload::executeTask() | |||||||
| 	QNetworkReply *rep = ENV.qnam().put(request, multiPart); | 	QNetworkReply *rep = ENV.qnam().put(request, multiPart); | ||||||
| 	m_reply = std::shared_ptr<QNetworkReply>(rep); | 	m_reply = std::shared_ptr<QNetworkReply>(rep); | ||||||
|  |  | ||||||
| 	setStatusText(tr("Uploading skin")); | 	setStatus(tr("Uploading skin")); | ||||||
| 	connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress); | 	connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress); | ||||||
| 	connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); | 	connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); | ||||||
| 	connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); | 	connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); | ||||||
|   | |||||||
| @@ -237,7 +237,7 @@ QString YggdrasilTask::getStateMessage() const | |||||||
| void YggdrasilTask::changeState(YggdrasilTask::State newState, QString reason) | void YggdrasilTask::changeState(YggdrasilTask::State newState, QString reason) | ||||||
| { | { | ||||||
| 	m_state = newState; | 	m_state = newState; | ||||||
| 	setStatusText(getStateMessage()); | 	setStatus(getStateMessage()); | ||||||
| 	if (newState == STATE_SUCCEEDED) | 	if (newState == STATE_SUCCEEDED) | ||||||
| 	{ | 	{ | ||||||
| 		emitSucceeded(); | 		emitSucceeded(); | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ Flame::FileResolvingTask::FileResolvingTask(Flame::Manifest& toProcess) | |||||||
|  |  | ||||||
| void Flame::FileResolvingTask::executeTask() | void Flame::FileResolvingTask::executeTask() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Resolving mod IDs...")); | 	setStatus(tr("Resolving mod IDs...")); | ||||||
| 	setProgress(0, m_toProcess.files.size()); | 	setProgress(0, m_toProcess.files.size()); | ||||||
| 	m_dljob.reset(new NetJob("Mod id resolver")); | 	m_dljob.reset(new NetJob("Mod id resolver")); | ||||||
| 	results.resize(m_toProcess.files.size()); | 	results.resize(m_toProcess.files.size()); | ||||||
|   | |||||||
| @@ -28,31 +28,31 @@ ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : Ne | |||||||
| 	m_entry = entry; | 	m_entry = entry; | ||||||
| 	m_target_path = entry->getFullPath(); | 	m_target_path = entry->getFullPath(); | ||||||
| 	m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX"); | 	m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX"); | ||||||
| 	m_status = Status::NotStarted; | 	m_status = Job_NotStarted; | ||||||
| 	m_url_path = relative_path; | 	m_url_path = relative_path; | ||||||
| 	m_url = "http://files.minecraftforge.net/maven/" + m_url_path + ".pack.xz"; | 	m_url = "http://files.minecraftforge.net/maven/" + m_url_path + ".pack.xz"; | ||||||
| } | } | ||||||
|  |  | ||||||
| void ForgeXzDownload::executeTask() | void ForgeXzDownload::start() | ||||||
| { | { | ||||||
| 	if(m_status == Status::Aborted) | 	if(m_status == Job_Aborted) | ||||||
| 	{ | 	{ | ||||||
| 		qWarning() << "Attempt to start an aborted Download:" << m_url.toString(); | 		qWarning() << "Attempt to start an aborted Download:" << m_url.toString(); | ||||||
| 		emit aborted(); | 		emit aborted(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	m_status = Status::InProgress; | 	m_status = Job_InProgress; | ||||||
| 	if (!m_entry->isStale()) | 	if (!m_entry->isStale()) | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Finished; | 		m_status = Job_Finished; | ||||||
| 		emit succeeded(); | 		emit succeeded(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	// can we actually create the real, final file? | 	// can we actually create the real, final file? | ||||||
| 	if (!FS::ensureFilePathExists(m_target_path)) | 	if (!FS::ensureFilePathExists(m_target_path)) | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Failed; | 		m_status = Job_Failed; | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -72,9 +72,9 @@ void ForgeXzDownload::executeTask() | |||||||
|  |  | ||||||
| void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | ||||||
| { | { | ||||||
| 	m_progressTotal = bytesTotal; | 	m_total_progress = bytesTotal; | ||||||
| 	m_progress = bytesReceived; | 	m_progress = bytesReceived; | ||||||
| 	emit progress(bytesReceived, bytesTotal); | 	emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) | void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) | ||||||
| @@ -82,29 +82,29 @@ void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) | |||||||
| 	if(error == QNetworkReply::OperationCanceledError) | 	if(error == QNetworkReply::OperationCanceledError) | ||||||
| 	{ | 	{ | ||||||
| 		qCritical() << "Aborted " << m_url.toString(); | 		qCritical() << "Aborted " << m_url.toString(); | ||||||
| 		m_status = Status::Aborted; | 		m_status = Job_Aborted; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		// error happened during download. | 		// error happened during download. | ||||||
| 		qCritical() << "Failed " << m_url.toString() << " with reason " << error; | 		qCritical() << "Failed " << m_url.toString() << " with reason " << error; | ||||||
| 		m_status = Status::Failed; | 		m_status = Job_Failed; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| void ForgeXzDownload::failAndTryNextMirror() | void ForgeXzDownload::failAndTryNextMirror() | ||||||
| { | { | ||||||
| 	m_status = Status::Failed; | 	m_status = Job_Failed; | ||||||
| 	emit failed(); | 	emit failed(m_index_within_job); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ForgeXzDownload::downloadFinished() | void ForgeXzDownload::downloadFinished() | ||||||
| { | { | ||||||
| 	// if the download succeeded | 	// if the download succeeded | ||||||
| 	if (m_status != Status::Failed && m_status != Status::Aborted) | 	if (m_status != Job_Failed && m_status != Job_Aborted) | ||||||
| 	{ | 	{ | ||||||
| 		// nothing went wrong... | 		// nothing went wrong... | ||||||
| 		m_status = Status::Finished; | 		m_status = Job_Finished; | ||||||
| 		if (m_pack200_xz_file.isOpen()) | 		if (m_pack200_xz_file.isOpen()) | ||||||
| 		{ | 		{ | ||||||
| 			// we actually downloaded something! process and isntall it | 			// we actually downloaded something! process and isntall it | ||||||
| @@ -114,25 +114,25 @@ void ForgeXzDownload::downloadFinished() | |||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
| 			// something bad happened -- on the local machine! | 			// something bad happened -- on the local machine! | ||||||
| 			m_status = Status::Failed; | 			m_status = Job_Failed; | ||||||
| 			m_pack200_xz_file.remove(); | 			m_pack200_xz_file.remove(); | ||||||
| 			m_reply.reset(); | 			m_reply.reset(); | ||||||
| 			emit failed(); | 			emit failed(m_index_within_job); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	else if(m_status == Status::Aborted) | 	else if(m_status == Job_Aborted) | ||||||
| 	{ | 	{ | ||||||
| 		m_pack200_xz_file.remove(); | 		m_pack200_xz_file.remove(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		emit aborted(); | 		emit aborted(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	// else the download failed | 	// else the download failed | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Failed; | 		m_status = Job_Failed; | ||||||
| 		m_pack200_xz_file.close(); | 		m_pack200_xz_file.close(); | ||||||
| 		m_pack200_xz_file.remove(); | 		m_pack200_xz_file.remove(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| @@ -152,7 +152,7 @@ void ForgeXzDownload::downloadReadyRead() | |||||||
| 			* Can't open the file... the job failed | 			* Can't open the file... the job failed | ||||||
| 			*/ | 			*/ | ||||||
| 			m_reply->abort(); | 			m_reply->abort(); | ||||||
| 			emit failed(); | 			emit failed(m_index_within_job); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -345,7 +345,7 @@ void ForgeXzDownload::decompressAndInstall() | |||||||
| 	} | 	} | ||||||
| 	catch (std::runtime_error &err) | 	catch (std::runtime_error &err) | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Failed; | 		m_status = Job_Failed; | ||||||
| 		qCritical() << "Error unpacking " << pack200_file.fileName() << " : " << err.what(); | 		qCritical() << "Error unpacking " << pack200_file.fileName() << " : " << err.what(); | ||||||
| 		QFile f(m_target_path); | 		QFile f(m_target_path); | ||||||
| 		if (f.exists()) | 		if (f.exists()) | ||||||
| @@ -374,18 +374,18 @@ void ForgeXzDownload::decompressAndInstall() | |||||||
| 	ENV.metacache()->updateEntry(m_entry); | 	ENV.metacache()->updateEntry(m_entry); | ||||||
|  |  | ||||||
| 	m_reply.reset(); | 	m_reply.reset(); | ||||||
| 	emit succeeded(); | 	emit succeeded(m_index_within_job); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool ForgeXzDownload::abort() | bool ForgeXzDownload::abort() | ||||||
| { | { | ||||||
| 	if(m_reply) | 	if(m_reply) | ||||||
| 		m_reply->abort(); | 		m_reply->abort(); | ||||||
| 	m_status = Status::Aborted; | 	m_status = Job_Aborted; | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool ForgeXzDownload::canAbort() const | bool ForgeXzDownload::canAbort() | ||||||
| { | { | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,9 +19,8 @@ | |||||||
| #include "net/HttpMetaCache.h" | #include "net/HttpMetaCache.h" | ||||||
| #include <QFile> | #include <QFile> | ||||||
| #include <QTemporaryFile> | #include <QTemporaryFile> | ||||||
| #include "QObjectPtr.h" |  | ||||||
|  |  | ||||||
| typedef shared_qobject_ptr<class ForgeXzDownload> ForgeXzDownloadPtr; | typedef std::shared_ptr<class ForgeXzDownload> ForgeXzDownloadPtr; | ||||||
|  |  | ||||||
| class ForgeXzDownload : public NetAction | class ForgeXzDownload : public NetAction | ||||||
| { | { | ||||||
| @@ -42,7 +41,7 @@ public: | |||||||
| 		return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry)); | 		return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry)); | ||||||
| 	} | 	} | ||||||
| 	virtual ~ForgeXzDownload(){}; | 	virtual ~ForgeXzDownload(){}; | ||||||
| 	bool canAbort() const override; | 	bool canAbort() override; | ||||||
|  |  | ||||||
| protected | protected | ||||||
| slots: | slots: | ||||||
| @@ -53,7 +52,7 @@ slots: | |||||||
|  |  | ||||||
| public | public | ||||||
| slots: | slots: | ||||||
| 	void executeTask() override; | 	void start() override; | ||||||
| 	bool abort() override; | 	bool abort() override; | ||||||
|  |  | ||||||
| private: | private: | ||||||
|   | |||||||
| @@ -131,7 +131,7 @@ std::shared_ptr<Task> LegacyInstance::createJarModdingTask() | |||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				setStatusText(tr("Installing mods: Backing up minecraft.jar ...")); | 				setStatus(tr("Installing mods: Backing up minecraft.jar ...")); | ||||||
| 				if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath())) | 				if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath())) | ||||||
| 				{ | 				{ | ||||||
| 					emitFailed("It seems both the active and base jar are gone. A fresh base jar will " | 					emitFailed("It seems both the active and base jar are gone. A fresh base jar will " | ||||||
| @@ -155,7 +155,7 @@ std::shared_ptr<Task> LegacyInstance::createJarModdingTask() | |||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			setStatusText(tr("Installing mods: Opening minecraft.jar ...")); | 			setStatus(tr("Installing mods: Opening minecraft.jar ...")); | ||||||
|  |  | ||||||
| 			QString outputJarPath = runnableJar.filePath(); | 			QString outputJarPath = runnableJar.filePath(); | ||||||
| 			QString inputJarPath = baseJar.filePath(); | 			QString inputJarPath = baseJar.filePath(); | ||||||
|   | |||||||
| @@ -58,7 +58,7 @@ void LegacyUpdate::fmllibsStart() | |||||||
| 	auto &libList = fmlLibsMapping[version]; | 	auto &libList = fmlLibsMapping[version]; | ||||||
|  |  | ||||||
| 	// determine if we need some libs for FML or forge | 	// determine if we need some libs for FML or forge | ||||||
| 	setStatusText(tr("Checking for FML libraries...")); | 	setStatus(tr("Checking for FML libraries...")); | ||||||
| 	for (unsigned i = 0; i < modList->size(); i++) | 	for (unsigned i = 0; i < modList->size(); i++) | ||||||
| 	{ | 	{ | ||||||
| 		auto &mod = modList->operator[](i); | 		auto &mod = modList->operator[](i); | ||||||
| @@ -105,7 +105,7 @@ void LegacyUpdate::fmllibsStart() | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// download missing libs to our place | 	// download missing libs to our place | ||||||
| 	setStatusText(tr("Dowloading FML libraries...")); | 	setStatus(tr("Dowloading FML libraries...")); | ||||||
| 	auto dljob = new NetJob("FML libraries"); | 	auto dljob = new NetJob("FML libraries"); | ||||||
| 	auto metacache = ENV.metacache(); | 	auto metacache = ENV.metacache(); | ||||||
| 	for (auto &lib : fmlLibsToProcess) | 	for (auto &lib : fmlLibsToProcess) | ||||||
| @@ -128,7 +128,7 @@ void LegacyUpdate::fmllibsFinished() | |||||||
| 	legacyDownloadJob.reset(); | 	legacyDownloadJob.reset(); | ||||||
| 	if(!fmlLibsToProcess.isEmpty()) | 	if(!fmlLibsToProcess.isEmpty()) | ||||||
| 	{ | 	{ | ||||||
| 		setStatusText(tr("Copying FML libraries into the instance...")); | 		setStatus(tr("Copying FML libraries into the instance...")); | ||||||
| 		LegacyInstance *inst = (LegacyInstance *)m_inst; | 		LegacyInstance *inst = (LegacyInstance *)m_inst; | ||||||
| 		auto metacache = ENV.metacache(); | 		auto metacache = ENV.metacache(); | ||||||
| 		int index = 0; | 		int index = 0; | ||||||
| @@ -183,7 +183,7 @@ void LegacyUpdate::lwjglStart() | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	setStatusText(tr("Downloading new LWJGL...")); | 	setStatus(tr("Downloading new LWJGL...")); | ||||||
| 	auto version = std::dynamic_pointer_cast<LWJGLVersion>(list->findVersion(lwjglVersion)); | 	auto version = std::dynamic_pointer_cast<LWJGLVersion>(list->findVersion(lwjglVersion)); | ||||||
| 	if (!version) | 	if (!version) | ||||||
| 	{ | 	{ | ||||||
| @@ -247,7 +247,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply *reply) | |||||||
| 	saveMe.open(QIODevice::WriteOnly); | 	saveMe.open(QIODevice::WriteOnly); | ||||||
| 	saveMe.write(m_reply->readAll()); | 	saveMe.write(m_reply->readAll()); | ||||||
| 	saveMe.close(); | 	saveMe.close(); | ||||||
| 	setStatusText(tr("Installing new LWJGL...")); | 	setStatus(tr("Installing new LWJGL...")); | ||||||
| 	extractLwjgl(); | 	extractLwjgl(); | ||||||
| 	jarStart(); | 	jarStart(); | ||||||
| } | } | ||||||
| @@ -323,7 +323,7 @@ void LegacyUpdate::extractLwjgl() | |||||||
| 		// Now if destFileName is still empty, go to the next file. | 		// Now if destFileName is still empty, go to the next file. | ||||||
| 		if (!destFileName.isEmpty()) | 		if (!destFileName.isEmpty()) | ||||||
| 		{ | 		{ | ||||||
| 			setStatusText(tr("Installing new LWJGL - extracting ") + name + "..."); | 			setStatus(tr("Installing new LWJGL - extracting ") + name + "..."); | ||||||
| 			QFile output(destFileName); | 			QFile output(destFileName); | ||||||
| 			output.open(QIODevice::WriteOnly); | 			output.open(QIODevice::WriteOnly); | ||||||
| 			output.write(file.readAll()); | 			output.write(file.readAll()); | ||||||
| @@ -353,7 +353,7 @@ void LegacyUpdate::jarStart() | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	setStatusText(tr("Checking for jar updates...")); | 	setStatus(tr("Checking for jar updates...")); | ||||||
| 	// Make directories | 	// Make directories | ||||||
| 	QDir binDir(inst->binRoot()); | 	QDir binDir(inst->binRoot()); | ||||||
| 	if (!binDir.exists() && !binDir.mkpath(".")) | 	if (!binDir.exists() && !binDir.mkpath(".")) | ||||||
| @@ -363,7 +363,7 @@ void LegacyUpdate::jarStart() | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Build a list of URLs that will need to be downloaded. | 	// Build a list of URLs that will need to be downloaded. | ||||||
| 	setStatusText(tr("Downloading new minecraft.jar ...")); | 	setStatus(tr("Downloading new minecraft.jar ...")); | ||||||
|  |  | ||||||
| 	QString version_id = inst->intendedVersionId(); | 	QString version_id = inst->intendedVersionId(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -41,7 +41,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent) | |||||||
| { | { | ||||||
| 	// create folders | 	// create folders | ||||||
| 	{ | 	{ | ||||||
| 		m_tasks.append(new FoldersTask(m_inst)); | 		m_tasks.append(std::make_shared<FoldersTask>(m_inst)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// add metadata update tasks, if necessary | 	// add metadata update tasks, if necessary | ||||||
| @@ -66,7 +66,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent) | |||||||
| 				if(task) | 				if(task) | ||||||
| 				{ | 				{ | ||||||
| 					qDebug() << "Loading remote meta patch" << id; | 					qDebug() << "Loading remote meta patch" << id; | ||||||
| 					m_tasks.append(task); | 					m_tasks.append(task.unwrap()); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| @@ -78,17 +78,17 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent) | |||||||
|  |  | ||||||
| 	// libraries download | 	// libraries download | ||||||
| 	{ | 	{ | ||||||
| 		m_tasks.append(new LibrariesTask(m_inst)); | 		m_tasks.append(std::make_shared<LibrariesTask>(m_inst)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// FML libraries download and copy into the instance | 	// FML libraries download and copy into the instance | ||||||
| 	{ | 	{ | ||||||
| 		m_tasks.append(new FMLLibrariesTask(m_inst)); | 		m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// assets update | 	// assets update | ||||||
| 	{ | 	{ | ||||||
| 		m_tasks.append(new AssetUpdateTask(m_inst)); | 		m_tasks.append(std::make_shared<AssetUpdateTask>(m_inst)); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -116,7 +116,7 @@ void OneSixUpdate::next() | |||||||
| 		disconnect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded); | 		disconnect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded); | ||||||
| 		disconnect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed); | 		disconnect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed); | ||||||
| 		disconnect(task.get(), &Task::progress, this, &OneSixUpdate::progress); | 		disconnect(task.get(), &Task::progress, this, &OneSixUpdate::progress); | ||||||
| 		disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatusText); | 		disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatus); | ||||||
| 	} | 	} | ||||||
| 	if(m_currentTask == m_tasks.size()) | 	if(m_currentTask == m_tasks.size()) | ||||||
| 	{ | 	{ | ||||||
| @@ -132,7 +132,7 @@ void OneSixUpdate::next() | |||||||
| 	connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded); | 	connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded); | ||||||
| 	connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed); | 	connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed); | ||||||
| 	connect(task.get(), &Task::progress, this, &OneSixUpdate::progress); | 	connect(task.get(), &Task::progress, this, &OneSixUpdate::progress); | ||||||
| 	connect(task.get(), &Task::status, this, &OneSixUpdate::setStatusText); | 	connect(task.get(), &Task::status, this, &OneSixUpdate::setStatus); | ||||||
| 	// if the task is already running, do not start it again | 	// if the task is already running, do not start it again | ||||||
| 	if(!task->isRunning()) | 	if(!task->isRunning()) | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ private: | |||||||
|  |  | ||||||
| private: | private: | ||||||
| 	OneSixInstance *m_inst = nullptr; | 	OneSixInstance *m_inst = nullptr; | ||||||
| 	QList<shared_qobject_ptr<Task>> m_tasks; | 	QList<std::shared_ptr<Task>> m_tasks; | ||||||
| 	QString m_preFailure; | 	QString m_preFailure; | ||||||
| 	int m_currentTask = -1; | 	int m_currentTask = -1; | ||||||
| 	bool m_abort = false; | 	bool m_abort = false; | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ AssetUpdateTask::AssetUpdateTask(OneSixInstance * inst) | |||||||
| } | } | ||||||
| void AssetUpdateTask::executeTask() | void AssetUpdateTask::executeTask() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Updating assets index...")); | 	setStatus(tr("Updating assets index...")); | ||||||
| 	auto profile = m_inst->getMinecraftProfile(); | 	auto profile = m_inst->getMinecraftProfile(); | ||||||
| 	auto assets = profile->getMinecraftAssets(); | 	auto assets = profile->getMinecraftAssets(); | ||||||
| 	QUrl indexUrl = assets->url; | 	QUrl indexUrl = assets->url; | ||||||
| @@ -63,7 +63,7 @@ void AssetUpdateTask::assetIndexFinished() | |||||||
| 	auto job = index.getDownloadJob(); | 	auto job = index.getDownloadJob(); | ||||||
| 	if(job) | 	if(job) | ||||||
| 	{ | 	{ | ||||||
| 		setStatusText(tr("Getting the assets files from Mojang...")); | 		setStatus(tr("Getting the assets files from Mojang...")); | ||||||
| 		downloadJob = job; | 		downloadJob = job; | ||||||
| 		connect(downloadJob.get(), &NetJob::succeeded, this, &AssetUpdateTask::emitSucceeded); | 		connect(downloadJob.get(), &NetJob::succeeded, this, &AssetUpdateTask::emitSucceeded); | ||||||
| 		connect(downloadJob.get(), &NetJob::failed, this, &AssetUpdateTask::assetsFailed); | 		connect(downloadJob.get(), &NetJob::failed, this, &AssetUpdateTask::assetsFailed); | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ void FMLLibrariesTask::executeTask() | |||||||
| 	auto &libList = fmlLibsMapping[version]; | 	auto &libList = fmlLibsMapping[version]; | ||||||
|  |  | ||||||
| 	// determine if we need some libs for FML or forge | 	// determine if we need some libs for FML or forge | ||||||
| 	setStatusText(tr("Checking for FML libraries...")); | 	setStatus(tr("Checking for FML libraries...")); | ||||||
| 	forge_present = (profile->versionPatch("net.minecraftforge") != nullptr); | 	forge_present = (profile->versionPatch("net.minecraftforge") != nullptr); | ||||||
| 	// we don't... | 	// we don't... | ||||||
| 	if (!forge_present) | 	if (!forge_present) | ||||||
| @@ -58,7 +58,7 @@ void FMLLibrariesTask::executeTask() | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// download missing libs to our place | 	// download missing libs to our place | ||||||
| 	setStatusText(tr("Dowloading FML libraries...")); | 	setStatus(tr("Dowloading FML libraries...")); | ||||||
| 	auto dljob = new NetJob("FML libraries"); | 	auto dljob = new NetJob("FML libraries"); | ||||||
| 	auto metacache = ENV.metacache(); | 	auto metacache = ENV.metacache(); | ||||||
| 	for (auto &lib : fmlLibsToProcess) | 	for (auto &lib : fmlLibsToProcess) | ||||||
| @@ -86,7 +86,7 @@ void FMLLibrariesTask::fmllibsFinished() | |||||||
| 	downloadJob.reset(); | 	downloadJob.reset(); | ||||||
| 	if (!fmlLibsToProcess.isEmpty()) | 	if (!fmlLibsToProcess.isEmpty()) | ||||||
| 	{ | 	{ | ||||||
| 		setStatusText(tr("Copying FML libraries into the instance...")); | 		setStatus(tr("Copying FML libraries into the instance...")); | ||||||
| 		OneSixInstance *inst = (OneSixInstance *)m_inst; | 		OneSixInstance *inst = (OneSixInstance *)m_inst; | ||||||
| 		auto metacache = ENV.metacache(); | 		auto metacache = ENV.metacache(); | ||||||
| 		int index = 0; | 		int index = 0; | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ LibrariesTask::LibrariesTask(OneSixInstance * inst) | |||||||
|  |  | ||||||
| void LibrariesTask::executeTask() | void LibrariesTask::executeTask() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Getting the library files from Mojang...")); | 	setStatus(tr("Getting the library files from Mojang...")); | ||||||
| 	qDebug() << m_inst->name() << ": downloading libraries"; | 	qDebug() << m_inst->name() << ": downloading libraries"; | ||||||
| 	OneSixInstance *inst = (OneSixInstance *)m_inst; | 	OneSixInstance *inst = (OneSixInstance *)m_inst; | ||||||
| 	inst->reloadProfile(); | 	inst->reloadProfile(); | ||||||
|   | |||||||
| @@ -21,34 +21,34 @@ public: | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| public: | public: | ||||||
| 	Task::Status init(QNetworkRequest & request) override | 	JobStatus init(QNetworkRequest & request) override | ||||||
| 	{ | 	{ | ||||||
| 		m_output->clear(); | 		m_output->clear(); | ||||||
| 		if(initAllValidators(request)) | 		if(initAllValidators(request)) | ||||||
| 			return Task::Status::InProgress; | 			return Job_InProgress; | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Task::Status write(QByteArray & data) override | 	JobStatus write(QByteArray & data) override | ||||||
| 	{ | 	{ | ||||||
| 		m_output->append(data); | 		m_output->append(data); | ||||||
| 		if(writeAllValidators(data)) | 		if(writeAllValidators(data)) | ||||||
| 			return Task::Status::InProgress; | 			return Job_InProgress; | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Task::Status abort() override | 	JobStatus abort() override | ||||||
| 	{ | 	{ | ||||||
| 		m_output->clear(); | 		m_output->clear(); | ||||||
| 		failAllValidators(); | 		failAllValidators(); | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Task::Status finalize(QNetworkReply &reply) override | 	JobStatus finalize(QNetworkReply &reply) override | ||||||
| 	{ | 	{ | ||||||
| 		if(finalizeAllValidators(reply)) | 		if(finalizeAllValidators(reply)) | ||||||
| 			return Task::Status::Finished; | 			return Job_Finished; | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	bool hasLocalData() override | 	bool hasLocalData() override | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ namespace Net { | |||||||
|  |  | ||||||
| Download::Download():NetAction() | Download::Download():NetAction() | ||||||
| { | { | ||||||
| 	m_status = Status::NotStarted; | 	m_status = Job_NotStarted; | ||||||
| } | } | ||||||
|  |  | ||||||
| Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options) | Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options) | ||||||
| @@ -40,7 +40,7 @@ Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options | |||||||
| 	auto cachedNode = new MetaCacheSink(entry, md5Node); | 	auto cachedNode = new MetaCacheSink(entry, md5Node); | ||||||
| 	dl->m_sink.reset(cachedNode); | 	dl->m_sink.reset(cachedNode); | ||||||
| 	dl->m_target_path = entry->getFullPath(); | 	dl->m_target_path = entry->getFullPath(); | ||||||
| 	return dl; | 	return std::shared_ptr<Download>(dl); | ||||||
| } | } | ||||||
|  |  | ||||||
| Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options options) | Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options options) | ||||||
| @@ -49,7 +49,7 @@ Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options opti | |||||||
| 	dl->m_url = url; | 	dl->m_url = url; | ||||||
| 	dl->m_options = options; | 	dl->m_options = options; | ||||||
| 	dl->m_sink.reset(new ByteArraySink(output)); | 	dl->m_sink.reset(new ByteArraySink(output)); | ||||||
| 	return dl; | 	return std::shared_ptr<Download>(dl); | ||||||
| } | } | ||||||
|  |  | ||||||
| Download::Ptr Download::makeFile(QUrl url, QString path, Options options) | Download::Ptr Download::makeFile(QUrl url, QString path, Options options) | ||||||
| @@ -58,7 +58,7 @@ Download::Ptr Download::makeFile(QUrl url, QString path, Options options) | |||||||
| 	dl->m_url = url; | 	dl->m_url = url; | ||||||
| 	dl->m_options = options; | 	dl->m_options = options; | ||||||
| 	dl->m_sink.reset(new FileSink(path)); | 	dl->m_sink.reset(new FileSink(path)); | ||||||
| 	return dl; | 	return std::shared_ptr<Download>(dl); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Download::addValidator(Validator * v) | void Download::addValidator(Validator * v) | ||||||
| @@ -66,30 +66,30 @@ void Download::addValidator(Validator * v) | |||||||
| 	m_sink->addValidator(v); | 	m_sink->addValidator(v); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Download::executeTask() | void Download::start() | ||||||
| { | { | ||||||
| 	if(m_status == Status::Aborted) | 	if(m_status == Job_Aborted) | ||||||
| 	{ | 	{ | ||||||
| 		qWarning() << "Attempt to start an aborted Download:" << m_url.toString(); | 		qWarning() << "Attempt to start an aborted Download:" << m_url.toString(); | ||||||
| 		emit aborted(); | 		emit aborted(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	QNetworkRequest request(m_url); | 	QNetworkRequest request(m_url); | ||||||
| 	m_status = m_sink->init(request); | 	m_status = m_sink->init(request); | ||||||
| 	switch(m_status) | 	switch(m_status) | ||||||
| 	{ | 	{ | ||||||
| 		case Status::Finished: | 		case Job_Finished: | ||||||
| 			emit succeeded(); | 			emit succeeded(m_index_within_job); | ||||||
| 			qDebug() << "Download cache hit " << m_url.toString(); | 			qDebug() << "Download cache hit " << m_url.toString(); | ||||||
| 			return; | 			return; | ||||||
| 		case Status::InProgress: | 		case Job_InProgress: | ||||||
| 			qDebug() << "Downloading " << m_url.toString(); | 			qDebug() << "Downloading " << m_url.toString(); | ||||||
| 			break; | 			break; | ||||||
| 		case Status::NotStarted: | 		case Job_NotStarted: | ||||||
| 		case Status::Failed: | 		case Job_Failed: | ||||||
| 			emit failed(); | 			emit failed(m_index_within_job); | ||||||
| 			return; | 			return; | ||||||
| 		case Status::Aborted: | 		case Job_Aborted: | ||||||
| 			return; | 			return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -106,20 +106,9 @@ void Download::executeTask() | |||||||
|  |  | ||||||
| void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | ||||||
| { | { | ||||||
| 	// FIXME: ignore unknown size. for now. | 	m_total_progress = bytesTotal; | ||||||
| 	if(bytesTotal == -1) |  | ||||||
| 	{ |  | ||||||
| 		return; |  | ||||||
| 	} |  | ||||||
| 	// FIXME: ignore redirects... for now. |  | ||||||
| 	auto redirectURL = getRedirect(); |  | ||||||
| 	if(!redirectURL.isEmpty()) |  | ||||||
| 	{ |  | ||||||
| 		return; |  | ||||||
| 	} |  | ||||||
| 	m_progressTotal = bytesTotal; |  | ||||||
| 	m_progress = bytesReceived; | 	m_progress = bytesReceived; | ||||||
| 	emit progress(bytesReceived, bytesTotal); | 	emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Download::downloadError(QNetworkReply::NetworkError error) | void Download::downloadError(QNetworkReply::NetworkError error) | ||||||
| @@ -127,7 +116,7 @@ void Download::downloadError(QNetworkReply::NetworkError error) | |||||||
| 	if(error == QNetworkReply::OperationCanceledError) | 	if(error == QNetworkReply::OperationCanceledError) | ||||||
| 	{ | 	{ | ||||||
| 		qCritical() << "Aborted " << m_url.toString(); | 		qCritical() << "Aborted " << m_url.toString(); | ||||||
| 		m_status = Status::Aborted; | 		m_status = Job_Aborted; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @@ -135,17 +124,17 @@ void Download::downloadError(QNetworkReply::NetworkError error) | |||||||
| 		{ | 		{ | ||||||
| 			if(m_sink->hasLocalData()) | 			if(m_sink->hasLocalData()) | ||||||
| 			{ | 			{ | ||||||
| 				m_status = Status::Failed_Proceed; | 				m_status = Job_Failed_Proceed; | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		// error happened during download. | 		// error happened during download. | ||||||
| 		qCritical() << "Failed " << m_url.toString() << " with reason " << error; | 		qCritical() << "Failed " << m_url.toString() << " with reason " << error; | ||||||
| 		m_status = Status::Failed; | 		m_status = Job_Failed; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| QString Download::getRedirect() | bool Download::handleRedirect() | ||||||
| { | { | ||||||
| 	QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader); | 	QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader); | ||||||
| 	QString redirectURL; | 	QString redirectURL; | ||||||
| @@ -162,15 +151,10 @@ QString Download::getRedirect() | |||||||
| 			redirectURL = m_reply->url().scheme() + ":" + data; | 			redirectURL = m_reply->url().scheme() + ":" + data; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return redirectURL; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool Download::handleRedirect() |  | ||||||
| { |  | ||||||
| 	auto redirectURL = getRedirect(); |  | ||||||
| 	if (!redirectURL.isEmpty()) | 	if (!redirectURL.isEmpty()) | ||||||
| 	{ | 	{ | ||||||
| 		m_url = QUrl(redirectURL); | 		m_url = QUrl(redirect.toString()); | ||||||
|  | 		qDebug() << "Following redirect to " << m_url.toString(); | ||||||
| 		start(); | 		start(); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| @@ -188,28 +172,28 @@ void Download::downloadFinished() | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// if the download failed before this point ... | 	// if the download failed before this point ... | ||||||
| 	if (m_status == Status::Failed_Proceed) | 	if (m_status == Job_Failed_Proceed) | ||||||
| 	{ | 	{ | ||||||
| 		qDebug() << "Download failed but we are allowed to proceed:" << m_url.toString(); | 		qDebug() << "Download failed but we are allowed to proceed:" << m_url.toString(); | ||||||
| 		m_sink->abort(); | 		m_sink->abort(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit succeeded(); | 		emit succeeded(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	else if (m_status == Status::Failed) | 	else if (m_status == Job_Failed) | ||||||
| 	{ | 	{ | ||||||
| 		qDebug() << "Download failed in previous step:" << m_url.toString(); | 		qDebug() << "Download failed in previous step:" << m_url.toString(); | ||||||
| 		m_sink->abort(); | 		m_sink->abort(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	else if(m_status == Status::Aborted) | 	else if(m_status == Job_Aborted) | ||||||
| 	{ | 	{ | ||||||
| 		qDebug() << "Download aborted in previous step:" << m_url.toString(); | 		qDebug() << "Download aborted in previous step:" << m_url.toString(); | ||||||
| 		m_sink->abort(); | 		m_sink->abort(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit aborted(); | 		emit aborted(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -223,26 +207,26 @@ void Download::downloadFinished() | |||||||
|  |  | ||||||
| 	// otherwise, finalize the whole graph | 	// otherwise, finalize the whole graph | ||||||
| 	m_status = m_sink->finalize(*m_reply.get()); | 	m_status = m_sink->finalize(*m_reply.get()); | ||||||
| 	if (m_status != Status::Finished) | 	if (m_status != Job_Finished) | ||||||
| 	{ | 	{ | ||||||
| 		qDebug() << "Download failed to finalize:" << m_url.toString(); | 		qDebug() << "Download failed to finalize:" << m_url.toString(); | ||||||
| 		m_sink->abort(); | 		m_sink->abort(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	m_reply.reset(); | 	m_reply.reset(); | ||||||
| 	qDebug() << "Download succeeded:" << m_url.toString(); | 	qDebug() << "Download succeeded:" << m_url.toString(); | ||||||
| 	emit succeeded(); | 	emit succeeded(m_index_within_job); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Download::downloadReadyRead() | void Download::downloadReadyRead() | ||||||
| { | { | ||||||
| 	if(m_status == Status::InProgress) | 	if(m_status == Job_InProgress) | ||||||
| 	{ | 	{ | ||||||
| 		auto data = m_reply->readAll(); | 		auto data = m_reply->readAll(); | ||||||
| 		m_status = m_sink->write(data); | 		m_status = m_sink->write(data); | ||||||
| 		if(m_status == Status::Failed) | 		if(m_status == Job_Failed) | ||||||
| 		{ | 		{ | ||||||
| 			qCritical() << "Failed to process response chunk for " << m_target_path; | 			qCritical() << "Failed to process response chunk for " << m_target_path; | ||||||
| 		} | 		} | ||||||
| @@ -250,7 +234,7 @@ void Download::downloadReadyRead() | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		qCritical() << "Cannot write to " << m_target_path << ", illegal status" << int(m_status); | 		qCritical() << "Cannot write to " << m_target_path << ", illegal status" << m_status; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -264,12 +248,12 @@ bool Net::Download::abort() | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		m_status = Status::Aborted; | 		m_status = Job_Aborted; | ||||||
| 	} | 	} | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Net::Download::canAbort() const | bool Net::Download::canAbort() | ||||||
| { | { | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ class MULTIMC_LOGIC_EXPORT Download : public NetAction | |||||||
| 	Q_OBJECT | 	Q_OBJECT | ||||||
|  |  | ||||||
| public: /* types */ | public: /* types */ | ||||||
| 	typedef shared_qobject_ptr<class Download> Ptr; | 	typedef std::shared_ptr<class Download> Ptr; | ||||||
| 	enum class Option | 	enum class Option | ||||||
| 	{ | 	{ | ||||||
| 		NoOptions = 0, | 		NoOptions = 0, | ||||||
| @@ -50,10 +50,9 @@ public: /* methods */ | |||||||
| 	} | 	} | ||||||
| 	void addValidator(Validator * v); | 	void addValidator(Validator * v); | ||||||
| 	bool abort() override; | 	bool abort() override; | ||||||
| 	bool canAbort() const override; | 	bool canAbort() override; | ||||||
|  |  | ||||||
| private: /* methods */ | private: /* methods */ | ||||||
| 	QString getRedirect(); |  | ||||||
| 	bool handleRedirect(); | 	bool handleRedirect(); | ||||||
|  |  | ||||||
| protected slots: | protected slots: | ||||||
| @@ -63,7 +62,7 @@ protected slots: | |||||||
| 	void downloadReadyRead() override; | 	void downloadReadyRead() override; | ||||||
|  |  | ||||||
| public slots: | public slots: | ||||||
| 	void executeTask() override; | 	void start() override; | ||||||
|  |  | ||||||
| private: /* data */ | private: /* data */ | ||||||
| 	// FIXME: remove this, it has no business being here. | 	// FIXME: remove this, it has no business being here. | ||||||
|   | |||||||
| @@ -17,10 +17,10 @@ FileSink::~FileSink() | |||||||
| 	// nil | 	// nil | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Task::Status FileSink::init(QNetworkRequest& request) | JobStatus FileSink::init(QNetworkRequest& request) | ||||||
| { | { | ||||||
| 	auto result = initCache(request); | 	auto result = initCache(request); | ||||||
| 	if(result != Task::Status::InProgress) | 	if(result != Job_InProgress) | ||||||
| 	{ | 	{ | ||||||
| 		return result; | 		return result; | ||||||
| 	} | 	} | ||||||
| @@ -28,27 +28,27 @@ Task::Status FileSink::init(QNetworkRequest& request) | |||||||
| 	if (!FS::ensureFilePathExists(m_filename)) | 	if (!FS::ensureFilePathExists(m_filename)) | ||||||
| 	{ | 	{ | ||||||
| 		qCritical() << "Could not create folder for " + m_filename; | 		qCritical() << "Could not create folder for " + m_filename; | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	} | 	} | ||||||
| 	wroteAnyData = false; | 	wroteAnyData = false; | ||||||
| 	m_output_file.reset(new QSaveFile(m_filename)); | 	m_output_file.reset(new QSaveFile(m_filename)); | ||||||
| 	if (!m_output_file->open(QIODevice::WriteOnly)) | 	if (!m_output_file->open(QIODevice::WriteOnly)) | ||||||
| 	{ | 	{ | ||||||
| 		qCritical() << "Could not open " + m_filename + " for writing"; | 		qCritical() << "Could not open " + m_filename + " for writing"; | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if(initAllValidators(request)) | 	if(initAllValidators(request)) | ||||||
| 		return Task::Status::InProgress; | 		return Job_InProgress; | ||||||
| 	return Task::Status::Failed; | 	return Job_Failed; | ||||||
| } | } | ||||||
|  |  | ||||||
| Task::Status FileSink::initCache(QNetworkRequest &) | JobStatus FileSink::initCache(QNetworkRequest &) | ||||||
| { | { | ||||||
| 	return Task::Status::InProgress; | 	return Job_InProgress; | ||||||
| } | } | ||||||
|  |  | ||||||
| Task::Status FileSink::write(QByteArray& data) | JobStatus FileSink::write(QByteArray& data) | ||||||
| { | { | ||||||
| 	if (!writeAllValidators(data) || m_output_file->write(data) != data.size()) | 	if (!writeAllValidators(data) || m_output_file->write(data) != data.size()) | ||||||
| 	{ | 	{ | ||||||
| @@ -56,20 +56,20 @@ Task::Status FileSink::write(QByteArray& data) | |||||||
| 		m_output_file->cancelWriting(); | 		m_output_file->cancelWriting(); | ||||||
| 		m_output_file.reset(); | 		m_output_file.reset(); | ||||||
| 		wroteAnyData = false; | 		wroteAnyData = false; | ||||||
| 		return Task::Status::Failed; | 		return Job_Failed; | ||||||
| 	} | 	} | ||||||
| 	wroteAnyData = true; | 	wroteAnyData = true; | ||||||
| 	return Task::Status::InProgress; | 	return Job_InProgress; | ||||||
| } | } | ||||||
|  |  | ||||||
| Task::Status FileSink::abort() | JobStatus FileSink::abort() | ||||||
| { | { | ||||||
| 	m_output_file->cancelWriting(); | 	m_output_file->cancelWriting(); | ||||||
| 	failAllValidators(); | 	failAllValidators(); | ||||||
| 	return Task::Status::Failed; | 	return Job_Failed; | ||||||
| } | } | ||||||
|  |  | ||||||
| Task::Status FileSink::finalize(QNetworkReply& reply) | JobStatus FileSink::finalize(QNetworkReply& reply) | ||||||
| { | { | ||||||
| 	// if we wrote any data to the save file, we try to commit the data to the real file. | 	// if we wrote any data to the save file, we try to commit the data to the real file. | ||||||
| 	if (wroteAnyData) | 	if (wroteAnyData) | ||||||
| @@ -77,13 +77,13 @@ Task::Status FileSink::finalize(QNetworkReply& reply) | |||||||
| 		// ask validators for data consistency | 		// ask validators for data consistency | ||||||
| 		// we only do this for actual downloads, not 'your data is still the same' cache hits | 		// we only do this for actual downloads, not 'your data is still the same' cache hits | ||||||
| 		if(!finalizeAllValidators(reply)) | 		if(!finalizeAllValidators(reply)) | ||||||
| 			return Task::Status::Failed; | 			return Job_Failed; | ||||||
| 		// nothing went wrong... | 		// nothing went wrong... | ||||||
| 		if (!m_output_file->commit()) | 		if (!m_output_file->commit()) | ||||||
| 		{ | 		{ | ||||||
| 			qCritical() << "Failed to commit changes to " << m_filename; | 			qCritical() << "Failed to commit changes to " << m_filename; | ||||||
| 			m_output_file->cancelWriting(); | 			m_output_file->cancelWriting(); | ||||||
| 			return Task::Status::Failed; | 			return Job_Failed; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	// then get rid of the save file | 	// then get rid of the save file | ||||||
| @@ -92,9 +92,9 @@ Task::Status FileSink::finalize(QNetworkReply& reply) | |||||||
| 	return finalizeCache(reply); | 	return finalizeCache(reply); | ||||||
| } | } | ||||||
|  |  | ||||||
| Task::Status FileSink::finalizeCache(QNetworkReply &) | JobStatus FileSink::finalizeCache(QNetworkReply &) | ||||||
| { | { | ||||||
| 	return Task::Status::Finished; | 	return Job_Finished; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool FileSink::hasLocalData() | bool FileSink::hasLocalData() | ||||||
|   | |||||||
| @@ -10,15 +10,15 @@ public: /* con/des */ | |||||||
| 	virtual ~FileSink(); | 	virtual ~FileSink(); | ||||||
|  |  | ||||||
| public: /* methods */ | public: /* methods */ | ||||||
| 	Task::Status init(QNetworkRequest & request) override; | 	JobStatus init(QNetworkRequest & request) override; | ||||||
| 	Task::Status write(QByteArray & data) override; | 	JobStatus write(QByteArray & data) override; | ||||||
| 	Task::Status abort() override; | 	JobStatus abort() override; | ||||||
| 	Task::Status finalize(QNetworkReply & reply) override; | 	JobStatus finalize(QNetworkReply & reply) override; | ||||||
| 	bool hasLocalData() override; | 	bool hasLocalData() override; | ||||||
|  |  | ||||||
| protected: /* methods */ | protected: /* methods */ | ||||||
| 	virtual Task::Status initCache(QNetworkRequest &); | 	virtual JobStatus initCache(QNetworkRequest &); | ||||||
| 	virtual Task::Status finalizeCache(QNetworkReply &reply); | 	virtual JobStatus finalizeCache(QNetworkReply &reply); | ||||||
|  |  | ||||||
| protected: /* data */ | protected: /* data */ | ||||||
| 	QString m_filename; | 	QString m_filename; | ||||||
|   | |||||||
| @@ -17,11 +17,11 @@ MetaCacheSink::~MetaCacheSink() | |||||||
| 	// nil | 	// nil | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Task::Status MetaCacheSink::initCache(QNetworkRequest& request) | JobStatus MetaCacheSink::initCache(QNetworkRequest& request) | ||||||
| { | { | ||||||
| 	if (!m_entry->isStale()) | 	if (!m_entry->isStale()) | ||||||
| 	{ | 	{ | ||||||
| 		return Task::Status::Finished; | 		return Job_Finished; | ||||||
| 	} | 	} | ||||||
| 	// check if file exists, if it does, use its information for the request | 	// check if file exists, if it does, use its information for the request | ||||||
| 	QFile current(m_filename); | 	QFile current(m_filename); | ||||||
| @@ -36,10 +36,10 @@ Task::Status MetaCacheSink::initCache(QNetworkRequest& request) | |||||||
| 			request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->getETag().toLatin1()); | 			request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->getETag().toLatin1()); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return Task::Status::InProgress; | 	return Job_InProgress; | ||||||
| } | } | ||||||
|  |  | ||||||
| Task::Status MetaCacheSink::finalizeCache(QNetworkReply & reply) | JobStatus MetaCacheSink::finalizeCache(QNetworkReply & reply) | ||||||
| { | { | ||||||
| 	QFileInfo output_file_info(m_filename); | 	QFileInfo output_file_info(m_filename); | ||||||
| 	if(wroteAnyData) | 	if(wroteAnyData) | ||||||
| @@ -54,7 +54,7 @@ Task::Status MetaCacheSink::finalizeCache(QNetworkReply & reply) | |||||||
| 	m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch()); | 	m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch()); | ||||||
| 	m_entry->setStale(false); | 	m_entry->setStale(false); | ||||||
| 	ENV.metacache()->updateEntry(m_entry); | 	ENV.metacache()->updateEntry(m_entry); | ||||||
| 	return Task::Status::Finished; | 	return Job_Finished; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool MetaCacheSink::hasLocalData() | bool MetaCacheSink::hasLocalData() | ||||||
|   | |||||||
| @@ -12,8 +12,8 @@ public: /* con/des */ | |||||||
| 	bool hasLocalData() override; | 	bool hasLocalData() override; | ||||||
|  |  | ||||||
| protected: /* methods */ | protected: /* methods */ | ||||||
| 	Task::Status initCache(QNetworkRequest & request) override; | 	JobStatus initCache(QNetworkRequest & request) override; | ||||||
| 	Task::Status finalizeCache(QNetworkReply & reply) override; | 	JobStatus finalizeCache(QNetworkReply & reply) override; | ||||||
|  |  | ||||||
| private: /* data */ | private: /* data */ | ||||||
| 	MetaEntryPtr m_entry; | 	MetaEntryPtr m_entry; | ||||||
|   | |||||||
| @@ -15,8 +15,6 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include "tasks/Task.h" |  | ||||||
|  |  | ||||||
| #include <QObject> | #include <QObject> | ||||||
| #include <QUrl> | #include <QUrl> | ||||||
| #include <memory> | #include <memory> | ||||||
| @@ -25,29 +23,82 @@ | |||||||
|  |  | ||||||
| #include "multimc_logic_export.h" | #include "multimc_logic_export.h" | ||||||
|  |  | ||||||
| typedef shared_qobject_ptr<class NetAction> NetActionPtr; | enum JobStatus | ||||||
| class MULTIMC_LOGIC_EXPORT NetAction : public Task | { | ||||||
|  | 	Job_NotStarted, | ||||||
|  | 	Job_InProgress, | ||||||
|  | 	Job_Finished, | ||||||
|  | 	Job_Failed, | ||||||
|  | 	Job_Aborted, | ||||||
|  | 	Job_Failed_Proceed | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef std::shared_ptr<class NetAction> NetActionPtr; | ||||||
|  | class MULTIMC_LOGIC_EXPORT NetAction : public QObject | ||||||
| { | { | ||||||
| 	Q_OBJECT | 	Q_OBJECT | ||||||
| protected: | protected: | ||||||
| 	explicit NetAction(QObject *parent = 0) : Task(parent) {}; | 	explicit NetAction() : QObject(0) {}; | ||||||
|  |  | ||||||
| public: | public: | ||||||
| 	virtual ~NetAction() {}; | 	virtual ~NetAction() {}; | ||||||
|  |  | ||||||
| public: | public: | ||||||
|  | 	virtual qint64 totalProgress() const | ||||||
|  | 	{ | ||||||
|  | 		return m_total_progress; | ||||||
|  | 	} | ||||||
|  | 	virtual qint64 currentProgress() const | ||||||
|  | 	{ | ||||||
|  | 		return m_progress; | ||||||
|  | 	} | ||||||
|  | 	virtual qint64 numberOfFailures() const | ||||||
|  | 	{ | ||||||
|  | 		return m_failures; | ||||||
|  | 	} | ||||||
|  | 	virtual bool abort() | ||||||
|  | 	{ | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | 	virtual bool canAbort() | ||||||
|  | 	{ | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | public: | ||||||
|  | 	/// the network reply | ||||||
| 	unique_qobject_ptr<QNetworkReply> m_reply; | 	unique_qobject_ptr<QNetworkReply> m_reply; | ||||||
|  |  | ||||||
|  | 	/// source URL | ||||||
| 	QUrl m_url; | 	QUrl m_url; | ||||||
| 	// FIXME: pull this up into Task |  | ||||||
| 	Status m_status = Status::NotStarted; | 	/// The file's status | ||||||
|  | 	JobStatus m_status = Job_NotStarted; | ||||||
|  |  | ||||||
|  | 	/// index within the parent job | ||||||
|  | 	int m_index_within_job = 0; | ||||||
|  |  | ||||||
|  | 	qint64 m_progress = 0; | ||||||
|  | 	qint64 m_total_progress = 1; | ||||||
|  |  | ||||||
|  | 	/// number of failures up to this point | ||||||
|  | 	int m_failures = 0; | ||||||
|  |  | ||||||
| signals: | signals: | ||||||
| 	void failed(); | 	void started(int index); | ||||||
| 	void aborted(); | 	void netActionProgress(int index, qint64 current, qint64 total); | ||||||
|  | 	void succeeded(int index); | ||||||
|  | 	void failed(int index); | ||||||
|  | 	void aborted(int index); | ||||||
|  |  | ||||||
| protected slots: | protected | ||||||
|  | slots: | ||||||
| 	virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0; | 	virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0; | ||||||
| 	virtual void downloadError(QNetworkReply::NetworkError error) = 0; | 	virtual void downloadError(QNetworkReply::NetworkError error) = 0; | ||||||
| 	virtual void downloadFinished() = 0; | 	virtual void downloadFinished() = 0; | ||||||
| 	virtual void downloadReadyRead() = 0; | 	virtual void downloadReadyRead() = 0; | ||||||
|  |  | ||||||
|  | public | ||||||
|  | slots: | ||||||
|  | 	virtual void start() = 0; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -18,24 +18,22 @@ | |||||||
|  |  | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
|  |  | ||||||
| void NetJob::partSucceeded() | void NetJob::partSucceeded(int index) | ||||||
| { | { | ||||||
| 	auto index = m_partsIndex[(NetAction *)QObject::sender()]; |  | ||||||
| 	// do progress. all slots are 1 in size at least | 	// do progress. all slots are 1 in size at least | ||||||
| 	auto &slot = m_parts[index]; | 	auto &slot = parts_progress[index]; | ||||||
| 	setPartProgress(index, slot.total_progress, slot.total_progress); | 	partProgress(index, slot.total_progress, slot.total_progress); | ||||||
|  |  | ||||||
| 	m_doing.remove(index); | 	m_doing.remove(index); | ||||||
| 	m_done.insert(index); | 	m_done.insert(index); | ||||||
| 	slot.download->disconnect(this); | 	downloads[index].get()->disconnect(this); | ||||||
| 	startMoreParts(); | 	startMoreParts(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void NetJob::partFailed() | void NetJob::partFailed(int index) | ||||||
| { | { | ||||||
| 	auto index = m_partsIndex[(NetAction *)QObject::sender()]; |  | ||||||
| 	m_doing.remove(index); | 	m_doing.remove(index); | ||||||
| 	auto &slot = m_parts[index]; | 	auto &slot = parts_progress[index]; | ||||||
| 	if (slot.failures == 3) | 	if (slot.failures == 3) | ||||||
| 	{ | 	{ | ||||||
| 		m_failed.insert(index); | 		m_failed.insert(index); | ||||||
| @@ -45,47 +43,38 @@ void NetJob::partFailed() | |||||||
| 		slot.failures++; | 		slot.failures++; | ||||||
| 		m_todo.enqueue(index); | 		m_todo.enqueue(index); | ||||||
| 	} | 	} | ||||||
| 	slot.download->disconnect(this); | 	downloads[index].get()->disconnect(this); | ||||||
| 	startMoreParts(); | 	startMoreParts(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void NetJob::partAborted() | void NetJob::partAborted(int index) | ||||||
| { | { | ||||||
| 	auto index = m_partsIndex[(NetAction *)QObject::sender()]; |  | ||||||
| 	m_aborted = true; | 	m_aborted = true; | ||||||
| 	m_doing.remove(index); | 	m_doing.remove(index); | ||||||
| 	auto &slot = m_parts[index]; |  | ||||||
| 	m_failed.insert(index); | 	m_failed.insert(index); | ||||||
| 	slot.download->disconnect(this); | 	downloads[index].get()->disconnect(this); | ||||||
| 	startMoreParts(); | 	startMoreParts(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void NetJob::partProgress(qint64 bytesReceived, qint64 bytesTotal) | void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal) | ||||||
| { | { | ||||||
| 	auto index = m_partsIndex[(NetAction *)QObject::sender()]; | 	auto &slot = parts_progress[index]; | ||||||
| 	setPartProgress(index, bytesReceived, bytesTotal); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void NetJob::setPartProgress(int index, qint64 bytesReceived, qint64 bytesTotal) | 	current_progress -= slot.current_progress; | ||||||
| { |  | ||||||
| 	auto &slot = m_parts[index]; |  | ||||||
| 	slot.current_progress = bytesReceived; | 	slot.current_progress = bytesReceived; | ||||||
|  | 	current_progress += slot.current_progress; | ||||||
|  |  | ||||||
|  | 	total_progress -= slot.total_progress; | ||||||
| 	slot.total_progress = bytesTotal; | 	slot.total_progress = bytesTotal; | ||||||
| 	qint64 current_progress = m_done.count() * 100; | 	total_progress += slot.total_progress; | ||||||
| 	qint64 total_progress = m_parts.count() * 100; |  | ||||||
| 	for(auto iter = m_doing.begin(); iter != m_doing.end(); iter++) |  | ||||||
| 	{ |  | ||||||
| 		auto &part = m_parts[*iter]; |  | ||||||
| 		float percentage = (float(part.current_progress) / float(part.total_progress)) * 100.0f; |  | ||||||
| 		current_progress += (qint64) percentage; |  | ||||||
| 	} |  | ||||||
| 	setProgress(current_progress, total_progress); | 	setProgress(current_progress, total_progress); | ||||||
| } | } | ||||||
|  |  | ||||||
| void NetJob::executeTask() | void NetJob::executeTask() | ||||||
| { | { | ||||||
| 	qDebug() << m_job_name.toLocal8Bit() << " started."; | 	qDebug() << m_job_name.toLocal8Bit() << " started."; | ||||||
| 	for (int i = 0; i < m_parts.size(); i++) | 	m_running = true; | ||||||
|  | 	for (int i = 0; i < downloads.size(); i++) | ||||||
| 	{ | 	{ | ||||||
| 		m_todo.enqueue(i); | 		m_todo.enqueue(i); | ||||||
| 	} | 	} | ||||||
| @@ -125,28 +114,24 @@ void NetJob::startMoreParts() | |||||||
| 			return; | 			return; | ||||||
| 		int doThis = m_todo.dequeue(); | 		int doThis = m_todo.dequeue(); | ||||||
| 		m_doing.insert(doThis); | 		m_doing.insert(doThis); | ||||||
| 		auto part = m_parts[doThis].download; | 		auto part = downloads[doThis]; | ||||||
| 		// connect signals :D | 		// connect signals :D | ||||||
| 		connectAction(part.get()); | 		connect(part.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); | ||||||
|  | 		connect(part.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); | ||||||
|  | 		connect(part.get(), SIGNAL(aborted(int)), SLOT(partAborted(int))); | ||||||
|  | 		connect(part.get(), SIGNAL(netActionProgress(int, qint64, qint64)), | ||||||
|  | 				SLOT(partProgress(int, qint64, qint64))); | ||||||
| 		part->start(); | 		part->start(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| void NetJob::connectAction(NetAction* action) |  | ||||||
| { |  | ||||||
| 	connect(action, &NetAction::succeeded, this, &NetJob::partSucceeded); |  | ||||||
| 	connect(action, &NetAction::failed, this, &NetJob::partFailed); |  | ||||||
| 	connect(action, &NetAction::aborted, this, &NetJob::partAborted); |  | ||||||
| 	connect(action, &NetAction::progress, this, &NetJob::partProgress); |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| QStringList NetJob::getFailedFiles() | QStringList NetJob::getFailedFiles() | ||||||
| { | { | ||||||
| 	QStringList failed; | 	QStringList failed; | ||||||
| 	for (auto index: m_failed) | 	for (auto index: m_failed) | ||||||
| 	{ | 	{ | ||||||
| 		failed.push_back(m_parts[index].download->m_url.toString()); | 		failed.push_back(downloads[index]->m_url.toString()); | ||||||
| 	} | 	} | ||||||
| 	failed.sort(); | 	failed.sort(); | ||||||
| 	return failed; | 	return failed; | ||||||
| @@ -158,13 +143,13 @@ bool NetJob::canAbort() const | |||||||
| 	// can abort the waiting? | 	// can abort the waiting? | ||||||
| 	for(auto index: m_todo) | 	for(auto index: m_todo) | ||||||
| 	{ | 	{ | ||||||
| 		auto part = m_parts[index].download; | 		auto part = downloads[index]; | ||||||
| 		canFullyAbort &= part->canAbort(); | 		canFullyAbort &= part->canAbort(); | ||||||
| 	} | 	} | ||||||
| 	// can abort the active? | 	// can abort the active? | ||||||
| 	for(auto index: m_doing) | 	for(auto index: m_doing) | ||||||
| 	{ | 	{ | ||||||
| 		auto part = m_parts[index].download; | 		auto part = downloads[index]; | ||||||
| 		canFullyAbort &= part->canAbort(); | 		canFullyAbort &= part->canAbort(); | ||||||
| 	} | 	} | ||||||
| 	return canFullyAbort; | 	return canFullyAbort; | ||||||
| @@ -180,26 +165,8 @@ bool NetJob::abort() | |||||||
| 	auto toKill = m_doing.toList(); | 	auto toKill = m_doing.toList(); | ||||||
| 	for(auto index: toKill) | 	for(auto index: toKill) | ||||||
| 	{ | 	{ | ||||||
| 		auto part = m_parts[index].download; | 		auto part = downloads[index]; | ||||||
| 		fullyAborted &= part->abort(); | 		fullyAborted &= part->abort(); | ||||||
| 	} | 	} | ||||||
| 	return fullyAborted; | 	return fullyAborted; | ||||||
| } | } | ||||||
|  |  | ||||||
| void NetJob::addNetAction(NetActionPtr action) |  | ||||||
| { |  | ||||||
| 	m_partsIndex[action.get()] = m_parts.count(); |  | ||||||
| 	part_info pi; |  | ||||||
| 	{ |  | ||||||
| 		pi.current_progress = action->getProgress(); |  | ||||||
| 		pi.total_progress = action->getTotalProgress(); |  | ||||||
| 		pi.failures = 0; |  | ||||||
| 		pi.download = action; |  | ||||||
| 	} |  | ||||||
| 	m_parts.append(pi); |  | ||||||
|  |  | ||||||
| 	if (isRunning()) |  | ||||||
| 	{ |  | ||||||
| 		m_todo.enqueue(m_parts.size() - 1); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -32,12 +32,52 @@ class MULTIMC_LOGIC_EXPORT NetJob : public Task | |||||||
| public: | public: | ||||||
| 	explicit NetJob(QString job_name) : Task(), m_job_name(job_name) {} | 	explicit NetJob(QString job_name) : Task(), m_job_name(job_name) {} | ||||||
| 	virtual ~NetJob() {} | 	virtual ~NetJob() {} | ||||||
|  | 	bool addNetAction(NetActionPtr action) | ||||||
|  | 	{ | ||||||
|  | 		action->m_index_within_job = downloads.size(); | ||||||
|  | 		downloads.append(action); | ||||||
|  | 		part_info pi; | ||||||
|  | 		{ | ||||||
|  | 			pi.current_progress = action->currentProgress(); | ||||||
|  | 			pi.total_progress = action->totalProgress(); | ||||||
|  | 			pi.failures = action->numberOfFailures(); | ||||||
|  | 		} | ||||||
|  | 		parts_progress.append(pi); | ||||||
|  | 		total_progress += pi.total_progress; | ||||||
|  | 		// if this is already running, the action needs to be started right away! | ||||||
|  | 		if (isRunning()) | ||||||
|  | 		{ | ||||||
|  | 			setProgress(current_progress, total_progress); | ||||||
|  | 			connect(action.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); | ||||||
|  | 			connect(action.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); | ||||||
|  | 			connect(action.get(), SIGNAL(netActionProgress(int, qint64, qint64)), | ||||||
|  | 					SLOT(partProgress(int, qint64, qint64))); | ||||||
|  | 			action->start(); | ||||||
|  | 		} | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	void addNetAction(NetActionPtr action); | 	NetActionPtr operator[](int index) | ||||||
|  | 	{ | ||||||
|  | 		return downloads[index]; | ||||||
|  | 	} | ||||||
|  | 	const NetActionPtr at(const int index) | ||||||
|  | 	{ | ||||||
|  | 		return downloads.at(index); | ||||||
|  | 	} | ||||||
|  | 	NetActionPtr first() | ||||||
|  | 	{ | ||||||
|  | 		if (downloads.size()) | ||||||
|  | 			return downloads[0]; | ||||||
|  | 		return NetActionPtr(); | ||||||
|  | 	} | ||||||
| 	int size() const | 	int size() const | ||||||
| 	{ | 	{ | ||||||
| 		return m_parts.size(); | 		return downloads.size(); | ||||||
|  | 	} | ||||||
|  | 	virtual bool isRunning() const override | ||||||
|  | 	{ | ||||||
|  | 		return m_running; | ||||||
| 	} | 	} | ||||||
| 	QStringList getFailedFiles(); | 	QStringList getFailedFiles(); | ||||||
|  |  | ||||||
| @@ -51,32 +91,28 @@ public slots: | |||||||
| 	virtual bool abort() override; | 	virtual bool abort() override; | ||||||
|  |  | ||||||
| private slots: | private slots: | ||||||
| 	void partProgress(qint64 bytesReceived, qint64 bytesTotal); | 	void partProgress(int index, qint64 bytesReceived, qint64 bytesTotal); | ||||||
| 	void partSucceeded(); | 	void partSucceeded(int index); | ||||||
| 	void partFailed(); | 	void partFailed(int index); | ||||||
| 	void partAborted(); | 	void partAborted(int index); | ||||||
|  |  | ||||||
| private: |  | ||||||
| 	void setPartProgress(int index, qint64 bytesReceived, qint64 bytesTotal); |  | ||||||
| 	void connectAction(NetAction * action); |  | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	struct part_info | 	struct part_info | ||||||
| 	{ | 	{ | ||||||
| 		NetActionPtr download; |  | ||||||
| 		qint64 current_progress = 0; | 		qint64 current_progress = 0; | ||||||
| 		qint64 total_progress = 1; | 		qint64 total_progress = 1; | ||||||
| 		int failures = 0; | 		int failures = 0; | ||||||
| 		bool connected = false; | 		bool connected = false; | ||||||
| 	}; | 	}; | ||||||
| 	QString m_job_name; | 	QString m_job_name; | ||||||
| 	QVector<part_info> m_parts; | 	QList<NetActionPtr> downloads; | ||||||
| 	QMap<NetAction *, int> m_partsIndex; | 	QList<part_info> parts_progress; | ||||||
| 	QQueue<int> m_todo; | 	QQueue<int> m_todo; | ||||||
| 	QSet<int> m_doing; | 	QSet<int> m_doing; | ||||||
| 	QSet<int> m_done; | 	QSet<int> m_done; | ||||||
| 	QSet<int> m_failed; | 	QSet<int> m_failed; | ||||||
| 	//qint64 current_progress = 0; | 	qint64 current_progress = 0; | ||||||
| 	//qint64 total_progress = 0; | 	qint64 total_progress = 0; | ||||||
|  | 	bool m_running = false; | ||||||
| 	bool m_aborted = false; | 	bool m_aborted = false; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ void PasteUpload::executeTask() | |||||||
| 	QNetworkReply *rep = ENV.qnam().post(request, buf); | 	QNetworkReply *rep = ENV.qnam().post(request, buf); | ||||||
|  |  | ||||||
| 	m_reply = std::shared_ptr<QNetworkReply>(rep); | 	m_reply = std::shared_ptr<QNetworkReply>(rep); | ||||||
| 	setStatusText(tr("Uploading to paste.ee")); | 	setStatus(tr("Uploading to paste.ee")); | ||||||
| 	connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress); | 	connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress); | ||||||
| 	connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); | 	connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); | ||||||
| 	connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); | 	connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); | ||||||
|   | |||||||
| @@ -13,10 +13,10 @@ public: /* con/des */ | |||||||
| 	virtual ~Sink() {}; | 	virtual ~Sink() {}; | ||||||
|  |  | ||||||
| public: /* methods */ | public: /* methods */ | ||||||
| 	virtual Task::Status init(QNetworkRequest & request) = 0; | 	virtual JobStatus init(QNetworkRequest & request) = 0; | ||||||
| 	virtual Task::Status write(QByteArray & data) = 0; | 	virtual JobStatus write(QByteArray & data) = 0; | ||||||
| 	virtual Task::Status abort() = 0; | 	virtual JobStatus abort() = 0; | ||||||
| 	virtual Task::Status finalize(QNetworkReply & reply) = 0; | 	virtual JobStatus finalize(QNetworkReply & reply) = 0; | ||||||
| 	virtual bool hasLocalData() = 0; | 	virtual bool hasLocalData() = 0; | ||||||
|  |  | ||||||
| 	void addValidator(Validator * validator) | 	void addValidator(Validator * validator) | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ void NotificationChecker::checkForNotifications() | |||||||
| 	m_checkJob->start(); | 	m_checkJob->start(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void NotificationChecker::downloadSucceeded() | void NotificationChecker::downloadSucceeded(int) | ||||||
| { | { | ||||||
| 	m_entries.clear(); | 	m_entries.clear(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -43,7 +43,7 @@ slots: | |||||||
|  |  | ||||||
| private | private | ||||||
| slots: | slots: | ||||||
| 	void downloadSucceeded(); | 	void downloadSucceeded(int); | ||||||
|  |  | ||||||
| signals: | signals: | ||||||
| 	void notificationCheckFinished(); | 	void notificationCheckFinished(); | ||||||
|   | |||||||
| @@ -13,12 +13,12 @@ | |||||||
| ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots) | ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots) | ||||||
| { | { | ||||||
| 	m_url = URLConstants::IMGUR_BASE_URL + "album.json"; | 	m_url = URLConstants::IMGUR_BASE_URL + "album.json"; | ||||||
| 	m_status = Status::NotStarted; | 	m_status = Job_NotStarted; | ||||||
| } | } | ||||||
|  |  | ||||||
| void ImgurAlbumCreation::executeTask() | void ImgurAlbumCreation::start() | ||||||
| { | { | ||||||
| 	m_status = Status::InProgress; | 	m_status = Job_InProgress; | ||||||
| 	QNetworkRequest request(m_url); | 	QNetworkRequest request(m_url); | ||||||
| 	request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); | 	request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); | ||||||
| 	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | 	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | ||||||
| @@ -43,11 +43,11 @@ void ImgurAlbumCreation::executeTask() | |||||||
| void ImgurAlbumCreation::downloadError(QNetworkReply::NetworkError error) | void ImgurAlbumCreation::downloadError(QNetworkReply::NetworkError error) | ||||||
| { | { | ||||||
| 	qDebug() << m_reply->errorString(); | 	qDebug() << m_reply->errorString(); | ||||||
| 	m_status = Status::Failed; | 	m_status = Job_Failed; | ||||||
| } | } | ||||||
| void ImgurAlbumCreation::downloadFinished() | void ImgurAlbumCreation::downloadFinished() | ||||||
| { | { | ||||||
| 	if (m_status != Status::Failed) | 	if (m_status != Job_Failed) | ||||||
| 	{ | 	{ | ||||||
| 		QByteArray data = m_reply->readAll(); | 		QByteArray data = m_reply->readAll(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| @@ -56,33 +56,33 @@ void ImgurAlbumCreation::downloadFinished() | |||||||
| 		if (jsonError.error != QJsonParseError::NoError) | 		if (jsonError.error != QJsonParseError::NoError) | ||||||
| 		{ | 		{ | ||||||
| 			qDebug() << jsonError.errorString(); | 			qDebug() << jsonError.errorString(); | ||||||
| 			emit failed(); | 			emit failed(m_index_within_job); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		auto object = doc.object(); | 		auto object = doc.object(); | ||||||
| 		if (!object.value("success").toBool()) | 		if (!object.value("success").toBool()) | ||||||
| 		{ | 		{ | ||||||
| 			qDebug() << doc.toJson(); | 			qDebug() << doc.toJson(); | ||||||
| 			emit failed(); | 			emit failed(m_index_within_job); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		m_deleteHash = object.value("data").toObject().value("deletehash").toString(); | 		m_deleteHash = object.value("data").toObject().value("deletehash").toString(); | ||||||
| 		m_id = object.value("data").toObject().value("id").toString(); | 		m_id = object.value("data").toObject().value("id").toString(); | ||||||
| 		m_status = Status::Finished; | 		m_status = Job_Finished; | ||||||
| 		emit succeeded(); | 		emit succeeded(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		qDebug() << m_reply->readAll(); | 		qDebug() << m_reply->readAll(); | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | ||||||
| { | { | ||||||
| 	m_progressTotal = bytesTotal; | 	m_total_progress = bytesTotal; | ||||||
| 	m_progress = bytesReceived; | 	m_progress = bytesReceived; | ||||||
| 	emit progress(bytesReceived, bytesTotal); | 	emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|  |  | ||||||
| #include "multimc_logic_export.h" | #include "multimc_logic_export.h" | ||||||
|  |  | ||||||
| typedef shared_qobject_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr; | typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr; | ||||||
| class MULTIMC_LOGIC_EXPORT ImgurAlbumCreation : public NetAction | class MULTIMC_LOGIC_EXPORT ImgurAlbumCreation : public NetAction | ||||||
| { | { | ||||||
| public: | public: | ||||||
| @@ -34,7 +34,7 @@ slots: | |||||||
|  |  | ||||||
| public | public | ||||||
| slots: | slots: | ||||||
| 	virtual void executeTask(); | 	virtual void start(); | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	QList<ScreenshotPtr> m_screenshots; | 	QList<ScreenshotPtr> m_screenshots; | ||||||
|   | |||||||
| @@ -15,13 +15,13 @@ | |||||||
| ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot) | ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot) | ||||||
| { | { | ||||||
| 	m_url = URLConstants::IMGUR_BASE_URL + "upload.json"; | 	m_url = URLConstants::IMGUR_BASE_URL + "upload.json"; | ||||||
| 	m_status = Status::NotStarted; | 	m_status = Job_NotStarted; | ||||||
| } | } | ||||||
|  |  | ||||||
| void ImgurUpload::executeTask() | void ImgurUpload::start() | ||||||
| { | { | ||||||
| 	finished = false; | 	finished = false; | ||||||
| 	m_status = Status::InProgress; | 	m_status = Job_InProgress; | ||||||
| 	QNetworkRequest request(m_url); | 	QNetworkRequest request(m_url); | ||||||
| 	request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); | 	request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); | ||||||
| 	request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); | 	request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); | ||||||
| @@ -30,7 +30,7 @@ void ImgurUpload::executeTask() | |||||||
| 	QFile f(m_shot->m_file.absoluteFilePath()); | 	QFile f(m_shot->m_file.absoluteFilePath()); | ||||||
| 	if (!f.open(QFile::ReadOnly)) | 	if (!f.open(QFile::ReadOnly)) | ||||||
| 	{ | 	{ | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -65,10 +65,10 @@ void ImgurUpload::downloadError(QNetworkReply::NetworkError error) | |||||||
| 		qCritical() << "Double finished ImgurUpload!"; | 		qCritical() << "Double finished ImgurUpload!"; | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	m_status = Status::Failed; | 	m_status = Job_Failed; | ||||||
| 	finished = true; | 	finished = true; | ||||||
| 	m_reply.reset(); | 	m_reply.reset(); | ||||||
| 	emit failed(); | 	emit failed(m_index_within_job); | ||||||
| } | } | ||||||
| void ImgurUpload::downloadFinished() | void ImgurUpload::downloadFinished() | ||||||
| { | { | ||||||
| @@ -86,7 +86,7 @@ void ImgurUpload::downloadFinished() | |||||||
| 		qDebug() << "imgur server did not reply with JSON" << jsonError.errorString(); | 		qDebug() << "imgur server did not reply with JSON" << jsonError.errorString(); | ||||||
| 		finished = true; | 		finished = true; | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	auto object = doc.object(); | 	auto object = doc.object(); | ||||||
| @@ -95,19 +95,19 @@ void ImgurUpload::downloadFinished() | |||||||
| 		qDebug() << "Screenshot upload not successful:" << doc.toJson(); | 		qDebug() << "Screenshot upload not successful:" << doc.toJson(); | ||||||
| 		finished = true; | 		finished = true; | ||||||
| 		m_reply.reset(); | 		m_reply.reset(); | ||||||
| 		emit failed(); | 		emit failed(m_index_within_job); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	m_shot->m_imgurId = object.value("data").toObject().value("id").toString(); | 	m_shot->m_imgurId = object.value("data").toObject().value("id").toString(); | ||||||
| 	m_shot->m_url = object.value("data").toObject().value("link").toString(); | 	m_shot->m_url = object.value("data").toObject().value("link").toString(); | ||||||
| 	m_status = Status::Finished; | 	m_status = Job_Finished; | ||||||
| 	finished = true; | 	finished = true; | ||||||
| 	emit succeeded(); | 	emit succeeded(m_index_within_job); | ||||||
| 	return; | 	return; | ||||||
| } | } | ||||||
| void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) | ||||||
| { | { | ||||||
| 	m_progressTotal = bytesTotal; | 	m_total_progress = bytesTotal; | ||||||
| 	m_progress = bytesReceived; | 	m_progress = bytesReceived; | ||||||
| 	emit progress(bytesReceived, bytesTotal); | 	emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,11 +1,10 @@ | |||||||
| #pragma once | #pragma once | ||||||
| #include "net/NetAction.h" | #include "net/NetAction.h" | ||||||
| #include "Screenshot.h" | #include "Screenshot.h" | ||||||
| #include "QObjectPtr.h" |  | ||||||
|  |  | ||||||
| #include "multimc_logic_export.h" | #include "multimc_logic_export.h" | ||||||
|  |  | ||||||
| typedef shared_qobject_ptr<class ImgurUpload> ImgurUploadPtr; | typedef std::shared_ptr<class ImgurUpload> ImgurUploadPtr; | ||||||
| class MULTIMC_LOGIC_EXPORT ImgurUpload : public NetAction | class MULTIMC_LOGIC_EXPORT ImgurUpload : public NetAction | ||||||
| { | { | ||||||
| public: | public: | ||||||
| @@ -26,7 +25,7 @@ slots: | |||||||
|  |  | ||||||
| public | public | ||||||
| slots: | slots: | ||||||
| 	virtual void executeTask(); | 	virtual void start(); | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	ScreenshotPtr m_shot; | 	ScreenshotPtr m_shot; | ||||||
|   | |||||||
| @@ -42,7 +42,7 @@ void SequentialTask::subTaskFailed(const QString &msg) | |||||||
| } | } | ||||||
| void SequentialTask::subTaskStatus(const QString &msg) | void SequentialTask::subTaskStatus(const QString &msg) | ||||||
| { | { | ||||||
| 	setStatusText(msg); | 	setStatus(msg); | ||||||
| } | } | ||||||
| void SequentialTask::subTaskProgress(qint64 current, qint64 total) | void SequentialTask::subTaskProgress(qint64 current, qint64 total) | ||||||
| { | { | ||||||
|   | |||||||
| @@ -21,12 +21,12 @@ Task::Task(QObject *parent) : QObject(parent) | |||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
| void Task::setStatusText(const QString &new_status) | void Task::setStatus(const QString &new_status) | ||||||
| { | { | ||||||
| 	if(m_statusText != new_status) | 	if(m_status != new_status) | ||||||
| 	{ | 	{ | ||||||
| 		m_statusText = new_status; | 		m_status = new_status; | ||||||
| 		emit status(m_statusText); | 		emit status(m_status); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,16 +23,6 @@ | |||||||
| class MULTIMC_LOGIC_EXPORT Task : public QObject | class MULTIMC_LOGIC_EXPORT Task : public QObject | ||||||
| { | { | ||||||
| 	Q_OBJECT | 	Q_OBJECT | ||||||
| public: |  | ||||||
| 	enum class Status |  | ||||||
| 	{ |  | ||||||
| 		NotStarted, |  | ||||||
| 		InProgress, |  | ||||||
| 		Finished, |  | ||||||
| 		Failed, |  | ||||||
| 		Aborted, |  | ||||||
| 		Failed_Proceed |  | ||||||
| 	}; |  | ||||||
| public: | public: | ||||||
| 	explicit Task(QObject *parent = 0); | 	explicit Task(QObject *parent = 0); | ||||||
| 	virtual ~Task() {}; | 	virtual ~Task() {}; | ||||||
| @@ -53,22 +43,19 @@ public: | |||||||
| 	 */ | 	 */ | ||||||
| 	virtual QString failReason() const; | 	virtual QString failReason() const; | ||||||
|  |  | ||||||
| 	virtual bool canAbort() const | 	virtual bool canAbort() const { return false; } | ||||||
|  |  | ||||||
|  | 	QString getStatus() | ||||||
| 	{ | 	{ | ||||||
| 		return false; | 		return m_status; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	QString getStatusText() | 	qint64 getProgress() | ||||||
| 	{ |  | ||||||
| 		return m_statusText; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	virtual qint64 getProgress() |  | ||||||
| 	{ | 	{ | ||||||
| 		return m_progress; | 		return m_progress; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	virtual qint64 getTotalProgress() | 	qint64 getTotalProgress() | ||||||
| 	{ | 	{ | ||||||
| 		return m_progressTotal; | 		return m_progressTotal; | ||||||
| 	} | 	} | ||||||
| @@ -81,12 +68,10 @@ signals: | |||||||
| 	void failed(QString reason); | 	void failed(QString reason); | ||||||
| 	void status(QString status); | 	void status(QString status); | ||||||
|  |  | ||||||
| public slots: | public | ||||||
|  | slots: | ||||||
| 	virtual void start(); | 	virtual void start(); | ||||||
| 	virtual bool abort() | 	virtual bool abort() { return false; }; | ||||||
| 	{ |  | ||||||
| 		return false; |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	virtual void executeTask() = 0; | 	virtual void executeTask() = 0; | ||||||
| @@ -96,18 +81,16 @@ protected slots: | |||||||
| 	virtual void emitFailed(QString reason); | 	virtual void emitFailed(QString reason); | ||||||
|  |  | ||||||
| public slots: | public slots: | ||||||
| 	void setStatusText(const QString &status); | 	void setStatus(const QString &status); | ||||||
| 	void setProgress(qint64 current, qint64 total); | 	void setProgress(qint64 current, qint64 total); | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	// FIXME: replace these with the m_status from NetAction |  | ||||||
| 	bool m_running = false; | 	bool m_running = false; | ||||||
| 	bool m_finished = false; | 	bool m_finished = false; | ||||||
| 	bool m_succeeded = false; | 	bool m_succeeded = false; | ||||||
| 	QString m_failReason = ""; | 	QString m_failReason = ""; | ||||||
| 	QString m_statusText; | 	QString m_status; | ||||||
|  | 	int m_progress = 0; | ||||||
| 	qint64 m_progress = 0; | 	int m_progressTotal = 100; | ||||||
| 	qint64 m_progressTotal = 1; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ void ThreadTask::iternal_started() | |||||||
|  |  | ||||||
| void ThreadTask::iternal_status(QString status) | void ThreadTask::iternal_status(QString status) | ||||||
| { | { | ||||||
| 	setStatusText(status); | 	setStatus(status); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ThreadTask::iternal_succeeded() | void ThreadTask::iternal_succeeded() | ||||||
|   | |||||||
| @@ -30,7 +30,7 @@ struct TranslationsModel::Private | |||||||
| 	std::unique_ptr<QTranslator> m_qt_translator; | 	std::unique_ptr<QTranslator> m_qt_translator; | ||||||
| 	std::unique_ptr<QTranslator> m_app_translator; | 	std::unique_ptr<QTranslator> m_app_translator; | ||||||
|  |  | ||||||
| 	Net::Download::Ptr m_index_task; | 	std::shared_ptr<Net::Download> m_index_task; | ||||||
| 	QString m_downloadingTranslation; | 	QString m_downloadingTranslation; | ||||||
| 	NetJobPtr m_dl_job; | 	NetJobPtr m_dl_job; | ||||||
| 	NetJobPtr m_index_job; | 	NetJobPtr m_index_job; | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ | |||||||
| namespace GoUpdate | namespace GoUpdate | ||||||
| { | { | ||||||
|  |  | ||||||
| DownloadTask::DownloadTask(GoUpdate::Status status, QString target, QObject *parent) | DownloadTask::DownloadTask(Status status, QString target, QObject *parent) | ||||||
| 	: Task(parent), m_updateFilesDir(target) | 	: Task(parent), m_updateFilesDir(target) | ||||||
| { | { | ||||||
| 	m_status = status; | 	m_status = status; | ||||||
| @@ -41,7 +41,7 @@ void DownloadTask::executeTask() | |||||||
|  |  | ||||||
| void DownloadTask::loadVersionInfo() | void DownloadTask::loadVersionInfo() | ||||||
| { | { | ||||||
| 	setStatusText(tr("Loading version information...")); | 	setStatus(tr("Loading version information...")); | ||||||
|  |  | ||||||
| 	NetJob *netJob = new NetJob("Version Info"); | 	NetJob *netJob = new NetJob("Version Info"); | ||||||
|  |  | ||||||
| @@ -70,7 +70,7 @@ void DownloadTask::vinfoDownloadFailed() | |||||||
| { | { | ||||||
| 	// Something failed. We really need the second download (current version info), so parse | 	// Something failed. We really need the second download (current version info), so parse | ||||||
| 	// downloads anyways as long as the first one succeeded. | 	// downloads anyways as long as the first one succeeded. | ||||||
| 	if (m_newVersionFileListDownload->m_status != Status::Failed) | 	if (m_newVersionFileListDownload->m_status != Job_Failed) | ||||||
| 	{ | 	{ | ||||||
| 		processDownloadedVersionInfo(); | 		processDownloadedVersionInfo(); | ||||||
| 		return; | 		return; | ||||||
| @@ -86,7 +86,7 @@ void DownloadTask::processDownloadedVersionInfo() | |||||||
| 	VersionFileList m_currentVersionFileList; | 	VersionFileList m_currentVersionFileList; | ||||||
| 	VersionFileList m_newVersionFileList; | 	VersionFileList m_newVersionFileList; | ||||||
|  |  | ||||||
| 	setStatusText(tr("Reading file list for new version...")); | 	setStatus(tr("Reading file list for new version...")); | ||||||
| 	qDebug() << "Reading file list for new version..."; | 	qDebug() << "Reading file list for new version..."; | ||||||
| 	QString error; | 	QString error; | ||||||
| 	if (!parseVersionInfo(newVersionFileListData, m_newVersionFileList, error)) | 	if (!parseVersionInfo(newVersionFileListData, m_newVersionFileList, error)) | ||||||
| @@ -97,9 +97,9 @@ void DownloadTask::processDownloadedVersionInfo() | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// if we have the current version info, use it. | 	// if we have the current version info, use it. | ||||||
| 	if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->m_status != Status::Failed) | 	if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->m_status != Job_Failed) | ||||||
| 	{ | 	{ | ||||||
| 		setStatusText(tr("Reading file list for current version...")); | 		setStatus(tr("Reading file list for current version...")); | ||||||
| 		qDebug() << "Reading file list for current version..."; | 		qDebug() << "Reading file list for current version..."; | ||||||
| 		// if this fails, it's not a complete loss. | 		// if this fails, it's not a complete loss. | ||||||
| 		QString error; | 		QString error; | ||||||
| @@ -114,7 +114,7 @@ void DownloadTask::processDownloadedVersionInfo() | |||||||
| 	m_newVersionFileListDownload.reset(); | 	m_newVersionFileListDownload.reset(); | ||||||
| 	m_vinfoNetJob.reset(); | 	m_vinfoNetJob.reset(); | ||||||
|  |  | ||||||
| 	setStatusText(tr("Processing file lists - figuring out how to install the update...")); | 	setStatus(tr("Processing file lists - figuring out how to install the update...")); | ||||||
|  |  | ||||||
| 	// make a new netjob for the actual update files | 	// make a new netjob for the actual update files | ||||||
| 	NetJobPtr netJob (new NetJob("Update Files")); | 	NetJobPtr netJob (new NetJob("Update Files")); | ||||||
| @@ -131,7 +131,7 @@ void DownloadTask::processDownloadedVersionInfo() | |||||||
| 	QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged); | 	QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged); | ||||||
| 	QObject::connect(netJob.get(), &NetJob::failed, this, &DownloadTask::fileDownloadFailed); | 	QObject::connect(netJob.get(), &NetJob::failed, this, &DownloadTask::fileDownloadFailed); | ||||||
|  |  | ||||||
| 	setStatusText(tr("Downloading %1 update files.").arg(QString::number(netJob->size()))); | 	setStatus(tr("Downloading %1 update files.").arg(QString::number(netJob->size()))); | ||||||
| 	qDebug() << "Begin downloading update files to" << m_updateFilesDir.path(); | 	qDebug() << "Begin downloading update files to" << m_updateFilesDir.path(); | ||||||
| 	m_filesNetJob = netJob; | 	m_filesNetJob = netJob; | ||||||
| 	m_filesNetJob->start(); | 	m_filesNetJob->start(); | ||||||
|   | |||||||
| @@ -37,7 +37,7 @@ public: | |||||||
| 	 * | 	 * | ||||||
| 	 * target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness | 	 * target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness | ||||||
| 	 */ | 	 */ | ||||||
| 	explicit DownloadTask(GoUpdate::Status status, QString target, QObject* parent = 0); | 	explicit DownloadTask(Status status, QString target, QObject* parent = 0); | ||||||
|  |  | ||||||
| 	/// Get the directory that will contain the update files. | 	/// Get the directory that will contain the update files. | ||||||
| 	QString updateFilesDir(); | 	QString updateFilesDir(); | ||||||
| @@ -71,7 +71,7 @@ protected: | |||||||
|  |  | ||||||
| 	NetJobPtr m_filesNetJob; | 	NetJobPtr m_filesNetJob; | ||||||
|  |  | ||||||
| 	GoUpdate::Status m_status; | 	Status m_status; | ||||||
|  |  | ||||||
| 	OperationList m_operations; | 	OperationList m_operations; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -87,7 +87,7 @@ int ProgressDialog::execWithTask(Task *task) | |||||||
| 	if(task->isRunning()) | 	if(task->isRunning()) | ||||||
| 	{ | 	{ | ||||||
| 		changeProgress(task->getProgress(), task->getTotalProgress()); | 		changeProgress(task->getProgress(), task->getTotalProgress()); | ||||||
| 		changeStatus(task->getStatusText()); | 		changeStatus(task->getStatus()); | ||||||
| 		return QDialog::exec(); | 		return QDialog::exec(); | ||||||
| 	} | 	} | ||||||
| 	else if(handleImmediateResult(result)) | 	else if(handleImmediateResult(result)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Petr Mrázek
					Petr Mrázek