NOISSUE Revert all recent changes to NetAction and NetJob

This commit is contained in:
Petr Mrázek
2017-05-03 23:11:52 +02:00
parent 0efa714ba5
commit e76e6329cd
45 changed files with 356 additions and 338 deletions

View File

@ -199,7 +199,7 @@ NetActionPtr AssetObject::getDownloadAction()
auto rawHash = QByteArray::fromHex(hash.toLatin1());
objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
}
objectDL->setProgress(0, size);
objectDL->m_total_progress = size;
return objectDL;
}
return nullptr;

View File

@ -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
{
QList<NetActionPtr> out;

View File

@ -43,7 +43,7 @@ void SkinUpload::executeTask()
QNetworkReply *rep = ENV.qnam().put(request, multiPart);
m_reply = std::shared_ptr<QNetworkReply>(rep);
setStatusText(tr("Uploading skin"));
setStatus(tr("Uploading skin"));
connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress);
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));

View File

@ -237,7 +237,7 @@ QString YggdrasilTask::getStateMessage() const
void YggdrasilTask::changeState(YggdrasilTask::State newState, QString reason)
{
m_state = newState;
setStatusText(getStateMessage());
setStatus(getStateMessage());
if (newState == STATE_SUCCEEDED)
{
emitSucceeded();

View File

@ -10,7 +10,7 @@ Flame::FileResolvingTask::FileResolvingTask(Flame::Manifest& toProcess)
void Flame::FileResolvingTask::executeTask()
{
setStatusText(tr("Resolving mod IDs..."));
setStatus(tr("Resolving mod IDs..."));
setProgress(0, m_toProcess.files.size());
m_dljob.reset(new NetJob("Mod id resolver"));
results.resize(m_toProcess.files.size());

View File

@ -28,31 +28,31 @@ ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : Ne
m_entry = entry;
m_target_path = entry->getFullPath();
m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX");
m_status = Status::NotStarted;
m_status = Job_NotStarted;
m_url_path = relative_path;
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();
emit aborted();
emit aborted(m_index_within_job);
return;
}
m_status = Status::InProgress;
m_status = Job_InProgress;
if (!m_entry->isStale())
{
m_status = Status::Finished;
emit succeeded();
m_status = Job_Finished;
emit succeeded(m_index_within_job);
return;
}
// can we actually create the real, final file?
if (!FS::ensureFilePathExists(m_target_path))
{
m_status = Status::Failed;
emit failed();
m_status = Job_Failed;
emit failed(m_index_within_job);
return;
}
@ -72,9 +72,9 @@ void ForgeXzDownload::executeTask()
void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_progressTotal = bytesTotal;
m_total_progress = bytesTotal;
m_progress = bytesReceived;
emit progress(bytesReceived, bytesTotal);
emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}
void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)
@ -82,29 +82,29 @@ void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)
if(error == QNetworkReply::OperationCanceledError)
{
qCritical() << "Aborted " << m_url.toString();
m_status = Status::Aborted;
m_status = Job_Aborted;
}
else
{
// error happened during download.
qCritical() << "Failed " << m_url.toString() << " with reason " << error;
m_status = Status::Failed;
m_status = Job_Failed;
}
}
void ForgeXzDownload::failAndTryNextMirror()
{
m_status = Status::Failed;
emit failed();
m_status = Job_Failed;
emit failed(m_index_within_job);
}
void ForgeXzDownload::downloadFinished()
{
// 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...
m_status = Status::Finished;
m_status = Job_Finished;
if (m_pack200_xz_file.isOpen())
{
// we actually downloaded something! process and isntall it
@ -114,25 +114,25 @@ void ForgeXzDownload::downloadFinished()
else
{
// something bad happened -- on the local machine!
m_status = Status::Failed;
m_status = Job_Failed;
m_pack200_xz_file.remove();
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
}
else if(m_status == Status::Aborted)
else if(m_status == Job_Aborted)
{
m_pack200_xz_file.remove();
m_reply.reset();
emit failed();
emit aborted();
emit failed(m_index_within_job);
emit aborted(m_index_within_job);
return;
}
// else the download failed
else
{
m_status = Status::Failed;
m_status = Job_Failed;
m_pack200_xz_file.close();
m_pack200_xz_file.remove();
m_reply.reset();
@ -152,7 +152,7 @@ void ForgeXzDownload::downloadReadyRead()
* Can't open the file... the job failed
*/
m_reply->abort();
emit failed();
emit failed(m_index_within_job);
return;
}
}
@ -345,7 +345,7 @@ void ForgeXzDownload::decompressAndInstall()
}
catch (std::runtime_error &err)
{
m_status = Status::Failed;
m_status = Job_Failed;
qCritical() << "Error unpacking " << pack200_file.fileName() << " : " << err.what();
QFile f(m_target_path);
if (f.exists())
@ -374,18 +374,18 @@ void ForgeXzDownload::decompressAndInstall()
ENV.metacache()->updateEntry(m_entry);
m_reply.reset();
emit succeeded();
emit succeeded(m_index_within_job);
}
bool ForgeXzDownload::abort()
{
if(m_reply)
m_reply->abort();
m_status = Status::Aborted;
m_status = Job_Aborted;
return true;
}
bool ForgeXzDownload::canAbort() const
bool ForgeXzDownload::canAbort()
{
return true;
}

