feat: support installing worlds during flame pack import.

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2022-12-25 16:49:56 -07:00
parent 8422e3ac01
commit 78984eea3a

View File

@ -57,6 +57,9 @@
#include <minecraft/mod/tasks/LocalTexturePackParseTask.h> #include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
#include <minecraft/mod/tasks/LocalDataPackParseTask.h> #include <minecraft/mod/tasks/LocalDataPackParseTask.h>
#include <minecraft/mod/tasks/LocalModParseTask.h> #include <minecraft/mod/tasks/LocalModParseTask.h>
#include <minecraft/mod/tasks/LocalWorldSaveParseTask.h>
#include <minecraft/mod/tasks/LocalShaderPackParseTask.h>
#include <minecraft/World.h>
#include <qdebug.h> #include <qdebug.h>
#include <qfileinfo.h> #include <qfileinfo.h>
@ -537,13 +540,13 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
setAbortable(true); setAbortable(true);
} }
static bool moveFile(QString src, QString dst) bool moveFile(QString src, QString dst)
{ {
if (!FS::copy(src, dst)()) { // copy if (!FS::copy(src, dst)()) { // copy
qDebug() << "Copy of" << src << "to" << dst << "Failed!"; qDebug() << "Copy of" << src << "to" << dst << "Failed!";
return false; return false;
} else { } else {
if (!FS::deletePath(src)) { // remove origonal if (!FS::deletePath(src)) { // remove original
qDebug() << "Deleation of" << src << "Failed!"; qDebug() << "Deleation of" << src << "Failed!";
return false; return false;
}; };
@ -551,50 +554,53 @@ static bool moveFile(QString src, QString dst)
return true; return true;
} }
void FlameCreationTask::validateZIPResouces() void FlameCreationTask::validateZIPResouces()
{ {
qDebug() << "Validating resoucres stored as .zip are in the right place"; qDebug() << "Validating resoucres stored as .zip are in the right place";
for (auto [fileName, targetFolder] : m_ZIP_resources) { for (auto [fileName, targetFolder] : m_ZIP_resources) {
qDebug() << "Checking" << fileName << "..."; qDebug() << "Checking" << fileName << "...";
auto localPath = FS::PathCombine(m_stagingPath, "minecraft", targetFolder, fileName); auto localPath = FS::PathCombine(m_stagingPath, "minecraft", targetFolder, fileName);
QFileInfo localFileInfo(localPath);
if (localFileInfo.exists() && localFileInfo.isFile()) { auto validatePath = [&localPath, this](QString fileName, QString targetFolder, QString realTarget) {
if (ResourcePackUtils::validate(localFileInfo)) {
if (targetFolder != "resourcepacks") { if (targetFolder != "resourcepacks") {
qDebug() << "Target folder of" << fileName << "is incorrect, it's a resource pack."; qDebug() << "Target folder of" << fileName << "is incorrect, it's a resource pack.";
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "resourcepacks", fileName); auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "resourcepacks", fileName);
qDebug() << "Moveing" << localPath << "to" << destPath; qDebug() << "Moving" << localPath << "to" << destPath;
moveFile(localPath, destPath); if (moveFile(localPath, destPath)) {
return destPath;
}
} else { } else {
qDebug() << fileName << "is in the right place :" << targetFolder; qDebug() << fileName << "is in the right place :" << targetFolder;
} }
return localPath;
};
QFileInfo localFileInfo(localPath);
if (localFileInfo.exists() && localFileInfo.isFile()) {
if (ResourcePackUtils::validate(localFileInfo)) {
validatePath(fileName, targetFolder, "resourcepacks");
} else if (TexturePackUtils::validate(localFileInfo)) { } else if (TexturePackUtils::validate(localFileInfo)) {
if (targetFolder != "texturepacks") { validatePath(fileName, targetFolder, "texturepacks");
qDebug() << "Target folder of" << fileName << "is incorrect, it's a pre 1.6 texture pack.";
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "texturepacks", fileName);
qDebug() << "Moveing" << localPath << "to" << destPath;
moveFile(localPath, destPath);
} else {
qDebug() << fileName << "is in the right place :" << targetFolder;
}
} else if (DataPackUtils::validate(localFileInfo)) { } else if (DataPackUtils::validate(localFileInfo)) {
if (targetFolder != "datapacks") { validatePath(fileName, targetFolder, "datapacks");
qDebug() << "Target folder of" << fileName << "is incorrect, it's a data pack.";
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "datapacks", fileName);
qDebug() << "Moveing" << localPath << "to" << destPath;
moveFile(localPath, destPath);
} else {
qDebug() << fileName << "is in the right place :" << targetFolder;
}
} else if (ModUtils::validate(localFileInfo)) { } else if (ModUtils::validate(localFileInfo)) {
if (targetFolder != "mods") { validatePath(fileName, targetFolder, "mods");
qDebug() << "Target folder of" << fileName << "is incorrect, it's a mod."; } else if (WorldSaveUtils::validate(localFileInfo)) {
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "mods", fileName); QString worldPath = validatePath(fileName, targetFolder, "saves");
qDebug() << "Moveing" << localPath << "to" << destPath;
moveFile(localPath, destPath); qDebug() << "Installing World from" << worldPath;
World w(worldPath);
if (!w.isValid()) {
qDebug() << "World at" << worldPath << "is not valid, skipping install.";
} else { } else {
qDebug() << fileName << "is in the right place :" << targetFolder; w.install(FS::PathCombine(m_stagingPath, "minecraft", "saves"));
} }
} else if (ShaderPackUtils::validate(localFileInfo)) {
// in theroy flame API can't do this but who knows, that *may* change ?
// better to handle it if it *does* occure in the future
validatePath(fileName, targetFolder, "shaderpacks");
} else { } else {
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is."; qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
} }