diff options
Diffstat (limited to 'api/logic/modplatform/modpacksch')
-rw-r--r-- | api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp | 38 | ||||
-rw-r--r-- | api/logic/modplatform/modpacksch/FTBPackInstallTask.h | 5 |
2 files changed, 41 insertions, 2 deletions
diff --git a/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp b/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp index ddc7fe35..f22373bc 100644 --- a/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -1,10 +1,12 @@ #include "FTBPackInstallTask.h" #include "BuildConfig.h" +#include "Env.h" #include "FileSystem.h" #include "Json.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" +#include "net/ChecksumValidator.h" #include "settings/INISettingsObject.h" namespace ModpacksCH { @@ -17,7 +19,11 @@ PackInstallTask::PackInstallTask(Modpack pack, QString version) bool PackInstallTask::abort() { - return true; + if(abortable) + { + return jobPtr->abort(); + } + return false; } void PackInstallTask::executeTask() @@ -93,26 +99,41 @@ void PackInstallTask::downloadPack() for(auto file : m_version.files) { if(file.serverOnly) continue; + QFileInfo fileName(file.name); + auto cacheName = fileName.completeBaseName() + "-" + file.sha1 + "." + fileName.suffix(); + + auto entry = ENV.metacache()->resolveEntry("ModpacksCHPacks", cacheName); + entry->setStale(true); + auto relpath = FS::PathCombine("minecraft", file.path, file.name); auto path = FS::PathCombine(m_stagingPath, relpath); qDebug() << "Will download" << file.url << "to" << path; - auto dl = Net::Download::makeFile(file.url, path); + filesToCopy[entry->getFullPath()] = path; + + auto dl = Net::Download::makeCached(file.url, entry); + if (!file.sha1.isEmpty()) { + auto rawSha1 = QByteArray::fromHex(file.sha1.toLatin1()); + dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1)); + } jobPtr->addNetAction(dl); } connect(jobPtr.get(), &NetJob::succeeded, this, [&]() { + abortable = false; jobPtr.reset(); install(); }); connect(jobPtr.get(), &NetJob::failed, [&](QString reason) { + abortable = false; jobPtr.reset(); emitFailed(reason); }); connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total) { + abortable = true; setProgress(current, total); }); @@ -121,6 +142,19 @@ void PackInstallTask::downloadPack() void PackInstallTask::install() { + setStatus(tr("Copying modpack files")); + + for (auto iter = filesToCopy.begin(); iter != filesToCopy.end(); iter++) { + auto &from = iter.key(); + auto &to = iter.value(); + FS::copy fileCopyOperation(from, to); + if(!fileCopyOperation()) { + qWarning() << "Failed to copy" << from << "to" << to; + emitFailed(tr("Failed to copy files")); + return; + } + } + setStatus(tr("Installing modpack")); auto instanceConfigPath = FS::PathCombine(m_stagingPath, "instance.cfg"); diff --git a/api/logic/modplatform/modpacksch/FTBPackInstallTask.h b/api/logic/modplatform/modpacksch/FTBPackInstallTask.h index 4f7786fd..55db3d3c 100644 --- a/api/logic/modplatform/modpacksch/FTBPackInstallTask.h +++ b/api/logic/modplatform/modpacksch/FTBPackInstallTask.h @@ -16,6 +16,7 @@ public: explicit PackInstallTask(Modpack pack, QString version); virtual ~PackInstallTask(){} + bool canAbort() const override { return true; } bool abort() override; protected: @@ -30,6 +31,8 @@ private: void install(); private: + bool abortable = false; + NetJobPtr jobPtr; QByteArray response; @@ -37,6 +40,8 @@ private: QString m_version_name; Version m_version; + QMap<QString, QString> filesToCopy; + }; } |