View File

@ -19,9 +19,8 @@
#include "net/HttpMetaCache.h"
#include <QFile>
#include <QTemporaryFile>
#include "QObjectPtr.h"
typedef shared_qobject_ptr<class ForgeXzDownload> ForgeXzDownloadPtr;
typedef std::shared_ptr<class ForgeXzDownload> ForgeXzDownloadPtr;
class ForgeXzDownload : public NetAction
{
@ -42,7 +41,7 @@ public:
return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry));
}
virtual ~ForgeXzDownload(){};
bool canAbort() const override;
bool canAbort() override;
protected
slots:
@ -53,7 +52,7 @@ slots:
public
slots:
void executeTask() override;
void start() override;
bool abort() override;
private:

View File

@ -131,7 +131,7 @@ std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
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()))
{
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;
}
setStatusText(tr("Installing mods: Opening minecraft.jar ..."));
setStatus(tr("Installing mods: Opening minecraft.jar ..."));
QString outputJarPath = runnableJar.filePath();
QString inputJarPath = baseJar.filePath();

View File

@ -58,7 +58,7 @@ void LegacyUpdate::fmllibsStart()
auto &libList = fmlLibsMapping[version];
// 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++)
{
auto &mod = modList->operator[](i);
@ -105,7 +105,7 @@ void LegacyUpdate::fmllibsStart()
}
// download missing libs to our place
setStatusText(tr("Dowloading FML libraries..."));
setStatus(tr("Dowloading FML libraries..."));
auto dljob = new NetJob("FML libraries");
auto metacache = ENV.metacache();
for (auto &lib : fmlLibsToProcess)
@ -128,7 +128,7 @@ void LegacyUpdate::fmllibsFinished()
legacyDownloadJob.reset();
if(!fmlLibsToProcess.isEmpty())
{
setStatusText(tr("Copying FML libraries into the instance..."));
setStatus(tr("Copying FML libraries into the instance..."));
LegacyInstance *inst = (LegacyInstance *)m_inst;
auto metacache = ENV.metacache();
int index = 0;
@ -183,7 +183,7 @@ void LegacyUpdate::lwjglStart()
return;
}
setStatusText(tr("Downloading new LWJGL..."));
setStatus(tr("Downloading new LWJGL..."));
auto version = std::dynamic_pointer_cast<LWJGLVersion>(list->findVersion(lwjglVersion));
if (!version)
{
@ -247,7 +247,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
saveMe.open(QIODevice::WriteOnly);
saveMe.write(m_reply->readAll());
saveMe.close();
setStatusText(tr("Installing new LWJGL..."));
setStatus(tr("Installing new LWJGL..."));
extractLwjgl();
jarStart();
}
@ -323,7 +323,7 @@ void LegacyUpdate::extractLwjgl()
// Now if destFileName is still empty, go to the next file.
if (!destFileName.isEmpty())
{
setStatusText(tr("Installing new LWJGL - extracting ") + name + "...");
setStatus(tr("Installing new LWJGL - extracting ") + name + "...");
QFile output(destFileName);
output.open(QIODevice::WriteOnly);
output.write(file.readAll());
@ -353,7 +353,7 @@ void LegacyUpdate::jarStart()
return;
}
setStatusText(tr("Checking for jar updates..."));
setStatus(tr("Checking for jar updates..."));
// Make directories
QDir binDir(inst->binRoot());
if (!binDir.exists() && !binDir.mkpath("."))
@ -363,7 +363,7 @@ void LegacyUpdate::jarStart()
}
// 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();

