aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-09-20 13:28:33 +0200
committerGitHub <noreply@github.com>2022-09-20 13:28:33 +0200
commitc6bcb6228b421983006d16c93f7cda091dc9679b (patch)
tree34bdf29ef57976517e5ce3c78e0a9dbe28d678cd
parent40c68595d7d5eccd1f264b2dc1e768b3faad6f16 (diff)
parenta24d589845aded0a485ddced900768efaca5328b (diff)
downloadPrismLauncher-c6bcb6228b421983006d16c93f7cda091dc9679b.tar.gz
PrismLauncher-c6bcb6228b421983006d16c93f7cda091dc9679b.tar.bz2
PrismLauncher-c6bcb6228b421983006d16c93f7cda091dc9679b.zip
Merge pull request #1108 from Scrumplex/better_texture_packs
-rw-r--r--launcher/CMakeLists.txt4
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp1
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/TexturePack.cpp64
-rw-r--r--launcher/minecraft/mod/TexturePack.h67
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.cpp78
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.h38
-rw-r--r--launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp155
-rw-r--r--launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h57
-rw-r--r--launcher/ui/pages/instance/TexturePackPage.h12
-rw-r--r--launcher/ui/widgets/InfoFrame.cpp47
-rw-r--r--launcher/ui/widgets/InfoFrame.h4
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/ResourceFolderModel_test.cpp1
-rw-r--r--tests/TexturePackParse_test.cpp71
-rw-r--r--tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt2
-rw-r--r--tests/testdata/TexturePackParse/test_texture_pack_idk.zipbin0 -> 184 bytes
-rw-r--r--tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt1
-rw-r--r--tests/testdata/TexturePackParse/test_texturefolder/pack.txt1
19 files changed, 554 insertions, 54 deletions
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index e44b98eb..848d2e51 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -320,6 +320,8 @@ set(MINECRAFT_SOURCES
minecraft/mod/ResourcePack.cpp
minecraft/mod/ResourcePackFolderModel.h
minecraft/mod/ResourcePackFolderModel.cpp
+ minecraft/mod/TexturePack.h
+ minecraft/mod/TexturePack.cpp
minecraft/mod/TexturePackFolderModel.h
minecraft/mod/TexturePackFolderModel.cpp
minecraft/mod/ShaderPackFolderModel.h
@@ -332,6 +334,8 @@ set(MINECRAFT_SOURCES
minecraft/mod/tasks/LocalModUpdateTask.cpp
minecraft/mod/tasks/LocalResourcePackParseTask.h
minecraft/mod/tasks/LocalResourcePackParseTask.cpp
+ minecraft/mod/tasks/LocalTexturePackParseTask.h
+ minecraft/mod/tasks/LocalTexturePackParseTask.cpp
# Assets
minecraft/AssetsUtils.h
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 9aca686f..66e80f4a 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -51,7 +51,6 @@
ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed)
{
- FS::ensureFolderPathExists(m_dir.absolutePath());
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE };
}
diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp
index 95bd5648..b2356309 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourceFolderModel.cpp
@@ -14,6 +14,8 @@
ResourceFolderModel::ResourceFolderModel(QDir dir, QObject* parent) : QAbstractListModel(parent), m_dir(dir), m_watcher(this)
{
+ FS::ensureFolderPathExists(m_dir.absolutePath());
+
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
diff --git a/launcher/minecraft/mod/TexturePack.cpp b/launcher/minecraft/mod/TexturePack.cpp
new file mode 100644
index 00000000..796eb69d
--- /dev/null
+++ b/launcher/minecraft/mod/TexturePack.cpp
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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 "TexturePack.h"
+
+#include <QDebug>
+#include <QMap>
+#include <QRegularExpression>
+
+#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
+
+void TexturePack::setDescription(QString new_description)
+{
+ QMutexLocker locker(&m_data_lock);
+
+ m_description = new_description;
+}
+
+void TexturePack::setImage(QImage new_image)
+{
+ QMutexLocker locker(&m_data_lock);
+
+ Q_ASSERT(!new_image.isNull());
+
+ if (m_pack_image_cache_key.key.isValid())
+ QPixmapCache::remove(m_pack_image_cache_key.key);
+
+ m_pack_image_cache_key.key = QPixmapCache::insert(QPixmap::fromImage(new_image));
+ m_pack_image_cache_key.was_ever_used = true;
+}
+
+QPixmap TexturePack::image(QSize size)
+{
+ QPixmap cached_image;
+ if (QPixmapCache::find(m_pack_image_cache_key.key, &cached_image)) {
+ if (size.isNull())
+ return cached_image;
+ return cached_image.scaled(size);
+ }
+
+ // No valid image we can get
+ if (!m_pack_image_cache_key.was_ever_used)
+ return {};
+
+ // Imaged got evicted from the cache. Re-process it and retry.
+ TexturePackUtils::process(*this);
+ return image(size);
+}
diff --git a/launcher/minecraft/mod/TexturePack.h b/launcher/minecraft/mod/TexturePack.h
new file mode 100644
index 00000000..6aa5e18e
--- /dev/null
+++ b/launcher/minecraft/mod/TexturePack.h
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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 "Resource.h"
+
+#include <QImage>
+#include <QMutex>
+#include <QPixmap>
+#include <QPixmapCache>
+
+class Version;
+
+class TexturePack : public Resource {
+ Q_OBJECT
+ public:
+ using Ptr = shared_qobject_ptr<Resource>;
+
+ TexturePack(QObject* parent = nullptr) : Resource(parent) {}
+ TexturePack(QFileInfo file_info) : Resource(file_info) {}
+
+ /** Gets the description of the texture pack. */
+ [[nodiscard]] QString description() const { return m_description; }
+
+ /** Gets the image of the texture pack, converted to a QPixmap for drawing, and scaled to size. */
+ [[nodiscard]] QPixmap image(QSize size);
+
+ /** Thread-safe. */
+ void setDescription(QString new_description);
+
+ /** Thread-safe. */
+ void setImage(QImage new_image);
+
+ protected:
+ mutable QMutex m_data_lock;
+
+ /** The texture pack's description, as defined in the pack.txt file.
+ */
+ QString m_description;
+
+ /** The texture pack's image file cache key, for access in the QPixmapCache global instance.
+ *
+ * The 'was_ever_used' state simply identifies whether the key was never inserted on the cache (true),
+ * so as to tell whether a cache entry is inexistent or if it was just evicted from the cache.
+ */
+ struct {
+ QPixmapCache::Key key;
+ bool was_ever_used = false;
+ } m_pack_image_cache_key;
+};
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp
index 2c7c945b..561f6202 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.cpp
+++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp
@@ -1,38 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
-* PolyMC - Minecraft Launcher
-* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
-*
-* 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/>.
-*
-* This file incorporates work covered by the following copyright and
-* permission notice:
-*
-* Copyright 2013-2021 MultiMC Contributors
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include "TexturePackFolderModel.h"
+#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
+#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
+
TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}
+
+Task* TexturePackFolderModel::createUpdateTask()
+{
+ return new BasicFolderLoadTask(m_dir, [](QFileInfo const& entry) { return new TexturePack(entry); });
+}
+
+Task* TexturePackFolderModel::createParseTask(Resource& resource)
+{
+ return new LocalTexturePackParseTask(m_next_resolution_ticket, static_cast<TexturePack&>(resource));
+}
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.h b/launcher/minecraft/mod/TexturePackFolderModel.h
index 69e98661..261f83b4 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.h
+++ b/launcher/minecraft/mod/TexturePackFolderModel.h
@@ -1,3 +1,39 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#pragma once
#include "ResourceFolderModel.h"
@@ -8,4 +44,6 @@ class TexturePackFolderModel : public ResourceFolderModel
public:
explicit TexturePackFolderModel(const QString &dir);
+ [[nodiscard]] Task* createUpdateTask() override;
+ [[nodiscard]] Task* createParseTask(Resource&) override;
};
diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp
new file mode 100644
index 00000000..bf1e308f
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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 "LocalTexturePackParseTask.h"
+
+#include "FileSystem.h"
+
+#include <quazip/quazip.h>
+#include <quazip/quazipfile.h>
+
+#include <QCryptographicHash>
+
+namespace TexturePackUtils {
+
+bool process(TexturePack& pack)
+{
+ switch (pack.type()) {
+ case ResourceType::FOLDER:
+ TexturePackUtils::processFolder(pack);
+ return true;
+ case ResourceType::ZIPFILE:
+ TexturePackUtils::processZIP(pack);
+ return true;
+ default:
+ qWarning() << "Invalid type for resource pack parse task!";
+ return false;
+ }
+}
+
+void processFolder(TexturePack& pack)
+{
+ Q_ASSERT(pack.type() == ResourceType::FOLDER);
+
+ QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.txt"));
+ if (mcmeta_file_info.isFile()) {
+ QFile mcmeta_file(mcmeta_file_info.filePath());
+ if (!mcmeta_file.open(QIODevice::ReadOnly))
+ return;
+
+ auto data = mcmeta_file.readAll();
+
+ TexturePackUtils::processPackTXT(pack, std::move(data));
+
+ mcmeta_file.close();
+ }
+
+ QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png"));
+ if (image_file_info.isFile()) {
+ QFile mcmeta_file(image_file_info.filePath());
+ if (!mcmeta_file.open(QIODevice::ReadOnly))
+ return;
+
+ auto data = mcmeta_file.readAll();
+
+ TexturePackUtils::processPackPNG(pack, std::move(data));
+
+ mcmeta_file.close();
+ }
+}
+
+void processZIP(TexturePack& pack)
+{
+ Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
+
+ QuaZip zip(pack.fileinfo().filePath());
+ if (!zip.open(QuaZip::mdUnzip))
+ return;
+
+ QuaZipFile file(&zip);
+
+ if (zip.setCurrentFile("pack.txt")) {
+ if (!file.open(QIODevice::ReadOnly)) {
+ qCritical() << "Failed to open file in zip.";
+ zip.close();
+ return;
+ }
+
+ auto data = file.readAll();
+
+ TexturePackUtils::processPackTXT(pack, std::move(data));
+
+ file.close();
+ }
+
+ if (zip.setCurrentFile("pack.png")) {
+ if (!file.open(QIODevice::ReadOnly)) {
+ qCritical() << "Failed to open file in zip.";
+ zip.close();
+ return;
+ }
+
+ auto data = file.readAll();
+
+ TexturePackUtils::processPackPNG(pack, std::move(data));
+
+ file.close();
+ }
+
+ zip.close();
+}
+
+void processPackTXT(TexturePack& pack, QByteArray&& raw_data)
+{
+ pack.setDescription(QString(raw_data));
+}
+
+void processPackPNG(TexturePack& pack, QByteArray&& raw_data)
+{
+ auto img = QImage::fromData(raw_data);
+ if (!img.isNull()) {
+ pack.setImage(img);
+ } else {
+ qWarning() << "Failed to parse pack.png.";
+ }
+}
+} // namespace TexturePackUtils
+
+LocalTexturePackParseTask::LocalTexturePackParseTask(int token, TexturePack& rp)
+ : Task(nullptr, false), m_token(token), m_texture_pack(rp)
+{}
+
+bool LocalTexturePackParseTask::abort()
+{
+ m_aborted = true;
+ return true;
+}
+
+void LocalTexturePackParseTask::executeTask()
+{
+ Q_ASSERT(m_texture_pack.valid());
+
+ if (!TexturePackUtils::process(m_texture_pack))
+ return;
+
+ if (m_aborted)
+ emitAborted();
+ else
+ emitSucceeded();
+}
diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h
new file mode 100644
index 00000000..cb0e404a
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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 <QObject>
+
+#include "minecraft/mod/TexturePack.h"
+
+#include "tasks/Task.h"
+
+namespace TexturePackUtils {
+bool process(TexturePack& pack);
+
+void processZIP(TexturePack& pack);
+void processFolder(TexturePack& pack);
+
+void processPackTXT(TexturePack& pack, QByteArray&& raw_data);
+void processPackPNG(TexturePack& pack, QByteArray&& raw_data);
+} // namespace TexturePackUtils
+
+class LocalTexturePackParseTask : public Task {
+ Q_OBJECT
+ public:
+ LocalTexturePackParseTask(int token, TexturePack& rp);
+
+ [[nodiscard]] bool canAbort() const override { return true; }
+ bool abort() override;
+
+ void executeTask() override;
+
+ [[nodiscard]] int token() const { return m_token; }
+
+ private:
+ int m_token;
+
+ TexturePack& m_texture_pack;
+
+ bool m_aborted = false;
+};
diff --git a/launcher/ui/pages/instance/TexturePackPage.h b/launcher/ui/pages/instance/TexturePackPage.h
index fa219eda..69b836ca 100644
--- a/launcher/ui/pages/instance/TexturePackPage.h
+++ b/launcher/ui/pages/instance/TexturePackPage.h
@@ -39,6 +39,7 @@
#include "ui_ExternalResourcesPage.h"
#include "minecraft/mod/TexturePackFolderModel.h"
+#include "minecraft/mod/TexturePack.h"
class TexturePackPage : public ExternalResourcesPage
{
@@ -60,4 +61,15 @@ public:
{
return m_instance->traits().contains("texturepacks");
}
+
+ public slots:
+ bool onSelectionChanged(const QModelIndex& current, const QModelIndex& previous) override
+ {
+ auto sourceCurrent = m_filterModel->mapToSource(current);
+ int row = sourceCurrent.row();
+ auto& rp = static_cast<TexturePack&>(m_model->at(row));
+ ui->frame->updateWithTexturePack(rp);
+
+ return true;
+ }
};
diff --git a/launcher/ui/widgets/InfoFrame.cpp b/launcher/ui/widgets/InfoFrame.cpp
index 9e0553f8..f78dbe16 100644
--- a/launcher/ui/widgets/InfoFrame.cpp
+++ b/launcher/ui/widgets/InfoFrame.cpp
@@ -105,10 +105,7 @@ static const QMap<QChar, QString> s_value_to_color = {
{'f', "#FFFFFF"}
};
-void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
-{
- setName(resource_pack.name());
-
+QString InfoFrame::renderColorCodes(QString input) {
// We have to manually set the colors for use.
//
// A color is set using §x, with x = a hex number from 0 to f.
@@ -119,39 +116,49 @@ void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
// TODO: Make the same logic for font formatting too.
// TODO: Wrap links inside <a> tags
- auto description = resource_pack.description();
-
- QString description_parsed("<html>");
+ QString html("<html>");
bool in_div = false;
- auto desc_it = description.constBegin();
- while (desc_it != description.constEnd()) {
- if (*desc_it == u'§') {
+ auto it = input.constBegin();
+ while (it != input.constEnd()) {
+ if (*it == u'§') {
if (in_div)
- description_parsed += "</span>";
+ html += "</span>";
- auto const& num = *(++desc_it);
- description_parsed += QString("<span style=\"color: %1;\">").arg(s_value_to_color.constFind(num).value());
+ auto const& num = *(++it);
+ html += QString("<span style=\"color: %1;\">").arg(s_value_to_color.constFind(num).value());
in_div = true;
- desc_it++;
+ it++;
}
- description_parsed += *desc_it;
- desc_it++;
+ html += *it;
+ it++;
}
if (in_div)
- description_parsed += "</span>";
- description_parsed += "</html>";
+ html += "</span>";
+ html += "</html>";
- description_parsed.replace("\n", "<br>");
+ html.replace("\n", "<br>");
+ return html;
+}
- setDescription(description_parsed);
+void InfoFrame::updateWithResourcePack(ResourcePack& resource_pack)
+{
+ setName(resource_pack.name());
+ setDescription(renderColorCodes(resource_pack.description()));
setImage(resource_pack.image({64, 64}));
}
+void InfoFrame::updateWithTexturePack(TexturePack& texture_pack)
+{
+ setName(texture_pack.name());
+ setDescription(renderColorCodes(texture_pack.description()));
+ setImage(texture_pack.image({64, 64}));
+}
+
void InfoFrame::clear()
{
setName();
diff --git a/launcher/ui/widgets/InfoFrame.h b/launcher/ui/widgets/InfoFrame.h
index 70d15b1e..84523e28 100644
--- a/launcher/ui/widgets/InfoFrame.h
+++ b/launcher/ui/widgets/InfoFrame.h
@@ -19,6 +19,7 @@
#include "minecraft/mod/Mod.h"
#include "minecraft/mod/ResourcePack.h"
+#include "minecraft/mod/TexturePack.h"
namespace Ui
{
@@ -41,6 +42,9 @@ class InfoFrame : public QFrame {
void updateWithMod(Mod const& m);
void updateWithResource(Resource const& resource);
void updateWithResourcePack(ResourcePack& rp);
+ void updateWithTexturePack(TexturePack& tp);
+
+ static QString renderColorCodes(QString input);
public slots:
void descriptionEllipsisHandler(QString link);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 1265d7a5..630f1200 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,6 +24,9 @@ ecm_add_test(ResourceFolderModel_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_V
ecm_add_test(ResourcePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
TEST_NAME ResourcePackParse)
+ecm_add_test(TexturePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
+ TEST_NAME TexturePackParse)
+
ecm_add_test(ParseUtils_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
TEST_NAME ParseUtils)
diff --git a/tests/ResourceFolderModel_test.cpp b/tests/ResourceFolderModel_test.cpp
index 3f0f3ba1..e38b8e93 100644
--- a/tests/ResourceFolderModel_test.cpp
+++ b/tests/ResourceFolderModel_test.cpp
@@ -146,7 +146,6 @@ slots:
for (auto mod : model.allMods())
qDebug() << mod->name();
- // FIXME: It considers every file in the directory as a mod, but we should probably filter that out somehow.
QCOMPARE(model.size(), 4);
model.stopWatching();
diff --git a/tests/TexturePackParse_test.cpp b/tests/TexturePackParse_test.cpp
new file mode 100644
index 00000000..0771f79f
--- /dev/null
+++ b/tests/TexturePackParse_test.cpp
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * 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 <QTest>
+#include <QTimer>
+
+#include "FileSystem.h"
+
+#include "minecraft/mod/TexturePack.h"
+#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
+
+class TexturePackParseTest : public QObject {
+ Q_OBJECT
+
+ private slots:
+ void test_parseZIP()
+ {
+ QString source = QFINDTESTDATA("testdata/TexturePackParse");
+
+ QString zip_rp = FS::PathCombine(source, "test_texture_pack_idk.zip");
+ TexturePack pack { QFileInfo(zip_rp) };
+
+ TexturePackUtils::processZIP(pack);
+
+ QVERIFY(pack.description() == "joe biden, wake up");
+ }
+
+ void test_parseFolder()
+ {
+ QString source = QFINDTESTDATA("testdata/TexturePackParse");
+
+ QString folder_rp = FS::PathCombine(source, "test_texturefolder");
+ TexturePack pack { QFileInfo(folder_rp) };
+
+ TexturePackUtils::processFolder(pack);
+
+ QVERIFY(pack.description() == "Some texture pack surely");
+ }
+
+ void test_parseFolder2()
+ {
+ QString source = QFINDTESTDATA("testdata/TexturePackParse");
+
+ QString folder_rp = FS::PathCombine(source, "another_test_texturefolder");
+ TexturePack pack { QFileInfo(folder_rp) };
+
+ TexturePackUtils::process(pack);
+
+ QVERIFY(pack.description() == "quieres\nfor real");
+ }
+};
+
+QTEST_GUILESS_MAIN(TexturePackParseTest)
+
+#include "TexturePackParse_test.moc"
diff --git a/tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt b/tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt
new file mode 100644
index 00000000..bbc0d271
--- /dev/null
+++ b/tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt
@@ -0,0 +1,2 @@
+quieres
+for real \ No newline at end of file
diff --git a/tests/testdata/TexturePackParse/test_texture_pack_idk.zip b/tests/testdata/TexturePackParse/test_texture_pack_idk.zip
new file mode 100644
index 00000000..fb4d3370
--- /dev/null
+++ b/tests/testdata/TexturePackParse/test_texture_pack_idk.zip
Binary files differ
diff --git a/tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt b/tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt
new file mode 100644
index 00000000..8d1c8b69
--- /dev/null
+++ b/tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt
@@ -0,0 +1 @@
+
diff --git a/tests/testdata/TexturePackParse/test_texturefolder/pack.txt b/tests/testdata/TexturePackParse/test_texturefolder/pack.txt
new file mode 100644
index 00000000..f6260725
--- /dev/null
+++ b/tests/testdata/TexturePackParse/test_texturefolder/pack.txt
@@ -0,0 +1 @@
+Some texture pack surely \ No newline at end of file