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/LocalShaderPackParseTask.cpp
|
||||||
minecraft/mod/tasks/LocalWorldSaveParseTask.h
|
minecraft/mod/tasks/LocalWorldSaveParseTask.h
|
||||||
minecraft/mod/tasks/LocalWorldSaveParseTask.cpp
|
minecraft/mod/tasks/LocalWorldSaveParseTask.cpp
|
||||||
|
minecraft/mod/tasks/LocalResourceParse.h
|
||||||
|
minecraft/mod/tasks/LocalResourceParse.cpp
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
minecraft/AssetsUtils.h
|
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 <QFileInfo>
|
||||||
|
|
||||||
#include "minecraft/World.h"
|
#include "minecraft/World.h"
|
||||||
#include "minecraft/mod/tasks/LocalDataPackParseTask.h"
|
#include "minecraft/mod/tasks/LocalResourceParse.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"
|
|
||||||
|
|
||||||
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
||||||
{ "1.4.2", "6.0.1.355" },
|
{ "1.4.2", "6.0.1.355" },
|
||||||
@ -561,42 +557,48 @@ void FlameCreationTask::validateZIPResouces()
|
|||||||
return localPath;
|
return localPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
QFileInfo localFileInfo(localPath);
|
auto installWorld = [this](QString worldPath){
|
||||||
if (localFileInfo.exists() && localFileInfo.isFile()) {
|
qDebug() << "Installing World from" << worldPath;
|
||||||
if (ResourcePackUtils::validate(localFileInfo)) {
|
QFileInfo worldFileInfo(worldPath);
|
||||||
qDebug() << fileName << "is a resource pack";
|
World w(worldFileInfo);
|
||||||
validatePath(fileName, targetFolder, "resourcepacks");
|
if (!w.isValid()) {
|
||||||
} else if (TexturePackUtils::validate(localFileInfo)) {
|
qDebug() << "World at" << worldPath << "is not valid, skipping install.";
|
||||||
qDebug() << fileName << "is a pre 1.6 texture pack";
|
} else {
|
||||||
validatePath(fileName, targetFolder, "texturepacks");
|
w.install(FS::PathCombine(m_stagingPath, "minecraft", "saves"));
|
||||||
} 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");
|
|
||||||
|
|
||||||
qDebug() << "Installing World from" << worldPath;
|
QFileInfo localFileInfo(localPath);
|
||||||
QFileInfo worldFileInfo(worldPath);
|
auto type = ResourceUtils::identify(localFileInfo);
|
||||||
World w(worldFileInfo);
|
|
||||||
if (!w.isValid()) {
|
QString worldPath;
|
||||||
qDebug() << "World at" << worldPath << "is not valid, skipping install.";
|
|
||||||
} else {
|
switch (type) {
|
||||||
w.install(FS::PathCombine(m_stagingPath, "minecraft", "saves"));
|
case PackedResourceType::ResourcePack :
|
||||||
}
|
validatePath(fileName, targetFolder, "resourcepacks");
|
||||||
} else if (ShaderPackUtils::validate(localFileInfo)) {
|
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 ?
|
// 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
|
// better to handle it if it *does* occure in the future
|
||||||
qDebug() << fileName << "is a shader pack";
|
|
||||||
validatePath(fileName, targetFolder, "shaderpacks");
|
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.";
|
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
|
||||||
}
|
break;
|
||||||
} else {
|
|
||||||
qDebug() << "Can't find" << localPath << "to validate it, ignoring";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user