View File

@ -41,7 +41,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
{
// create folders
{
m_tasks.append(new FoldersTask(m_inst));
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
}
// add metadata update tasks, if necessary
@ -66,7 +66,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
if(task)
{
qDebug() << "Loading remote meta patch" << id;
m_tasks.append(task);
m_tasks.append(task.unwrap());
}
}
else
@ -78,17 +78,17 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
// 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
{
m_tasks.append(new FMLLibrariesTask(m_inst));
m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst));
}
// 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::failed, this, &OneSixUpdate::subtaskFailed);
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())
{
@ -132,7 +132,7 @@ void OneSixUpdate::next()
connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
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(!task->isRunning())
{

View File

@ -46,7 +46,7 @@ private:
private:
OneSixInstance *m_inst = nullptr;
QList<shared_qobject_ptr<Task>> m_tasks;
QList<std::shared_ptr<Task>> m_tasks;
QString m_preFailure;
int m_currentTask = -1;
bool m_abort = false;

View File

@ -10,7 +10,7 @@ AssetUpdateTask::AssetUpdateTask(OneSixInstance * inst)
}
void AssetUpdateTask::executeTask()
{
setStatusText(tr("Updating assets index..."));
setStatus(tr("Updating assets index..."));
auto profile = m_inst->getMinecraftProfile();
auto assets = profile->getMinecraftAssets();
QUrl indexUrl = assets->url;
@ -63,7 +63,7 @@ void AssetUpdateTask::assetIndexFinished()
auto job = index.getDownloadJob();
if(job)
{
setStatusText(tr("Getting the assets files from Mojang..."));
setStatus(tr("Getting the assets files from Mojang..."));
downloadJob = job;
connect(downloadJob.get(), &NetJob::succeeded, this, &AssetUpdateTask::emitSucceeded);
connect(downloadJob.get(), &NetJob::failed, this, &AssetUpdateTask::assetsFailed);

View File

@ -32,7 +32,7 @@ void FMLLibrariesTask::executeTask()
auto &libList = fmlLibsMapping[version];
// 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);
// we don't...
if (!forge_present)
@ -58,7 +58,7 @@ void FMLLibrariesTask::executeTask()
}
// download missing libs to our place
setStatusText(tr("Dowloading FML libraries..."));
setStatus(tr("Dowloading FML libraries..."));
auto dljob = new NetJob("FML libraries");
auto metacache = ENV.metacache();
for (auto &lib : fmlLibsToProcess)
@ -86,7 +86,7 @@ void FMLLibrariesTask::fmllibsFinished()
downloadJob.reset();
if (!fmlLibsToProcess.isEmpty())
{
setStatusText(tr("Copying FML libraries into the instance..."));
setStatus(tr("Copying FML libraries into the instance..."));
OneSixInstance *inst = (OneSixInstance *)m_inst;
auto metacache = ENV.metacache();
int index = 0;

View File

@ -9,7 +9,7 @@ LibrariesTask::LibrariesTask(OneSixInstance * inst)
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";
OneSixInstance *inst = (OneSixInstance *)m_inst;
inst->reloadProfile();