mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 13:17:41 +02:00
Merge remote-tracking branch 'upstream/develop' into resource-meta
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
@ -38,7 +38,6 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QSaveFile>
|
||||
#include <QString>
|
||||
|
||||
#include <FileSystem.h>
|
||||
@ -57,6 +56,7 @@
|
||||
#include <optional>
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "PSaveFile.h"
|
||||
|
||||
using std::nullopt;
|
||||
using std::optional;
|
||||
@ -183,7 +183,7 @@ bool putLevelDatDataToFS(const QFileInfo& file, QByteArray& data)
|
||||
if (fullFilePath.isNull()) {
|
||||
return false;
|
||||
}
|
||||
QSaveFile f(fullFilePath);
|
||||
PSaveFile f(fullFilePath);
|
||||
if (!f.open(QIODevice::WriteOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -180,6 +180,7 @@ bool parseMinecraftProfile(QByteArray& data, MinecraftProfile& output)
|
||||
if (!getString(skinObj.value("url"), skinOut.url)) {
|
||||
continue;
|
||||
}
|
||||
skinOut.url.replace("http://textures.minecraft.net", "https://textures.minecraft.net");
|
||||
if (!getString(skinObj.value("variant"), skinOut.variant)) {
|
||||
continue;
|
||||
}
|
||||
@ -221,9 +222,9 @@ namespace {
|
||||
// these skin URLs are for the MHF_Steve and MHF_Alex accounts (made by a Mojang employee)
|
||||
// they are needed because the session server doesn't return skin urls for default skins
|
||||
static const QString SKIN_URL_STEVE =
|
||||
"http://textures.minecraft.net/texture/1a4af718455d4aab528e7a61f86fa25e6a369d1768dcb13f7df319a713eb810b";
|
||||
"https://textures.minecraft.net/texture/1a4af718455d4aab528e7a61f86fa25e6a369d1768dcb13f7df319a713eb810b";
|
||||
static const QString SKIN_URL_ALEX =
|
||||
"http://textures.minecraft.net/texture/83cee5ca6afcdb171285aa00e8049c297b2dbeba0efb8ff970a5677a1b644032";
|
||||
"https://textures.minecraft.net/texture/83cee5ca6afcdb171285aa00e8049c297b2dbeba0efb8ff970a5677a1b644032";
|
||||
|
||||
bool isDefaultModelSteve(QString uuid)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@
|
||||
|
||||
AutoInstallJava::AutoInstallJava(LaunchTask* parent)
|
||||
: LaunchStep(parent)
|
||||
, m_instance(std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance()))
|
||||
, m_instance(m_parent->instance())
|
||||
, m_supported_arch(SysInfo::getSupportedJavaArchitecture()) {};
|
||||
|
||||
void AutoInstallJava::executeTask()
|
||||
|
@ -8,16 +8,15 @@ CreateGameFolders::CreateGameFolders(LaunchTask* parent) : LaunchStep(parent) {}
|
||||
void CreateGameFolders::executeTask()
|
||||
{
|
||||
auto instance = m_parent->instance();
|
||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
||||
|
||||
if (!FS::ensureFolderPathExists(minecraftInstance->gameRoot())) {
|
||||
if (!FS::ensureFolderPathExists(instance->gameRoot())) {
|
||||
emit logLine("Couldn't create the main game folder", MessageLevel::Error);
|
||||
emitFailed(tr("Couldn't create the main game folder"));
|
||||
return;
|
||||
}
|
||||
|
||||
// HACK: this is a workaround for MCL-3732 - 'server-resource-packs' folder is created.
|
||||
if (!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->gameRoot(), "server-resource-packs"))) {
|
||||
if (!FS::ensureFolderPathExists(FS::PathCombine(instance->gameRoot(), "server-resource-packs"))) {
|
||||
emit logLine("Couldn't create the 'server-resource-packs' folder", MessageLevel::Error);
|
||||
}
|
||||
emitSucceeded();
|
||||
|
@ -70,17 +70,16 @@ static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibH
|
||||
void ExtractNatives::executeTask()
|
||||
{
|
||||
auto instance = m_parent->instance();
|
||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
||||
auto toExtract = minecraftInstance->getNativeJars();
|
||||
auto toExtract = instance->getNativeJars();
|
||||
if (toExtract.isEmpty()) {
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
auto settings = minecraftInstance->settings();
|
||||
auto settings = instance->settings();
|
||||
|
||||
auto outputPath = minecraftInstance->getNativePath();
|
||||
auto outputPath = instance->getNativePath();
|
||||
FS::ensureFolderPathExists(outputPath);
|
||||
auto javaVersion = minecraftInstance->getJavaVersion();
|
||||
auto javaVersion = instance->getJavaVersion();
|
||||
bool jniHackEnabled = javaVersion.major() >= 8;
|
||||
for (const auto& source : toExtract) {
|
||||
if (!unzipNatives(source, outputPath, jniHackEnabled)) {
|
||||
|
@ -48,18 +48,20 @@
|
||||
#include "gamemode_client.h"
|
||||
#endif
|
||||
|
||||
LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent) : LaunchStep(parent)
|
||||
LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent)
|
||||
: LaunchStep(parent)
|
||||
, m_process(parent->instance()->getJavaVersion().defaultsToUtf8() ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale())
|
||||
{
|
||||
auto instance = parent->instance();
|
||||
if (instance->settings()->get("CloseAfterLaunch").toBool()) {
|
||||
if (parent->instance()->settings()->get("CloseAfterLaunch").toBool()) {
|
||||
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
|
||||
*connection = connect(&m_process, &LoggedProcess::log, this, [=](QStringList lines, [[maybe_unused]] MessageLevel::Enum level) {
|
||||
qDebug() << lines;
|
||||
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
|
||||
APPLICATION->closeAllWindows();
|
||||
disconnect(*connection);
|
||||
}
|
||||
});
|
||||
*connection =
|
||||
connect(&m_process, &LoggedProcess::log, this, [=](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
|
||||
qDebug() << lines;
|
||||
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
|
||||
APPLICATION->closeAllWindows();
|
||||
disconnect(*connection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
|
||||
@ -77,10 +79,9 @@ void LauncherPartLaunch::executeTask()
|
||||
}
|
||||
|
||||
auto instance = m_parent->instance();
|
||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
||||
|
||||
QString legacyJarPath;
|
||||
if (minecraftInstance->getLauncher() == "legacy" || minecraftInstance->shouldApplyOnlineFixes()) {
|
||||
if (instance->getLauncher() == "legacy" || instance->shouldApplyOnlineFixes()) {
|
||||
legacyJarPath = APPLICATION->getJarPath("NewLaunchLegacy.jar");
|
||||
if (legacyJarPath.isEmpty()) {
|
||||
const char* reason = QT_TR_NOOP("Legacy launcher library could not be found. Please check your installation.");
|
||||
@ -90,8 +91,8 @@ void LauncherPartLaunch::executeTask()
|
||||
}
|
||||
}
|
||||
|
||||
m_launchScript = minecraftInstance->createLaunchScript(m_session, m_targetToJoin);
|
||||
QStringList args = minecraftInstance->javaArguments();
|
||||
m_launchScript = instance->createLaunchScript(m_session, m_targetToJoin);
|
||||
QStringList args = instance->javaArguments();
|
||||
QString allArgs = args.join(", ");
|
||||
emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::Launcher);
|
||||
|
||||
@ -102,13 +103,13 @@ void LauncherPartLaunch::executeTask()
|
||||
// make detachable - this will keep the process running even if the object is destroyed
|
||||
m_process.setDetachable(true);
|
||||
|
||||
auto classPath = minecraftInstance->getClassPath();
|
||||
auto classPath = instance->getClassPath();
|
||||
classPath.prepend(jarPath);
|
||||
|
||||
if (!legacyJarPath.isEmpty())
|
||||
classPath.prepend(legacyJarPath);
|
||||
|
||||
auto natPath = minecraftInstance->getNativePath();
|
||||
auto natPath = instance->getNativePath();
|
||||
#ifdef Q_OS_WIN
|
||||
natPath = FS::getPathNameInLocal8bit(natPath);
|
||||
#endif
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
void ModMinecraftJar::executeTask()
|
||||
{
|
||||
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
||||
auto m_inst = m_parent->instance();
|
||||
|
||||
if (!m_inst->getJarMods().size()) {
|
||||
emitSucceeded();
|
||||
@ -82,7 +82,7 @@ void ModMinecraftJar::finalize()
|
||||
|
||||
bool ModMinecraftJar::removeJar()
|
||||
{
|
||||
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
||||
auto m_inst = m_parent->instance();
|
||||
auto finalJarPath = QDir(m_inst->binRoot()).absoluteFilePath("minecraft.jar");
|
||||
QFile finalJar(finalJarPath);
|
||||
if (finalJar.exists()) {
|
||||
|
@ -22,12 +22,11 @@
|
||||
void ReconstructAssets::executeTask()
|
||||
{
|
||||
auto instance = m_parent->instance();
|
||||
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
|
||||
auto components = minecraftInstance->getPackProfile();
|
||||
auto components = instance->getPackProfile();
|
||||
auto profile = components->getProfile();
|
||||
auto assets = profile->getMinecraftAssets();
|
||||
|
||||
if (!AssetsUtils::reconstructAssets(assets->id, minecraftInstance->resourcesDir())) {
|
||||
if (!AssetsUtils::reconstructAssets(assets->id, instance->resourcesDir())) {
|
||||
emit logLine("Failed to reconstruct Minecraft assets.", MessageLevel::Error);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
void ScanModFolders::executeTask()
|
||||
{
|
||||
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
||||
auto m_inst = m_parent->instance();
|
||||
|
||||
auto loaders = m_inst->loaderModList();
|
||||
connect(loaders.get(), &ModFolderModel::updateFinished, this, &ScanModFolders::modsDone);
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
void VerifyJavaInstall::executeTask()
|
||||
{
|
||||
auto instance = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
|
||||
auto instance = m_parent->instance();
|
||||
auto packProfile = instance->getPackProfile();
|
||||
auto settings = instance->settings();
|
||||
auto storedVersion = settings->get("JavaVersion").toString();
|
||||
|
@ -35,6 +35,7 @@
|
||||
*/
|
||||
|
||||
#include "Mod.h"
|
||||
#include <qpixmap.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
@ -210,7 +211,7 @@ void Mod::finishResolvingWithDetails(ModDetails&& details)
|
||||
|
||||
m_local_details = std::move(details);
|
||||
if (!iconPath().isEmpty()) {
|
||||
m_pack_image_cache_key.was_read_attempt = false;
|
||||
m_packImageCacheKey.wasReadAttempt = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,45 +225,53 @@ auto Mod::issueTracker() const -> QString
|
||||
return details().issue_tracker;
|
||||
}
|
||||
|
||||
void Mod::setIcon(QImage new_image) const
|
||||
QPixmap Mod::setIcon(QImage new_image) const
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
Q_ASSERT(!new_image.isNull());
|
||||
|
||||
if (m_pack_image_cache_key.key.isValid())
|
||||
PixmapCache::remove(m_pack_image_cache_key.key);
|
||||
if (m_packImageCacheKey.key.isValid())
|
||||
PixmapCache::remove(m_packImageCacheKey.key);
|
||||
|
||||
// scale the image to avoid flooding the pixmapcache
|
||||
auto pixmap =
|
||||
QPixmap::fromImage(new_image.scaled({ 64, 64 }, Qt::AspectRatioMode::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
|
||||
|
||||
m_pack_image_cache_key.key = PixmapCache::insert(pixmap);
|
||||
m_pack_image_cache_key.was_ever_used = true;
|
||||
m_pack_image_cache_key.was_read_attempt = true;
|
||||
m_packImageCacheKey.key = PixmapCache::insert(pixmap);
|
||||
m_packImageCacheKey.wasEverUsed = true;
|
||||
m_packImageCacheKey.wasReadAttempt = true;
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QPixmap Mod::icon(QSize size, Qt::AspectRatioMode mode) const
|
||||
{
|
||||
QPixmap cached_image;
|
||||
if (PixmapCache::find(m_pack_image_cache_key.key, &cached_image)) {
|
||||
auto pixmap_transform = [&size, &mode](QPixmap pixmap) {
|
||||
if (size.isNull())
|
||||
return cached_image;
|
||||
return cached_image.scaled(size, mode, Qt::SmoothTransformation);
|
||||
return pixmap;
|
||||
return pixmap.scaled(size, mode, Qt::SmoothTransformation);
|
||||
};
|
||||
|
||||
QPixmap cached_image;
|
||||
if (PixmapCache::find(m_packImageCacheKey.key, &cached_image)) {
|
||||
return pixmap_transform(cached_image);
|
||||
}
|
||||
|
||||
// No valid image we can get
|
||||
if ((!m_pack_image_cache_key.was_ever_used && m_pack_image_cache_key.was_read_attempt) || iconPath().isEmpty())
|
||||
if ((!m_packImageCacheKey.wasEverUsed && m_packImageCacheKey.wasReadAttempt) || iconPath().isEmpty())
|
||||
return {};
|
||||
|
||||
if (m_pack_image_cache_key.was_ever_used) {
|
||||
if (m_packImageCacheKey.wasEverUsed) {
|
||||
qDebug() << "Mod" << name() << "Had it's icon evicted from the cache. reloading...";
|
||||
PixmapCache::markCacheMissByEviciton();
|
||||
}
|
||||
// Image got evicted from the cache or an attempt to load it has not been made. load it and retry.
|
||||
m_pack_image_cache_key.was_read_attempt = true;
|
||||
ModUtils::loadIconFile(*this);
|
||||
return icon(size);
|
||||
m_packImageCacheKey.wasReadAttempt = true;
|
||||
if (ModUtils::loadIconFile(*this, &cached_image)) {
|
||||
return pixmap_transform(cached_image);
|
||||
}
|
||||
// Image failed to load
|
||||
return {};
|
||||
}
|
||||
|
||||
bool Mod::valid() const
|
||||
|
@ -77,7 +77,7 @@ class Mod : public Resource {
|
||||
/** Gets the icon of the mod, converted to a QPixmap for drawing, and scaled to size. */
|
||||
[[nodiscard]] QPixmap icon(QSize size, Qt::AspectRatioMode mode = Qt::AspectRatioMode::IgnoreAspectRatio) const;
|
||||
/** Thread-safe. */
|
||||
void setIcon(QImage new_image) const;
|
||||
QPixmap setIcon(QImage new_image) const;
|
||||
|
||||
void setDetails(const ModDetails& details);
|
||||
|
||||
@ -100,7 +100,7 @@ class Mod : public Resource {
|
||||
|
||||
struct {
|
||||
QPixmapCache::Key key;
|
||||
bool was_ever_used = false;
|
||||
bool was_read_attempt = false;
|
||||
} mutable m_pack_image_cache_key;
|
||||
bool wasEverUsed = false;
|
||||
bool wasReadAttempt = false;
|
||||
} mutable m_packImageCacheKey;
|
||||
};
|
||||
|
@ -40,10 +40,9 @@ ResourceFolderModel::ResourceFolderModel(const QDir& dir, BaseInstance* instance
|
||||
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &ResourceFolderModel::directoryChanged);
|
||||
connect(&m_helper_thread_task, &ConcurrentTask::finished, this, [this] { m_helper_thread_task.clear(); });
|
||||
#ifndef LAUNCHER_TEST
|
||||
// in tests the application macro doesn't work
|
||||
m_helper_thread_task.setMaxConcurrent(APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
||||
#endif
|
||||
if (APPLICATION_DYN) { // in tests the application macro doesn't work
|
||||
m_helper_thread_task.setMaxConcurrent(APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
||||
}
|
||||
}
|
||||
|
||||
ResourceFolderModel::~ResourceFolderModel()
|
||||
|
85
launcher/minecraft/mod/tasks/BasicFolderLoadTask.h
Normal file
85
launcher/minecraft/mod/tasks/BasicFolderLoadTask.h
Normal file
@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Application.h"
|
||||
#include "FileSystem.h"
|
||||
#include "minecraft/mod/Resource.h"
|
||||
|
||||
#include "tasks/Task.h"
|
||||
|
||||
/** Very simple task that just loads a folder's contents directly.
|
||||
*/
|
||||
class BasicFolderLoadTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct Result {
|
||||
QMap<QString, Resource::Ptr> resources;
|
||||
};
|
||||
using ResultPtr = std::shared_ptr<Result>;
|
||||
|
||||
[[nodiscard]] ResultPtr result() const { return m_result; }
|
||||
|
||||
public:
|
||||
BasicFolderLoadTask(QDir dir) : Task(nullptr, false), m_dir(dir), m_result(new Result), m_thread_to_spawn_into(thread())
|
||||
{
|
||||
m_create_func = [](QFileInfo const& entry) -> Resource::Ptr { return makeShared<Resource>(entry); };
|
||||
}
|
||||
BasicFolderLoadTask(QDir dir, std::function<Resource::Ptr(QFileInfo const&)> create_function)
|
||||
: Task(nullptr, false)
|
||||
, m_dir(dir)
|
||||
, m_result(new Result)
|
||||
, m_create_func(std::move(create_function))
|
||||
, m_thread_to_spawn_into(thread())
|
||||
{}
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
bool abort() override
|
||||
{
|
||||
m_aborted.store(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void executeTask() override
|
||||
{
|
||||
if (thread() != m_thread_to_spawn_into)
|
||||
connect(this, &Task::finished, this->thread(), &QThread::quit);
|
||||
|
||||
m_dir.refresh();
|
||||
for (auto entry : m_dir.entryInfoList()) {
|
||||
auto filePath = entry.absoluteFilePath();
|
||||
if (auto app = APPLICATION_DYN; app && app->checkQSavePath(filePath)) {
|
||||
continue;
|
||||
}
|
||||
auto newFilePath = FS::getUniqueResourceName(filePath);
|
||||
if (newFilePath != filePath) {
|
||||
FS::move(filePath, newFilePath);
|
||||
entry = QFileInfo(newFilePath);
|
||||
}
|
||||
auto resource = m_create_func(entry);
|
||||
resource->moveToThread(m_thread_to_spawn_into);
|
||||
m_result->resources.insert(resource->internal_id(), resource);
|
||||
}
|
||||
|
||||
if (m_aborted)
|
||||
emit finished();
|
||||
else
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
private:
|
||||
QDir m_dir;
|
||||
ResultPtr m_result;
|
||||
|
||||
std::atomic<bool> m_aborted = false;
|
||||
|
||||
std::function<Resource::Ptr(QFileInfo const&)> m_create_func;
|
||||
|
||||
/** This is the thread in which we should put new mod objects */
|
||||
QThread* m_thread_to_spawn_into;
|
||||
};
|
@ -647,11 +647,11 @@ bool validate(QFileInfo file)
|
||||
return ModUtils::process(mod, ProcessingLevel::BasicInfoOnly) && mod.valid();
|
||||
}
|
||||
|
||||
bool processIconPNG(const Mod& mod, QByteArray&& raw_data)
|
||||
bool processIconPNG(const Mod& mod, QByteArray&& raw_data, QPixmap* pixmap)
|
||||
{
|
||||
auto img = QImage::fromData(raw_data);
|
||||
if (!img.isNull()) {
|
||||
mod.setIcon(img);
|
||||
*pixmap = mod.setIcon(img);
|
||||
} else {
|
||||
qWarning() << "Failed to parse mod logo:" << mod.iconPath() << "from" << mod.name();
|
||||
return false;
|
||||
@ -659,15 +659,15 @@ bool processIconPNG(const Mod& mod, QByteArray&& raw_data)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadIconFile(const Mod& mod)
|
||||
bool loadIconFile(const Mod& mod, QPixmap* pixmap)
|
||||
{
|
||||
if (mod.iconPath().isEmpty()) {
|
||||
qWarning() << "No Iconfile set, be sure to parse the mod first";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto png_invalid = [&mod]() {
|
||||
qWarning() << "Mod at" << mod.fileinfo().filePath() << "does not have a valid icon";
|
||||
auto png_invalid = [&mod](const QString& reason) {
|
||||
qWarning() << "Mod at" << mod.fileinfo().filePath() << "does not have a valid icon:" << reason;
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -676,24 +676,26 @@ bool loadIconFile(const Mod& mod)
|
||||
QFileInfo icon_info(FS::PathCombine(mod.fileinfo().filePath(), mod.iconPath()));
|
||||
if (icon_info.exists() && icon_info.isFile()) {
|
||||
QFile icon(icon_info.filePath());
|
||||
if (!icon.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
if (!icon.open(QIODevice::ReadOnly)) {
|
||||
return png_invalid("failed to open file " + icon_info.filePath());
|
||||
}
|
||||
auto data = icon.readAll();
|
||||
|
||||
bool icon_result = ModUtils::processIconPNG(mod, std::move(data));
|
||||
bool icon_result = ModUtils::processIconPNG(mod, std::move(data), pixmap);
|
||||
|
||||
icon.close();
|
||||
|
||||
if (!icon_result) {
|
||||
return png_invalid(); // icon invalid
|
||||
return png_invalid("invalid png image"); // icon invalid
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return png_invalid("file '" + icon_info.filePath() + "' does not exists or is not a file");
|
||||
}
|
||||
case ResourceType::ZIPFILE: {
|
||||
QuaZip zip(mod.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return false;
|
||||
return png_invalid("failed to open '" + mod.fileinfo().filePath() + "' as a zip archive");
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
@ -701,28 +703,27 @@ bool loadIconFile(const Mod& mod)
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file in zip.";
|
||||
zip.close();
|
||||
return png_invalid();
|
||||
return png_invalid("Failed to open '" + mod.iconPath() + "' in zip archive");
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
bool icon_result = ModUtils::processIconPNG(mod, std::move(data));
|
||||
bool icon_result = ModUtils::processIconPNG(mod, std::move(data), pixmap);
|
||||
|
||||
file.close();
|
||||
if (!icon_result) {
|
||||
return png_invalid(); // icon png invalid
|
||||
return png_invalid("invalid png image"); // icon png invalid
|
||||
}
|
||||
} else {
|
||||
return png_invalid(); // could not set icon as current file.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return png_invalid("Failed to set '" + mod.iconPath() +
|
||||
"' as current file in zip archive"); // could not set icon as current file.
|
||||
}
|
||||
case ResourceType::LITEMOD: {
|
||||
return false; // can lightmods even have icons?
|
||||
return png_invalid("litemods do not have icons"); // can lightmods even have icons?
|
||||
}
|
||||
default:
|
||||
qWarning() << "Invalid type for mod, can not load icon.";
|
||||
return false;
|
||||
return png_invalid("Invalid type for mod, can not load icon.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ bool processLitemod(Mod& mod, ProcessingLevel level = ProcessingLevel::Full);
|
||||
/** Checks whether a file is valid as a mod or not. */
|
||||
bool validate(QFileInfo file);
|
||||
|
||||
bool processIconPNG(const Mod& mod, QByteArray&& raw_data);
|
||||
bool loadIconFile(const Mod& mod);
|
||||
bool processIconPNG(const Mod& mod, QByteArray&& raw_data, QPixmap* pixmap);
|
||||
bool loadIconFile(const Mod& mod, QPixmap* pixmap);
|
||||
} // namespace ModUtils
|
||||
|
||||
class LocalModParseTask : public Task {
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "ResourceFolderLoadTask.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "FileSystem.h"
|
||||
#include "minecraft/mod/MetadataHandler.h"
|
||||
|
||||
@ -70,6 +71,9 @@ void ResourceFolderLoadTask::executeTask()
|
||||
m_resource_dir.refresh();
|
||||
for (auto entry : m_resource_dir.entryInfoList()) {
|
||||
auto filePath = entry.absoluteFilePath();
|
||||
if (auto app = APPLICATION_DYN; app && app->checkQSavePath(filePath)) {
|
||||
continue;
|
||||
}
|
||||
auto newFilePath = FS::getUniqueResourceName(filePath);
|
||||
if (newFilePath != filePath) {
|
||||
FS::move(filePath, newFilePath);
|
||||
|
Reference in New Issue
Block a user