NOISSUE Support cf-extract file type on modpacks.ch

This makes a start on supporting CurseForge pack installation through
the modpacks.ch API.
This commit is contained in:
Jamie Mansfield 2022-05-01 23:34:36 +01:00 committed by Petr Mrázek
parent cad522fe41
commit 863cf3807e
2 changed files with 46 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org> * Copyright 2020-2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2020-2021 Petr Mrazek <peterix@gmail.com> * Copyright 2020-2021 Petr Mrazek <peterix@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -19,6 +19,7 @@
#include "FileSystem.h" #include "FileSystem.h"
#include "Json.h" #include "Json.h"
#include "MMCZip.h"
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "net/ChecksumValidator.h" #include "net/ChecksumValidator.h"
@ -122,6 +123,10 @@ void PackInstallTask::downloadPack()
auto entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", cacheName); auto entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", cacheName);
entry->setStale(true); entry->setStale(true);
if (file.type == "cf-extract") {
filesToExtract[entry->getFullPath()] = file;
}
else {
auto relpath = FS::PathCombine("minecraft", file.path, file.name); auto relpath = FS::PathCombine("minecraft", file.path, file.name);
auto path = FS::PathCombine(m_stagingPath, relpath); auto path = FS::PathCombine(m_stagingPath, relpath);
@ -131,6 +136,7 @@ void PackInstallTask::downloadPack()
} }
qDebug() << "Will download" << file.url << "to" << path; qDebug() << "Will download" << file.url << "to" << path;
filesToCopy[path] = entry->getFullPath(); filesToCopy[path] = entry->getFullPath();
}
auto dl = Net::Download::makeCached(file.url, entry); auto dl = Net::Download::makeCached(file.url, entry);
if (!file.sha1.isEmpty()) { if (!file.sha1.isEmpty()) {
@ -163,18 +169,38 @@ void PackInstallTask::downloadPack()
void PackInstallTask::install() void PackInstallTask::install()
{ {
if (!filesToCopy.isEmpty()) {
setStatus(tr("Copying modpack files")); setStatus(tr("Copying modpack files"));
for (auto iter = filesToCopy.begin(); iter != filesToCopy.end(); iter++) { for (auto iter = filesToCopy.begin(); iter != filesToCopy.end(); iter++) {
auto &to = iter.key(); auto& to = iter.key();
auto &from = iter.value(); auto& from = iter.value();
FS::copy fileCopyOperation(from, to); FS::copy fileCopyOperation(from, to);
if(!fileCopyOperation()) { if (!fileCopyOperation()) {
qWarning() << "Failed to copy" << from << "to" << to; qWarning() << "Failed to copy" << from << "to" << to;
emitFailed(tr("Failed to copy files")); emitFailed(tr("Failed to copy files"));
return; return;
} }
} }
}
if (!filesToExtract.isEmpty()) {
setStatus(tr("Extracting modpack files"));
for (auto iter = filesToExtract.begin(); iter != filesToExtract.end(); iter++) {
auto& filePath = iter.key();
auto& file = iter.value();
auto relpath = FS::PathCombine("minecraft", file.path);
auto path = FS::PathCombine(m_stagingPath, relpath);
if (!MMCZip::extractDir(filePath, "overrides/", path)) {
qWarning() << "Failed to extract files from" << filePath << "to" << path;
emitFailed(tr("Failed to extract files"));
return;
}
}
}
setStatus(tr("Installing modpack")); setStatus(tr("Installing modpack"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org> * Copyright 2020-2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2020-2021 Petr Mrazek <peterix@gmail.com> * Copyright 2020-2021 Petr Mrazek <peterix@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -56,6 +56,7 @@ private:
QString m_version_name; QString m_version_name;
Version m_version; Version m_version;
QMap<QString, VersionFile> filesToExtract;
QMap<QString, QString> filesToCopy; QMap<QString, QString> filesToCopy;
}; };