diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-04-29 02:24:00 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-04-29 02:24:00 +0200 |
commit | e1465f4848d003cab3d3d1288c1a0f3b945083ee (patch) | |
tree | 6721fbaac70aa39cb0f0dd75b75e8e6f87d42743 /api/logic/minecraft/forge | |
parent | 243f7e4fb4d58fa530404930566f83d1dc481588 (diff) | |
download | MultiMC-e1465f4848d003cab3d3d1288c1a0f3b945083ee.tar MultiMC-e1465f4848d003cab3d3d1288c1a0f3b945083ee.tar.gz MultiMC-e1465f4848d003cab3d3d1288c1a0f3b945083ee.tar.lz MultiMC-e1465f4848d003cab3d3d1288c1a0f3b945083ee.tar.xz MultiMC-e1465f4848d003cab3d3d1288c1a0f3b945083ee.zip |
NOISSUE refactor NetAction to be based on Task
Still missing some things, this is part 1.
Diffstat (limited to 'api/logic/minecraft/forge')
-rw-r--r-- | api/logic/minecraft/forge/ForgeXzDownload.cpp | 56 | ||||
-rw-r--r-- | api/logic/minecraft/forge/ForgeXzDownload.h | 4 |
2 files changed, 30 insertions, 30 deletions
diff --git a/api/logic/minecraft/forge/ForgeXzDownload.cpp b/api/logic/minecraft/forge/ForgeXzDownload.cpp index 4d94dd12..8bcd43aa 100644 --- a/api/logic/minecraft/forge/ForgeXzDownload.cpp +++ b/api/logic/minecraft/forge/ForgeXzDownload.cpp @@ -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 = Job_NotStarted; + m_status = Status::NotStarted; m_url_path = relative_path; m_url = "http://files.minecraftforge.net/maven/" + m_url_path + ".pack.xz"; } -void ForgeXzDownload::start() +void ForgeXzDownload::executeTask() { - if(m_status == Job_Aborted) + if(m_status == Status::Aborted) { qWarning() << "Attempt to start an aborted Download:" << m_url.toString(); - emit aborted(m_index_within_job); + emit aborted(); return; } - m_status = Job_InProgress; + m_status = Status::InProgress; if (!m_entry->isStale()) { - m_status = Job_Finished; - emit succeeded(m_index_within_job); + m_status = Status::Finished; + emit succeeded(); return; } // can we actually create the real, final file? if (!FS::ensureFilePathExists(m_target_path)) { - m_status = Job_Failed; - emit failed(m_index_within_job); + m_status = Status::Failed; + emit failed(); return; } @@ -72,9 +72,9 @@ void ForgeXzDownload::start() void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { - m_total_progress = bytesTotal; + m_progressTotal = bytesTotal; m_progress = bytesReceived; - emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); + emit progress(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 = Job_Aborted; + m_status = Status::Aborted; } else { // error happened during download. qCritical() << "Failed " << m_url.toString() << " with reason " << error; - m_status = Job_Failed; + m_status = Status::Failed; } } void ForgeXzDownload::failAndTryNextMirror() { - m_status = Job_Failed; - emit failed(m_index_within_job); + m_status = Status::Failed; + emit failed(); } void ForgeXzDownload::downloadFinished() { // if the download succeeded - if (m_status != Job_Failed && m_status != Job_Aborted) + if (m_status != Status::Failed && m_status != Status::Aborted) { // nothing went wrong... - m_status = Job_Finished; + m_status = Status::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 = Job_Failed; + m_status = Status::Failed; m_pack200_xz_file.remove(); m_reply.reset(); - emit failed(m_index_within_job); + emit failed(); return; } } - else if(m_status == Job_Aborted) + else if(m_status == Status::Aborted) { m_pack200_xz_file.remove(); m_reply.reset(); - emit failed(m_index_within_job); - emit aborted(m_index_within_job); + emit failed(); + emit aborted(); return; } // else the download failed else { - m_status = Job_Failed; + m_status = Status::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(m_index_within_job); + emit failed(); return; } } @@ -345,7 +345,7 @@ void ForgeXzDownload::decompressAndInstall() } catch (std::runtime_error &err) { - m_status = Job_Failed; + m_status = Status::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(m_index_within_job); + emit succeeded(); } bool ForgeXzDownload::abort() { if(m_reply) m_reply->abort(); - m_status = Job_Aborted; + m_status = Status::Aborted; return true; } -bool ForgeXzDownload::canAbort() +bool ForgeXzDownload::canAbort() const { return true; } diff --git a/api/logic/minecraft/forge/ForgeXzDownload.h b/api/logic/minecraft/forge/ForgeXzDownload.h index ef23809b..ede4e6ce 100644 --- a/api/logic/minecraft/forge/ForgeXzDownload.h +++ b/api/logic/minecraft/forge/ForgeXzDownload.h @@ -41,7 +41,7 @@ public: return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry)); } virtual ~ForgeXzDownload(){}; - bool canAbort() override; + bool canAbort() const override; protected slots: @@ -52,7 +52,7 @@ slots: public slots: - void start() override; + void executeTask() override; bool abort() override; private: |