refactor: add an identify
function to make easy to reuse
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
c470f05abf
commit
7f438425aa
@ -363,6 +363,8 @@ set(MINECRAFT_SOURCES
|
||||
minecraft/mod/tasks/LocalShaderPackParseTask.cpp
|
||||
minecraft/mod/tasks/LocalWorldSaveParseTask.h
|
||||
minecraft/mod/tasks/LocalWorldSaveParseTask.cpp
|
||||
minecraft/mod/tasks/LocalResourceParse.h
|
||||
minecraft/mod/tasks/LocalResourceParse.cpp
|
||||
|
||||
# Assets
|
||||
minecraft/AssetsUtils.h
|
||||
|
60
launcher/minecraft/mod/tasks/LocalResourceParse.cpp
Normal file
60
launcher/minecraft/mod/tasks/LocalResourceParse.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LocalResourceParse.h"
|
||||
|
||||
#include "LocalDataPackParseTask.h"
|
||||
#include "LocalModParseTask.h"
|
||||
#include "LocalResourcePackParseTask.h"
|
||||
#include "LocalShaderPackParseTask.h"
|
||||
#include "LocalTexturePackParseTask.h"
|
||||
#include "LocalWorldSaveParseTask.h"
|
||||
|
||||
namespace ResourceUtils {
|
||||
PackedResourceType identify(QFileInfo file){
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (ResourcePackUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a resource pack";
|
||||
return PackedResourceType::ResourcePack;
|
||||
} else if (TexturePackUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a pre 1.6 texture pack";
|
||||
return PackedResourceType::TexturePack;
|
||||
} else if (DataPackUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a data pack";
|
||||
return PackedResourceType::DataPack;
|
||||
} else if (ModUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a mod";
|
||||
return PackedResourceType::Mod;
|
||||
} else if (WorldSaveUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a world save";
|
||||
return PackedResourceType::WorldSave;
|
||||
} else if (ShaderPackUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a shader pack";
|
||||
return PackedResourceType::ShaderPack;
|
||||
} else {
|
||||
qDebug() << "Can't Identify" << file.fileName() ;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Can't find" << file.absolutePath();
|
||||
}
|
||||
return PackedResourceType::UNKNOWN;
|
||||
}
|
||||
}
|
31
launcher/minecraft/mod/tasks/LocalResourceParse.h
Normal file
31
launcher/minecraft/mod/tasks/LocalResourceParse.h
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QObject>
|
||||
|
||||
enum class PackedResourceType { DataPack, ResourcePack, TexturePack, ShaderPack, WorldSave, Mod, UNKNOWN };
|
||||
namespace ResourceUtils {
|
||||
PackedResourceType identify(QFileInfo file);
|
||||
} // namespace ResourceUtils
|
@ -57,12 +57,8 @@
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "minecraft/World.h"
|
||||
#include "minecraft/mod/tasks/LocalDataPackParseTask.h"
|
||||
#include "minecraft/mod/tasks/LocalModParseTask.h"
|
||||
#include "minecraft/mod/tasks/LocalResourcePackParseTask.h"
|
||||
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h"
|
||||
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
||||
#include "minecraft/mod/tasks/LocalWorldSaveParseTask.h"
|
||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
||||
|
||||
|
||||
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
||||
{ "1.4.2", "6.0.1.355" },
|
||||
@ -561,42 +557,48 @@ void FlameCreationTask::validateZIPResouces()
|
||||
return localPath;
|
||||
};
|
||||
|
||||
QFileInfo localFileInfo(localPath);
|
||||
if (localFileInfo.exists() && localFileInfo.isFile()) {
|
||||
if (ResourcePackUtils::validate(localFileInfo)) {
|
||||
qDebug() << fileName << "is a resource pack";
|
||||
validatePath(fileName, targetFolder, "resourcepacks");
|
||||
} else if (TexturePackUtils::validate(localFileInfo)) {
|
||||
qDebug() << fileName << "is a pre 1.6 texture pack";
|
||||
validatePath(fileName, targetFolder, "texturepacks");
|
||||
} else if (DataPackUtils::validate(localFileInfo)) {
|
||||
qDebug() << fileName << "is a data pack";
|
||||
validatePath(fileName, targetFolder, "datapacks");
|
||||
} else if (ModUtils::validate(localFileInfo)) {
|
||||
qDebug() << fileName << "is a mod";
|
||||
validatePath(fileName, targetFolder, "mods");
|
||||
} else if (WorldSaveUtils::validate(localFileInfo)) {
|
||||
qDebug() << fileName << "is a world save";
|
||||
QString worldPath = validatePath(fileName, targetFolder, "saves");
|
||||
auto installWorld = [this](QString worldPath){
|
||||
qDebug() << "Installing World from" << worldPath;
|
||||
QFileInfo worldFileInfo(worldPath);
|
||||
World w(worldFileInfo);
|
||||
if (!w.isValid()) {
|
||||
qDebug() << "World at" << worldPath << "is not valid, skipping install.";
|
||||
} else {
|
||||
w.install(FS::PathCombine(m_stagingPath, "minecraft", "saves"));
|
||||
}
|
||||
};
|
||||
|
||||
qDebug() << "Installing World from" << worldPath;
|
||||
QFileInfo worldFileInfo(worldPath);
|
||||
World w(worldFileInfo);
|
||||
if (!w.isValid()) {
|
||||
qDebug() << "World at" << worldPath << "is not valid, skipping install.";
|
||||
} else {
|
||||
w.install(FS::PathCombine(m_stagingPath, "minecraft", "saves"));
|
||||
}
|
||||
} else if (ShaderPackUtils::validate(localFileInfo)) {
|
||||
QFileInfo localFileInfo(localPath);
|
||||
auto type = ResourceUtils::identify(localFileInfo);
|
||||
|
||||
QString worldPath;
|
||||
|
||||
switch (type) {
|
||||
case PackedResourceType::ResourcePack :
|
||||
validatePath(fileName, targetFolder, "resourcepacks");
|
||||
break;
|
||||
case PackedResourceType::TexturePack :
|
||||
validatePath(fileName, targetFolder, "texturepacks");
|
||||
break;
|
||||
case PackedResourceType::DataPack :
|
||||
validatePath(fileName, targetFolder, "datapacks");
|
||||
break;
|
||||
case PackedResourceType::Mod :
|
||||
validatePath(fileName, targetFolder, "mods");
|
||||
break;
|
||||
case PackedResourceType::ShaderPack :
|
||||
// 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
|
||||
qDebug() << fileName << "is a shader pack";
|
||||
validatePath(fileName, targetFolder, "shaderpacks");
|
||||
} else {
|
||||
break;
|
||||
case PackedResourceType::WorldSave :
|
||||
worldPath = validatePath(fileName, targetFolder, "saves");
|
||||
installWorld(worldPath);
|
||||
break;
|
||||
case PackedResourceType::UNKNOWN :
|
||||
default :
|
||||
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Can't find" << localPath << "to validate it, ignoring";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user