Merge branch 'PrismLauncher:develop' into instance-accounts
This commit is contained in:
commit
b2f48eaeb8
9
.github/workflows/build.yml
vendored
9
.github/workflows/build.yml
vendored
@ -61,7 +61,7 @@ jobs:
|
||||
qt_ver: 6
|
||||
qt_host: windows
|
||||
qt_arch: ''
|
||||
qt_version: '6.4.0'
|
||||
qt_version: '6.4.2'
|
||||
qt_modules: 'qt5compat qtimageformats'
|
||||
qt_tools: ''
|
||||
|
||||
@ -73,7 +73,7 @@ jobs:
|
||||
qt_ver: 6
|
||||
qt_host: windows
|
||||
qt_arch: 'win64_msvc2019_arm64'
|
||||
qt_version: '6.4.0'
|
||||
qt_version: '6.4.2'
|
||||
qt_modules: 'qt5compat qtimageformats'
|
||||
qt_tools: ''
|
||||
|
||||
@ -105,6 +105,7 @@ jobs:
|
||||
INSTALL_APPIMAGE_DIR: "install-appdir"
|
||||
BUILD_DIR: "build"
|
||||
CCACHE_VAR: ""
|
||||
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
|
||||
|
||||
steps:
|
||||
##
|
||||
@ -143,7 +144,7 @@ jobs:
|
||||
|
||||
- name: Setup ccache
|
||||
if: (runner.os != 'Windows' || matrix.msystem == '') && inputs.build_type == 'Debug'
|
||||
uses: hendrikmuhs/ccache-action@v1.2.5
|
||||
uses: hendrikmuhs/ccache-action@v1.2.6
|
||||
with:
|
||||
key: ${{ matrix.os }}-qt${{ matrix.qt_ver }}-${{ matrix.architecture }}
|
||||
|
||||
@ -165,7 +166,7 @@ jobs:
|
||||
|
||||
- name: Retrieve ccache cache (Windows MinGW-w64)
|
||||
if: runner.os == 'Windows' && matrix.msystem != '' && inputs.build_type == 'Debug'
|
||||
uses: actions/cache@v3.2.2
|
||||
uses: actions/cache@v3.2.3
|
||||
with:
|
||||
path: '${{ github.workspace }}\.ccache'
|
||||
key: ${{ matrix.os }}-mingw-w64
|
||||
|
@ -62,15 +62,11 @@
|
||||
#include "ui/pages/global/APIPage.h"
|
||||
#include "ui/pages/global/CustomCommandsPage.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "ui/WinDarkmode.h"
|
||||
#include <versionhelpers.h>
|
||||
#endif
|
||||
|
||||
#include "ui/setupwizard/SetupWizard.h"
|
||||
#include "ui/setupwizard/LanguageWizardPage.h"
|
||||
#include "ui/setupwizard/JavaWizardPage.h"
|
||||
#include "ui/setupwizard/PasteWizardPage.h"
|
||||
#include "ui/setupwizard/ThemeWizardPage.h"
|
||||
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
|
||||
@ -502,7 +498,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
|
||||
// Theming
|
||||
m_settings->registerSetting("IconTheme", QString("pe_colored"));
|
||||
m_settings->registerSetting("ApplicationTheme", QString("system"));
|
||||
m_settings->registerSetting("ApplicationTheme", QString());
|
||||
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
|
||||
|
||||
// Remembered state
|
||||
@ -851,10 +847,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
});
|
||||
|
||||
{
|
||||
setIconTheme(settings()->get("IconTheme").toString());
|
||||
qDebug() << "<> Icon theme set.";
|
||||
setApplicationTheme(settings()->get("ApplicationTheme").toString(), true);
|
||||
qDebug() << "<> Application theme set.";
|
||||
applyCurrentlySelectedTheme();
|
||||
}
|
||||
|
||||
updateCapabilities();
|
||||
@ -897,7 +890,8 @@ bool Application::createSetupWizard()
|
||||
return false;
|
||||
}();
|
||||
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
|
||||
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired;
|
||||
bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
|
||||
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
|
||||
|
||||
if(wizardRequired)
|
||||
{
|
||||
@ -916,6 +910,12 @@ bool Application::createSetupWizard()
|
||||
{
|
||||
m_setupWizard->addPage(new PasteWizardPage(m_setupWizard));
|
||||
}
|
||||
|
||||
if (themeInterventionRequired)
|
||||
{
|
||||
settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
|
||||
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
|
||||
}
|
||||
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
|
||||
m_setupWizard->show();
|
||||
return true;
|
||||
@ -1123,9 +1123,14 @@ QList<ITheme*> Application::getValidApplicationThemes()
|
||||
return m_themeManager->getValidApplicationThemes();
|
||||
}
|
||||
|
||||
void Application::setApplicationTheme(const QString& name, bool initial)
|
||||
void Application::applyCurrentlySelectedTheme()
|
||||
{
|
||||
m_themeManager->setApplicationTheme(name, initial);
|
||||
m_themeManager->applyCurrentlySelectedTheme();
|
||||
}
|
||||
|
||||
void Application::setApplicationTheme(const QString& name)
|
||||
{
|
||||
m_themeManager->setApplicationTheme(name);
|
||||
}
|
||||
|
||||
void Application::setIconTheme(const QString& name)
|
||||
@ -1353,16 +1358,7 @@ MainWindow* Application::showMainWindow(bool minimized)
|
||||
m_mainWindow = new MainWindow();
|
||||
m_mainWindow->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowState").toByteArray()));
|
||||
m_mainWindow->restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowGeometry").toByteArray()));
|
||||
#ifdef Q_OS_WIN
|
||||
if (IsWindows10OrGreater())
|
||||
{
|
||||
if (QString::compare(settings()->get("ApplicationTheme").toString(), "dark") == 0) {
|
||||
WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true);
|
||||
} else {
|
||||
WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(minimized)
|
||||
{
|
||||
m_mainWindow->showMinimized();
|
||||
|
@ -120,9 +120,11 @@ public:
|
||||
|
||||
void setIconTheme(const QString& name);
|
||||
|
||||
void applyCurrentlySelectedTheme();
|
||||
|
||||
QList<ITheme*> getValidApplicationThemes();
|
||||
|
||||
void setApplicationTheme(const QString& name, bool initial);
|
||||
void setApplicationTheme(const QString& name);
|
||||
|
||||
shared_qobject_ptr<UpdateChecker> updateChecker() {
|
||||
return m_updateChecker;
|
||||
|
@ -331,12 +331,18 @@ set(MINECRAFT_SOURCES
|
||||
minecraft/mod/Resource.cpp
|
||||
minecraft/mod/ResourceFolderModel.h
|
||||
minecraft/mod/ResourceFolderModel.cpp
|
||||
minecraft/mod/DataPack.h
|
||||
minecraft/mod/DataPack.cpp
|
||||
minecraft/mod/ResourcePack.h
|
||||
minecraft/mod/ResourcePack.cpp
|
||||
minecraft/mod/ResourcePackFolderModel.h
|
||||
minecraft/mod/ResourcePackFolderModel.cpp
|
||||
minecraft/mod/TexturePack.h
|
||||
minecraft/mod/TexturePack.cpp
|
||||
minecraft/mod/ShaderPack.h
|
||||
minecraft/mod/ShaderPack.cpp
|
||||
minecraft/mod/WorldSave.h
|
||||
minecraft/mod/WorldSave.cpp
|
||||
minecraft/mod/TexturePackFolderModel.h
|
||||
minecraft/mod/TexturePackFolderModel.cpp
|
||||
minecraft/mod/ShaderPackFolderModel.h
|
||||
@ -347,10 +353,18 @@ set(MINECRAFT_SOURCES
|
||||
minecraft/mod/tasks/LocalModParseTask.cpp
|
||||
minecraft/mod/tasks/LocalModUpdateTask.h
|
||||
minecraft/mod/tasks/LocalModUpdateTask.cpp
|
||||
minecraft/mod/tasks/LocalDataPackParseTask.h
|
||||
minecraft/mod/tasks/LocalDataPackParseTask.cpp
|
||||
minecraft/mod/tasks/LocalResourcePackParseTask.h
|
||||
minecraft/mod/tasks/LocalResourcePackParseTask.cpp
|
||||
minecraft/mod/tasks/LocalTexturePackParseTask.h
|
||||
minecraft/mod/tasks/LocalTexturePackParseTask.cpp
|
||||
minecraft/mod/tasks/LocalShaderPackParseTask.h
|
||||
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
|
||||
@ -669,6 +683,8 @@ SET(LAUNCHER_SOURCES
|
||||
ui/setupwizard/LanguageWizardPage.h
|
||||
ui/setupwizard/PasteWizardPage.cpp
|
||||
ui/setupwizard/PasteWizardPage.h
|
||||
ui/setupwizard/ThemeWizardPage.cpp
|
||||
ui/setupwizard/ThemeWizardPage.h
|
||||
|
||||
# GUI - themes
|
||||
ui/themes/FusionTheme.cpp
|
||||
@ -908,6 +924,8 @@ SET(LAUNCHER_SOURCES
|
||||
ui/widgets/ProgressWidget.cpp
|
||||
ui/widgets/WideBar.h
|
||||
ui/widgets/WideBar.cpp
|
||||
ui/widgets/ThemeCustomizationWidget.h
|
||||
ui/widgets/ThemeCustomizationWidget.cpp
|
||||
|
||||
# GUI - instance group view
|
||||
ui/instanceview/InstanceProxyModel.cpp
|
||||
@ -923,18 +941,9 @@ SET(LAUNCHER_SOURCES
|
||||
ui/instanceview/VisualGroup.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LAUNCHER_SOURCES
|
||||
${LAUNCHER_SOURCES}
|
||||
|
||||
# GUI - dark titlebar for Windows 10/11
|
||||
ui/WinDarkmode.h
|
||||
ui/WinDarkmode.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
qt_wrap_ui(LAUNCHER_UI
|
||||
ui/setupwizard/PasteWizardPage.ui
|
||||
ui/setupwizard/ThemeWizardPage.ui
|
||||
ui/pages/global/AccountListPage.ui
|
||||
ui/pages/global/JavaPage.ui
|
||||
ui/pages/global/LauncherPage.ui
|
||||
@ -967,6 +976,7 @@ qt_wrap_ui(LAUNCHER_UI
|
||||
ui/widgets/CustomCommands.ui
|
||||
ui/widgets/InfoFrame.ui
|
||||
ui/widgets/ModFilterWidget.ui
|
||||
ui/widgets/ThemeCustomizationWidget.ui
|
||||
ui/dialogs/CopyInstanceDialog.ui
|
||||
ui/dialogs/ProfileSetupDialog.ui
|
||||
ui/dialogs/ProgressDialog.ui
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include <shlobj.h>
|
||||
#include <shobjidl.h>
|
||||
#include <sys/utime.h>
|
||||
#include <versionhelpers.h>
|
||||
#include <windows.h>
|
||||
#include <winnls.h>
|
||||
#include <string>
|
||||
@ -214,6 +215,22 @@ bool copy::operator()(const QString& offset, bool dryRun)
|
||||
return err.value() == 0;
|
||||
}
|
||||
|
||||
bool move(const QString& source, const QString& dest)
|
||||
{
|
||||
std::error_code err;
|
||||
|
||||
ensureFilePathExists(dest);
|
||||
fs::rename(StringUtils::toStdString(source), StringUtils::toStdString(dest), err);
|
||||
|
||||
if (err) {
|
||||
qWarning() << "Failed to move file:" << QString::fromStdString(err.message());
|
||||
qDebug() << "Source file:" << source;
|
||||
qDebug() << "Destination file:" << dest;
|
||||
}
|
||||
|
||||
return err.value() == 0;
|
||||
}
|
||||
|
||||
bool deletePath(QString path)
|
||||
{
|
||||
std::error_code err;
|
||||
@ -235,6 +252,10 @@ bool trash(QString path, QString *pathInTrash)
|
||||
// FIXME: Figure out trash in Flatpak. Qt seemingly doesn't use the Trash portal
|
||||
if (DesktopServices::isFlatpak())
|
||||
return false;
|
||||
#if defined Q_OS_WIN32
|
||||
if (IsWindowsServer())
|
||||
return false;
|
||||
#endif
|
||||
return QFile::moveToTrash(path, pathInTrash);
|
||||
#endif
|
||||
}
|
||||
|
@ -122,6 +122,14 @@ class copy : public QObject {
|
||||
int m_copied;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief moves a file by renaming it
|
||||
* @param source source file path
|
||||
* @param dest destination filepath
|
||||
*
|
||||
*/
|
||||
bool move(const QString& source, const QString& dest);
|
||||
|
||||
/**
|
||||
* Delete a folder recursively
|
||||
*/
|
||||
|
108
launcher/minecraft/mod/DataPack.cpp
Normal file
108
launcher/minecraft/mod/DataPack.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
// 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 "DataPack.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "Version.h"
|
||||
|
||||
// Values taken from:
|
||||
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_data_pack#%22pack_format%22
|
||||
static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = {
|
||||
{ 4, { Version("1.13"), Version("1.14.4") } }, { 5, { Version("1.15"), Version("1.16.1") } },
|
||||
{ 6, { Version("1.16.2"), Version("1.16.5") } }, { 7, { Version("1.17"), Version("1.17.1") } },
|
||||
{ 8, { Version("1.18"), Version("1.18.1") } }, { 9, { Version("1.18.2"), Version("1.18.2") } },
|
||||
{ 10, { Version("1.19"), Version("1.19.3") } },
|
||||
};
|
||||
|
||||
void DataPack::setPackFormat(int new_format_id)
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
if (!s_pack_format_versions.contains(new_format_id)) {
|
||||
qWarning() << "Pack format '" << new_format_id << "' is not a recognized data pack id!";
|
||||
}
|
||||
|
||||
m_pack_format = new_format_id;
|
||||
}
|
||||
|
||||
void DataPack::setDescription(QString new_description)
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
m_description = new_description;
|
||||
}
|
||||
|
||||
std::pair<Version, Version> DataPack::compatibleVersions() const
|
||||
{
|
||||
if (!s_pack_format_versions.contains(m_pack_format)) {
|
||||
return { {}, {} };
|
||||
}
|
||||
|
||||
return s_pack_format_versions.constFind(m_pack_format).value();
|
||||
}
|
||||
|
||||
std::pair<int, bool> DataPack::compare(const Resource& other, SortType type) const
|
||||
{
|
||||
auto const& cast_other = static_cast<DataPack const&>(other);
|
||||
|
||||
switch (type) {
|
||||
default: {
|
||||
auto res = Resource::compare(other, type);
|
||||
if (res.first != 0)
|
||||
return res;
|
||||
}
|
||||
case SortType::PACK_FORMAT: {
|
||||
auto this_ver = packFormat();
|
||||
auto other_ver = cast_other.packFormat();
|
||||
|
||||
if (this_ver > other_ver)
|
||||
return { 1, type == SortType::PACK_FORMAT };
|
||||
if (this_ver < other_ver)
|
||||
return { -1, type == SortType::PACK_FORMAT };
|
||||
}
|
||||
}
|
||||
return { 0, false };
|
||||
}
|
||||
|
||||
bool DataPack::applyFilter(QRegularExpression filter) const
|
||||
{
|
||||
if (filter.match(description()).hasMatch())
|
||||
return true;
|
||||
|
||||
if (filter.match(QString::number(packFormat())).hasMatch())
|
||||
return true;
|
||||
|
||||
if (filter.match(compatibleVersions().first.toString()).hasMatch())
|
||||
return true;
|
||||
if (filter.match(compatibleVersions().second.toString()).hasMatch())
|
||||
return true;
|
||||
|
||||
return Resource::applyFilter(filter);
|
||||
}
|
||||
|
||||
bool DataPack::valid() const
|
||||
{
|
||||
return m_pack_format != 0;
|
||||
}
|
73
launcher/minecraft/mod/DataPack.h
Normal file
73
launcher/minecraft/mod/DataPack.h
Normal file
@ -0,0 +1,73 @@
|
||||
// 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 "Resource.h"
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
class Version;
|
||||
|
||||
/* TODO:
|
||||
*
|
||||
* Store localized descriptions
|
||||
* */
|
||||
|
||||
class DataPack : public Resource {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<Resource>;
|
||||
|
||||
DataPack(QObject* parent = nullptr) : Resource(parent) {}
|
||||
DataPack(QFileInfo file_info) : Resource(file_info) {}
|
||||
|
||||
/** Gets the numerical ID of the pack format. */
|
||||
[[nodiscard]] int packFormat() const { return m_pack_format; }
|
||||
/** Gets, respectively, the lower and upper versions supported by the set pack format. */
|
||||
[[nodiscard]] std::pair<Version, Version> compatibleVersions() const;
|
||||
|
||||
/** Gets the description of the data pack. */
|
||||
[[nodiscard]] QString description() const { return m_description; }
|
||||
|
||||
/** Thread-safe. */
|
||||
void setPackFormat(int new_format_id);
|
||||
|
||||
/** Thread-safe. */
|
||||
void setDescription(QString new_description);
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
|
||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||
|
||||
protected:
|
||||
mutable QMutex m_data_lock;
|
||||
|
||||
/* The 'version' of a data pack, as defined in the pack.mcmeta file.
|
||||
* See https://minecraft.fandom.com/wiki/Data_pack#pack.mcmeta
|
||||
*/
|
||||
int m_pack_format = 0;
|
||||
|
||||
/** The data pack's description, as defined in the pack.mcmeta file.
|
||||
*/
|
||||
QString m_description;
|
||||
};
|
@ -43,6 +43,7 @@
|
||||
|
||||
#include "MetadataHandler.h"
|
||||
#include "Version.h"
|
||||
#include "minecraft/mod/ModDetails.h"
|
||||
|
||||
static ModPlatform::ProviderCapabilities ProviderCaps;
|
||||
|
||||
@ -70,6 +71,10 @@ void Mod::setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
|
||||
m_local_details.metadata = metadata;
|
||||
}
|
||||
|
||||
void Mod::setDetails(const ModDetails& details) {
|
||||
m_local_details = details;
|
||||
}
|
||||
|
||||
std::pair<int, bool> Mod::compare(const Resource& other, SortType type) const
|
||||
{
|
||||
auto cast_other = dynamic_cast<Mod const*>(&other);
|
||||
@ -204,3 +209,8 @@ auto Mod::provider() const -> std::optional<QString>
|
||||
return ProviderCaps.readableName(metadata()->provider);
|
||||
return {};
|
||||
}
|
||||
|
||||
bool Mod::valid() const
|
||||
{
|
||||
return !m_local_details.mod_id.isEmpty();
|
||||
}
|
||||
|
@ -71,6 +71,9 @@ public:
|
||||
void setStatus(ModStatus status);
|
||||
void setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata);
|
||||
void setMetadata(const Metadata::ModStruct& metadata) { setMetadata(std::make_shared<Metadata::ModStruct>(metadata)); }
|
||||
void setDetails(const ModDetails& details);
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
|
||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||
|
@ -81,7 +81,7 @@ struct ModDetails
|
||||
ModDetails() = default;
|
||||
|
||||
/** Metadata should be handled manually to properly set the mod status. */
|
||||
ModDetails(ModDetails& other)
|
||||
ModDetails(const ModDetails& other)
|
||||
: mod_id(other.mod_id)
|
||||
, name(other.name)
|
||||
, version(other.version)
|
||||
@ -92,7 +92,7 @@ struct ModDetails
|
||||
, status(other.status)
|
||||
{}
|
||||
|
||||
ModDetails& operator=(ModDetails& other)
|
||||
ModDetails& operator=(const ModDetails& other)
|
||||
{
|
||||
this->mod_id = other.mod_id;
|
||||
this->name = other.name;
|
||||
@ -106,7 +106,7 @@ struct ModDetails
|
||||
return *this;
|
||||
}
|
||||
|
||||
ModDetails& operator=(ModDetails&& other)
|
||||
ModDetails& operator=(const ModDetails&& other)
|
||||
{
|
||||
this->mod_id = other.mod_id;
|
||||
this->name = other.name;
|
||||
|
@ -13,11 +13,12 @@
|
||||
// Values taken from:
|
||||
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
|
||||
static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = {
|
||||
{ 1, { Version("1.6.1"), Version("1.8.9") } }, { 2, { Version("1.9"), Version("1.10.2") } },
|
||||
{ 3, { Version("1.11"), Version("1.12.2") } }, { 4, { Version("1.13"), Version("1.14.4") } },
|
||||
{ 5, { Version("1.15"), Version("1.16.1") } }, { 6, { Version("1.16.2"), Version("1.16.5") } },
|
||||
{ 7, { Version("1.17"), Version("1.17.1") } }, { 8, { Version("1.18"), Version("1.18.2") } },
|
||||
{ 9, { Version("1.19"), Version("1.19.2") } }, { 11, { Version("1.19.3"), Version("1.19.3") } },
|
||||
{ 1, { Version("1.6.1"), Version("1.8.9") } }, { 2, { Version("1.9"), Version("1.10.2") } },
|
||||
{ 3, { Version("1.11"), Version("1.12.2") } }, { 4, { Version("1.13"), Version("1.14.4") } },
|
||||
{ 5, { Version("1.15"), Version("1.16.1") } }, { 6, { Version("1.16.2"), Version("1.16.5") } },
|
||||
{ 7, { Version("1.17"), Version("1.17.1") } }, { 8, { Version("1.18"), Version("1.18.2") } },
|
||||
{ 9, { Version("1.19"), Version("1.19.2") } }, { 11, { Version("22w42a"), Version("22w44a") } },
|
||||
{ 12, { Version("1.19.3"), Version("1.19.3") } },
|
||||
};
|
||||
|
||||
void ResourcePack::setPackFormat(int new_format_id)
|
||||
@ -25,7 +26,7 @@ void ResourcePack::setPackFormat(int new_format_id)
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
if (!s_pack_format_versions.contains(new_format_id)) {
|
||||
qWarning() << "Pack format '%1' is not a recognized resource pack id!";
|
||||
qWarning() << "Pack format '" << new_format_id << "' is not a recognized resource pack id!";
|
||||
}
|
||||
|
||||
m_pack_format = new_format_id;
|
||||
|
37
launcher/minecraft/mod/ShaderPack.cpp
Normal file
37
launcher/minecraft/mod/ShaderPack.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
// 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 "ShaderPack.h"
|
||||
|
||||
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h"
|
||||
|
||||
void ShaderPack::setPackFormat(ShaderPackFormat new_format)
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
m_pack_format = new_format;
|
||||
}
|
||||
|
||||
bool ShaderPack::valid() const
|
||||
{
|
||||
return m_pack_format != ShaderPackFormat::INVALID;
|
||||
}
|
62
launcher/minecraft/mod/ShaderPack.h
Normal file
62
launcher/minecraft/mod/ShaderPack.h
Normal file
@ -0,0 +1,62 @@
|
||||
// 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 "Resource.h"
|
||||
|
||||
/* Info:
|
||||
* Currently For Optifine / Iris shader packs,
|
||||
* could be expanded to support others should they exist?
|
||||
*
|
||||
* This class and enum are mostly here as placeholders for validating
|
||||
* that a shaderpack exists and is in the right format,
|
||||
* namely that they contain a folder named 'shaders'.
|
||||
*
|
||||
* In the technical sense it would be possible to parse files like `shaders/shaders.properties`
|
||||
* to get information like the available profiles but this is not all that useful without more knowledge of the
|
||||
* shader mod used to be able to change settings.
|
||||
*/
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
enum class ShaderPackFormat { VALID, INVALID };
|
||||
|
||||
class ShaderPack : public Resource {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<Resource>;
|
||||
|
||||
[[nodiscard]] ShaderPackFormat packFormat() const { return m_pack_format; }
|
||||
|
||||
ShaderPack(QObject* parent = nullptr) : Resource(parent) {}
|
||||
ShaderPack(QFileInfo file_info) : Resource(file_info) {}
|
||||
|
||||
/** Thread-safe. */
|
||||
void setPackFormat(ShaderPackFormat new_format);
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
protected:
|
||||
mutable QMutex m_data_lock;
|
||||
|
||||
ShaderPackFormat m_pack_format = ShaderPackFormat::INVALID;
|
||||
};
|
43
launcher/minecraft/mod/WorldSave.cpp
Normal file
43
launcher/minecraft/mod/WorldSave.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// 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 "WorldSave.h"
|
||||
|
||||
#include "minecraft/mod/tasks/LocalWorldSaveParseTask.h"
|
||||
|
||||
void WorldSave::setSaveFormat(WorldSaveFormat new_save_format)
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
m_save_format = new_save_format;
|
||||
}
|
||||
|
||||
void WorldSave::setSaveDirName(QString dir_name)
|
||||
{
|
||||
QMutexLocker locker(&m_data_lock);
|
||||
|
||||
m_save_dir_name = dir_name;
|
||||
}
|
||||
|
||||
bool WorldSave::valid() const
|
||||
{
|
||||
return m_save_format != WorldSaveFormat::INVALID;
|
||||
}
|
61
launcher/minecraft/mod/WorldSave.h
Normal file
61
launcher/minecraft/mod/WorldSave.h
Normal file
@ -0,0 +1,61 @@
|
||||
// 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 "Resource.h"
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
class Version;
|
||||
|
||||
enum class WorldSaveFormat { SINGLE, MULTI, INVALID };
|
||||
|
||||
class WorldSave : public Resource {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<Resource>;
|
||||
|
||||
WorldSave(QObject* parent = nullptr) : Resource(parent) {}
|
||||
WorldSave(QFileInfo file_info) : Resource(file_info) {}
|
||||
|
||||
/** Gets the format of the save. */
|
||||
[[nodiscard]] WorldSaveFormat saveFormat() const { return m_save_format; }
|
||||
/** Gets the name of the save dir (first found in multi mode). */
|
||||
[[nodiscard]] QString saveDirName() const { return m_save_dir_name; }
|
||||
|
||||
/** Thread-safe. */
|
||||
void setSaveFormat(WorldSaveFormat new_save_format);
|
||||
/** Thread-safe. */
|
||||
void setSaveDirName(QString dir_name);
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
protected:
|
||||
mutable QMutex m_data_lock;
|
||||
|
||||
/** The format in which the save file is in.
|
||||
* Since saves can be distributed in various slightly different ways, this allows us to treat them separately.
|
||||
*/
|
||||
WorldSaveFormat m_save_format = WorldSaveFormat::INVALID;
|
||||
|
||||
QString m_save_dir_name;
|
||||
};
|
177
launcher/minecraft/mod/tasks/LocalDataPackParseTask.cpp
Normal file
177
launcher/minecraft/mod/tasks/LocalDataPackParseTask.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
// 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 "LocalDataPackParseTask.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
|
||||
#include <quazip/quazip.h>
|
||||
#include <quazip/quazipdir.h>
|
||||
#include <quazip/quazipfile.h>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
|
||||
namespace DataPackUtils {
|
||||
|
||||
bool process(DataPack& pack, ProcessingLevel level)
|
||||
{
|
||||
switch (pack.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
return DataPackUtils::processFolder(pack, level);
|
||||
case ResourceType::ZIPFILE:
|
||||
return DataPackUtils::processZIP(pack, level);
|
||||
default:
|
||||
qWarning() << "Invalid type for data pack parse task!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool processFolder(DataPack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||
|
||||
auto mcmeta_invalid = [&pack]() {
|
||||
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||
return false; // the mcmeta is not optional
|
||||
};
|
||||
|
||||
QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.mcmeta"));
|
||||
if (mcmeta_file_info.exists() && mcmeta_file_info.isFile()) {
|
||||
QFile mcmeta_file(mcmeta_file_info.filePath());
|
||||
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
||||
return mcmeta_invalid(); // can't open mcmeta file
|
||||
|
||||
auto data = mcmeta_file.readAll();
|
||||
|
||||
bool mcmeta_result = DataPackUtils::processMCMeta(pack, std::move(data));
|
||||
|
||||
mcmeta_file.close();
|
||||
if (!mcmeta_result) {
|
||||
return mcmeta_invalid(); // mcmeta invalid
|
||||
}
|
||||
} else {
|
||||
return mcmeta_invalid(); // mcmeta file isn't a valid file
|
||||
}
|
||||
|
||||
QFileInfo data_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "data"));
|
||||
if (!data_dir_info.exists() || !data_dir_info.isDir()) {
|
||||
return false; // data dir does not exists or isn't valid
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
return true; // all tests passed
|
||||
}
|
||||
|
||||
bool processZIP(DataPack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
|
||||
|
||||
QuaZip zip(pack.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return false; // can't open zip file
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
auto mcmeta_invalid = [&pack]() {
|
||||
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||
return false; // the mcmeta is not optional
|
||||
};
|
||||
|
||||
if (zip.setCurrentFile("pack.mcmeta")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file in zip.";
|
||||
zip.close();
|
||||
return mcmeta_invalid();
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
bool mcmeta_result = DataPackUtils::processMCMeta(pack, std::move(data));
|
||||
|
||||
file.close();
|
||||
if (!mcmeta_result) {
|
||||
return mcmeta_invalid(); // mcmeta invalid
|
||||
}
|
||||
} else {
|
||||
return mcmeta_invalid(); // could not set pack.mcmeta as current file.
|
||||
}
|
||||
|
||||
QuaZipDir zipDir(&zip);
|
||||
if (!zipDir.exists("/data")) {
|
||||
return false; // data dir does not exists at zip root
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
zip.close();
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
zip.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://minecraft.fandom.com/wiki/Data_pack#pack.mcmeta
|
||||
bool processMCMeta(DataPack& pack, QByteArray&& raw_data)
|
||||
{
|
||||
try {
|
||||
auto json_doc = QJsonDocument::fromJson(raw_data);
|
||||
auto pack_obj = Json::requireObject(json_doc.object(), "pack", {});
|
||||
|
||||
pack.setPackFormat(Json::ensureInteger(pack_obj, "pack_format", 0));
|
||||
pack.setDescription(Json::ensureString(pack_obj, "description", ""));
|
||||
} catch (Json::JsonException& e) {
|
||||
qWarning() << "JsonException: " << e.what() << e.cause();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validate(QFileInfo file)
|
||||
{
|
||||
DataPack dp{ file };
|
||||
return DataPackUtils::process(dp, ProcessingLevel::BasicInfoOnly) && dp.valid();
|
||||
}
|
||||
|
||||
} // namespace DataPackUtils
|
||||
|
||||
LocalDataPackParseTask::LocalDataPackParseTask(int token, DataPack& dp) : Task(nullptr, false), m_token(token), m_data_pack(dp) {}
|
||||
|
||||
bool LocalDataPackParseTask::abort()
|
||||
{
|
||||
m_aborted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocalDataPackParseTask::executeTask()
|
||||
{
|
||||
if (!DataPackUtils::process(m_data_pack))
|
||||
return;
|
||||
|
||||
if (m_aborted)
|
||||
emitAborted();
|
||||
else
|
||||
emitSucceeded();
|
||||
}
|
65
launcher/minecraft/mod/tasks/LocalDataPackParseTask.h
Normal file
65
launcher/minecraft/mod/tasks/LocalDataPackParseTask.h
Normal file
@ -0,0 +1,65 @@
|
||||
// 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 <QObject>
|
||||
|
||||
#include "minecraft/mod/DataPack.h"
|
||||
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace DataPackUtils {
|
||||
|
||||
enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(DataPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
bool processZIP(DataPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processFolder(DataPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
bool processMCMeta(DataPack& pack, QByteArray&& raw_data);
|
||||
|
||||
/** Checks whether a file is valid as a data pack or not. */
|
||||
bool validate(QFileInfo file);
|
||||
|
||||
} // namespace DataPackUtils
|
||||
|
||||
class LocalDataPackParseTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocalDataPackParseTask(int token, DataPack& dp);
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
bool abort() override;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
[[nodiscard]] int token() const { return m_token; }
|
||||
|
||||
private:
|
||||
int m_token;
|
||||
|
||||
DataPack& m_data_pack;
|
||||
|
||||
bool m_aborted = false;
|
||||
};
|
@ -11,9 +11,10 @@
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
#include "minecraft/mod/ModDetails.h"
|
||||
#include "settings/INIFile.h"
|
||||
|
||||
namespace {
|
||||
namespace ModUtils {
|
||||
|
||||
// NEW format
|
||||
// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/6f62b37cea040daf350dc253eae6326dd9c822c3
|
||||
@ -283,35 +284,46 @@ ModDetails ReadLiteModInfo(QByteArray contents)
|
||||
return details;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
LocalModParseTask::LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile)
|
||||
: Task(nullptr, false), m_token(token), m_type(type), m_modFile(modFile), m_result(new Result())
|
||||
{}
|
||||
|
||||
void LocalModParseTask::processAsZip()
|
||||
bool process(Mod& mod, ProcessingLevel level)
|
||||
{
|
||||
QuaZip zip(m_modFile.filePath());
|
||||
switch (mod.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
return processFolder(mod, level);
|
||||
case ResourceType::ZIPFILE:
|
||||
return processZIP(mod, level);
|
||||
case ResourceType::LITEMOD:
|
||||
return processLitemod(mod);
|
||||
default:
|
||||
qWarning() << "Invalid type for mod parse task!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool processZIP(Mod& mod, ProcessingLevel level)
|
||||
{
|
||||
ModDetails details;
|
||||
|
||||
QuaZip zip(mod.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return;
|
||||
return false;
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
if (zip.setCurrentFile("META-INF/mods.toml")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_result->details = ReadMCModTOML(file.readAll());
|
||||
details = ReadMCModTOML(file.readAll());
|
||||
file.close();
|
||||
|
||||
// to replace ${file.jarVersion} with the actual version, as needed
|
||||
if (m_result->details.version == "${file.jarVersion}") {
|
||||
if (details.version == "${file.jarVersion}") {
|
||||
if (zip.setCurrentFile("META-INF/MANIFEST.MF")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// quick and dirty line-by-line parser
|
||||
@ -330,93 +342,131 @@ void LocalModParseTask::processAsZip()
|
||||
manifestVersion = "NONE";
|
||||
}
|
||||
|
||||
m_result->details.version = manifestVersion;
|
||||
details.version = manifestVersion;
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
zip.close();
|
||||
return;
|
||||
mod.setDetails(details);
|
||||
|
||||
return true;
|
||||
} else if (zip.setCurrentFile("mcmod.info")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_result->details = ReadMCModInfo(file.readAll());
|
||||
details = ReadMCModInfo(file.readAll());
|
||||
file.close();
|
||||
zip.close();
|
||||
return;
|
||||
|
||||
mod.setDetails(details);
|
||||
return true;
|
||||
} else if (zip.setCurrentFile("quilt.mod.json")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_result->details = ReadQuiltModInfo(file.readAll());
|
||||
details = ReadQuiltModInfo(file.readAll());
|
||||
file.close();
|
||||
zip.close();
|
||||
return;
|
||||
|
||||
mod.setDetails(details);
|
||||
return true;
|
||||
} else if (zip.setCurrentFile("fabric.mod.json")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_result->details = ReadFabricModInfo(file.readAll());
|
||||
details = ReadFabricModInfo(file.readAll());
|
||||
file.close();
|
||||
zip.close();
|
||||
return;
|
||||
|
||||
mod.setDetails(details);
|
||||
return true;
|
||||
} else if (zip.setCurrentFile("forgeversion.properties")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_result->details = ReadForgeInfo(file.readAll());
|
||||
details = ReadForgeInfo(file.readAll());
|
||||
file.close();
|
||||
zip.close();
|
||||
return;
|
||||
|
||||
mod.setDetails(details);
|
||||
return true;
|
||||
}
|
||||
|
||||
zip.close();
|
||||
return false; // no valid mod found in archive
|
||||
}
|
||||
|
||||
void LocalModParseTask::processAsFolder()
|
||||
bool processFolder(Mod& mod, ProcessingLevel level)
|
||||
{
|
||||
QFileInfo mcmod_info(FS::PathCombine(m_modFile.filePath(), "mcmod.info"));
|
||||
if (mcmod_info.isFile()) {
|
||||
ModDetails details;
|
||||
|
||||
QFileInfo mcmod_info(FS::PathCombine(mod.fileinfo().filePath(), "mcmod.info"));
|
||||
if (mcmod_info.exists() && mcmod_info.isFile()) {
|
||||
QFile mcmod(mcmod_info.filePath());
|
||||
if (!mcmod.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
return false;
|
||||
auto data = mcmod.readAll();
|
||||
if (data.isEmpty() || data.isNull())
|
||||
return;
|
||||
m_result->details = ReadMCModInfo(data);
|
||||
return false;
|
||||
details = ReadMCModInfo(data);
|
||||
|
||||
mod.setDetails(details);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // no valid mcmod.info file found
|
||||
}
|
||||
|
||||
void LocalModParseTask::processAsLitemod()
|
||||
bool processLitemod(Mod& mod, ProcessingLevel level)
|
||||
{
|
||||
QuaZip zip(m_modFile.filePath());
|
||||
ModDetails details;
|
||||
|
||||
QuaZip zip(mod.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return;
|
||||
return false;
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
if (zip.setCurrentFile("litemod.json")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_result->details = ReadLiteModInfo(file.readAll());
|
||||
details = ReadLiteModInfo(file.readAll());
|
||||
file.close();
|
||||
|
||||
mod.setDetails(details);
|
||||
return true;
|
||||
}
|
||||
zip.close();
|
||||
|
||||
return false; // no valid litemod.json found in archive
|
||||
}
|
||||
|
||||
/** Checks whether a file is valid as a mod or not. */
|
||||
bool validate(QFileInfo file)
|
||||
{
|
||||
Mod mod{ file };
|
||||
return ModUtils::process(mod, ProcessingLevel::BasicInfoOnly) && mod.valid();
|
||||
}
|
||||
|
||||
} // namespace ModUtils
|
||||
|
||||
LocalModParseTask::LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile)
|
||||
: Task(nullptr, false), m_token(token), m_type(type), m_modFile(modFile), m_result(new Result())
|
||||
{}
|
||||
|
||||
bool LocalModParseTask::abort()
|
||||
{
|
||||
m_aborted.store(true);
|
||||
@ -425,19 +475,10 @@ bool LocalModParseTask::abort()
|
||||
|
||||
void LocalModParseTask::executeTask()
|
||||
{
|
||||
switch (m_type) {
|
||||
case ResourceType::ZIPFILE:
|
||||
processAsZip();
|
||||
break;
|
||||
case ResourceType::FOLDER:
|
||||
processAsFolder();
|
||||
break;
|
||||
case ResourceType::LITEMOD:
|
||||
processAsLitemod();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Mod mod{ m_modFile };
|
||||
ModUtils::process(mod, ModUtils::ProcessingLevel::Full);
|
||||
|
||||
m_result->details = mod.details();
|
||||
|
||||
if (m_aborted)
|
||||
emit finished();
|
||||
|
@ -8,32 +8,48 @@
|
||||
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class LocalModParseTask : public Task
|
||||
{
|
||||
namespace ModUtils {
|
||||
|
||||
ModDetails ReadFabricModInfo(QByteArray contents);
|
||||
ModDetails ReadQuiltModInfo(QByteArray contents);
|
||||
ModDetails ReadForgeInfo(QByteArray contents);
|
||||
ModDetails ReadLiteModInfo(QByteArray contents);
|
||||
|
||||
enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(Mod& mod, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
bool processZIP(Mod& mod, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processFolder(Mod& mod, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processLitemod(Mod& mod, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
/** Checks whether a file is valid as a mod or not. */
|
||||
bool validate(QFileInfo file);
|
||||
} // namespace ModUtils
|
||||
|
||||
class LocalModParseTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
struct Result {
|
||||
ModDetails details;
|
||||
};
|
||||
using ResultPtr = std::shared_ptr<Result>;
|
||||
ResultPtr result() const {
|
||||
return m_result;
|
||||
}
|
||||
ResultPtr result() const { return m_result; }
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
bool abort() override;
|
||||
|
||||
LocalModParseTask(int token, ResourceType type, const QFileInfo & modFile);
|
||||
LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile);
|
||||
void executeTask() override;
|
||||
|
||||
[[nodiscard]] int token() const { return m_token; }
|
||||
|
||||
private:
|
||||
private:
|
||||
void processAsZip();
|
||||
void processAsFolder();
|
||||
void processAsLitemod();
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_token;
|
||||
ResourceType m_type;
|
||||
QFileInfo m_modFile;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "Json.h"
|
||||
|
||||
#include <quazip/quazip.h>
|
||||
#include <quazip/quazipdir.h>
|
||||
#include <quazip/quazipfile.h>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
@ -32,99 +33,152 @@ bool process(ResourcePack& pack, ProcessingLevel level)
|
||||
{
|
||||
switch (pack.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
ResourcePackUtils::processFolder(pack, level);
|
||||
return true;
|
||||
return ResourcePackUtils::processFolder(pack, level);
|
||||
case ResourceType::ZIPFILE:
|
||||
ResourcePackUtils::processZIP(pack, level);
|
||||
return true;
|
||||
return ResourcePackUtils::processZIP(pack, level);
|
||||
default:
|
||||
qWarning() << "Invalid type for resource pack parse task!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void processFolder(ResourcePack& pack, ProcessingLevel level)
|
||||
bool processFolder(ResourcePack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||
|
||||
auto mcmeta_invalid = [&pack]() {
|
||||
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||
return false; // the mcmeta is not optional
|
||||
};
|
||||
|
||||
QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.mcmeta"));
|
||||
if (mcmeta_file_info.isFile()) {
|
||||
if (mcmeta_file_info.exists() && mcmeta_file_info.isFile()) {
|
||||
QFile mcmeta_file(mcmeta_file_info.filePath());
|
||||
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
return mcmeta_invalid(); // can't open mcmeta file
|
||||
|
||||
auto data = mcmeta_file.readAll();
|
||||
|
||||
ResourcePackUtils::processMCMeta(pack, std::move(data));
|
||||
bool mcmeta_result = ResourcePackUtils::processMCMeta(pack, std::move(data));
|
||||
|
||||
mcmeta_file.close();
|
||||
if (!mcmeta_result) {
|
||||
return mcmeta_invalid(); // mcmeta invalid
|
||||
}
|
||||
} else {
|
||||
return mcmeta_invalid(); // mcmeta file isn't a valid file
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly)
|
||||
return;
|
||||
QFileInfo assets_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "assets"));
|
||||
if (!assets_dir_info.exists() || !assets_dir_info.isDir()) {
|
||||
return false; // assets dir does not exists or isn't valid
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
auto png_invalid = [&pack]() {
|
||||
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.png";
|
||||
return true; // the png is optional
|
||||
};
|
||||
|
||||
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;
|
||||
if (image_file_info.exists() && image_file_info.isFile()) {
|
||||
QFile pack_png_file(image_file_info.filePath());
|
||||
if (!pack_png_file.open(QIODevice::ReadOnly))
|
||||
return png_invalid(); // can't open pack.png file
|
||||
|
||||
auto data = mcmeta_file.readAll();
|
||||
auto data = pack_png_file.readAll();
|
||||
|
||||
ResourcePackUtils::processPackPNG(pack, std::move(data));
|
||||
bool pack_png_result = ResourcePackUtils::processPackPNG(pack, std::move(data));
|
||||
|
||||
mcmeta_file.close();
|
||||
pack_png_file.close();
|
||||
if (!pack_png_result) {
|
||||
return png_invalid(); // pack.png invalid
|
||||
}
|
||||
} else {
|
||||
return png_invalid(); // pack.png does not exists or is not a valid file.
|
||||
}
|
||||
|
||||
return true; // all tests passed
|
||||
}
|
||||
|
||||
void processZIP(ResourcePack& pack, ProcessingLevel level)
|
||||
bool processZIP(ResourcePack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
|
||||
|
||||
QuaZip zip(pack.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return;
|
||||
return false; // can't open zip file
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
auto mcmeta_invalid = [&pack]() {
|
||||
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||
return false; // the mcmeta is not optional
|
||||
};
|
||||
|
||||
if (zip.setCurrentFile("pack.mcmeta")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file in zip.";
|
||||
zip.close();
|
||||
return;
|
||||
return mcmeta_invalid();
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
ResourcePackUtils::processMCMeta(pack, std::move(data));
|
||||
bool mcmeta_result = ResourcePackUtils::processMCMeta(pack, std::move(data));
|
||||
|
||||
file.close();
|
||||
if (!mcmeta_result) {
|
||||
return mcmeta_invalid(); // mcmeta invalid
|
||||
}
|
||||
} else {
|
||||
return mcmeta_invalid(); // could not set pack.mcmeta as current file.
|
||||
}
|
||||
|
||||
QuaZipDir zipDir(&zip);
|
||||
if (!zipDir.exists("/assets")) {
|
||||
return false; // assets dir does not exists at zip root
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
zip.close();
|
||||
return;
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
auto png_invalid = [&pack]() {
|
||||
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.png";
|
||||
return true; // the png is optional
|
||||
};
|
||||
|
||||
if (zip.setCurrentFile("pack.png")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file in zip.";
|
||||
zip.close();
|
||||
return;
|
||||
return png_invalid();
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
ResourcePackUtils::processPackPNG(pack, std::move(data));
|
||||
bool pack_png_result = ResourcePackUtils::processPackPNG(pack, std::move(data));
|
||||
|
||||
file.close();
|
||||
if (!pack_png_result) {
|
||||
return png_invalid(); // pack.png invalid
|
||||
}
|
||||
} else {
|
||||
return png_invalid(); // could not set pack.mcmeta as current file.
|
||||
}
|
||||
|
||||
zip.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
|
||||
void processMCMeta(ResourcePack& pack, QByteArray&& raw_data)
|
||||
bool processMCMeta(ResourcePack& pack, QByteArray&& raw_data)
|
||||
{
|
||||
try {
|
||||
auto json_doc = QJsonDocument::fromJson(raw_data);
|
||||
@ -134,17 +188,21 @@ void processMCMeta(ResourcePack& pack, QByteArray&& raw_data)
|
||||
pack.setDescription(Json::ensureString(pack_obj, "description", ""));
|
||||
} catch (Json::JsonException& e) {
|
||||
qWarning() << "JsonException: " << e.what() << e.cause();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void processPackPNG(ResourcePack& pack, QByteArray&& raw_data)
|
||||
bool processPackPNG(ResourcePack& pack, QByteArray&& raw_data)
|
||||
{
|
||||
auto img = QImage::fromData(raw_data);
|
||||
if (!img.isNull()) {
|
||||
pack.setImage(img);
|
||||
} else {
|
||||
qWarning() << "Failed to parse pack.png.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validate(QFileInfo file)
|
||||
|
@ -31,11 +31,11 @@ enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processZIP(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
void processFolder(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processZIP(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processFolder(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processMCMeta(ResourcePack& pack, QByteArray&& raw_data);
|
||||
void processPackPNG(ResourcePack& pack, QByteArray&& raw_data);
|
||||
bool processMCMeta(ResourcePack& pack, QByteArray&& raw_data);
|
||||
bool processPackPNG(ResourcePack& pack, QByteArray&& raw_data);
|
||||
|
||||
/** Checks whether a file is valid as a resource pack or not. */
|
||||
bool validate(QFileInfo file);
|
||||
|
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
|
113
launcher/minecraft/mod/tasks/LocalShaderPackParseTask.cpp
Normal file
113
launcher/minecraft/mod/tasks/LocalShaderPackParseTask.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
// 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 "LocalShaderPackParseTask.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include <quazip/quazip.h>
|
||||
#include <quazip/quazipdir.h>
|
||||
#include <quazip/quazipfile.h>
|
||||
|
||||
namespace ShaderPackUtils {
|
||||
|
||||
bool process(ShaderPack& pack, ProcessingLevel level)
|
||||
{
|
||||
switch (pack.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
return ShaderPackUtils::processFolder(pack, level);
|
||||
case ResourceType::ZIPFILE:
|
||||
return ShaderPackUtils::processZIP(pack, level);
|
||||
default:
|
||||
qWarning() << "Invalid type for shader pack parse task!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool processFolder(ShaderPack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||
|
||||
QFileInfo shaders_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "shaders"));
|
||||
if (!shaders_dir_info.exists() || !shaders_dir_info.isDir()) {
|
||||
return false; // assets dir does not exists or isn't valid
|
||||
}
|
||||
pack.setPackFormat(ShaderPackFormat::VALID);
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
return true; // all tests passed
|
||||
}
|
||||
|
||||
bool processZIP(ShaderPack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
|
||||
|
||||
QuaZip zip(pack.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return false; // can't open zip file
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
QuaZipDir zipDir(&zip);
|
||||
if (!zipDir.exists("/shaders")) {
|
||||
return false; // assets dir does not exists at zip root
|
||||
}
|
||||
pack.setPackFormat(ShaderPackFormat::VALID);
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
zip.close();
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
zip.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validate(QFileInfo file)
|
||||
{
|
||||
ShaderPack sp{ file };
|
||||
return ShaderPackUtils::process(sp, ProcessingLevel::BasicInfoOnly) && sp.valid();
|
||||
}
|
||||
|
||||
} // namespace ShaderPackUtils
|
||||
|
||||
LocalShaderPackParseTask::LocalShaderPackParseTask(int token, ShaderPack& sp) : Task(nullptr, false), m_token(token), m_shader_pack(sp) {}
|
||||
|
||||
bool LocalShaderPackParseTask::abort()
|
||||
{
|
||||
m_aborted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocalShaderPackParseTask::executeTask()
|
||||
{
|
||||
if (!ShaderPackUtils::process(m_shader_pack))
|
||||
return;
|
||||
|
||||
if (m_aborted)
|
||||
emitAborted();
|
||||
else
|
||||
emitSucceeded();
|
||||
}
|
62
launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h
Normal file
62
launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h
Normal file
@ -0,0 +1,62 @@
|
||||
// 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 <QObject>
|
||||
|
||||
#include "minecraft/mod/ShaderPack.h"
|
||||
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace ShaderPackUtils {
|
||||
|
||||
enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
bool processZIP(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processFolder(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
/** Checks whether a file is valid as a shader pack or not. */
|
||||
bool validate(QFileInfo file);
|
||||
} // namespace ShaderPackUtils
|
||||
|
||||
class LocalShaderPackParseTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocalShaderPackParseTask(int token, ShaderPack& sp);
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
bool abort() override;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
[[nodiscard]] int token() const { return m_token; }
|
||||
|
||||
private:
|
||||
int m_token;
|
||||
|
||||
ShaderPack& m_shader_pack;
|
||||
|
||||
bool m_aborted = false;
|
||||
};
|
@ -32,18 +32,16 @@ bool process(TexturePack& pack, ProcessingLevel level)
|
||||
{
|
||||
switch (pack.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
TexturePackUtils::processFolder(pack, level);
|
||||
return true;
|
||||
return TexturePackUtils::processFolder(pack, level);
|
||||
case ResourceType::ZIPFILE:
|
||||
TexturePackUtils::processZIP(pack, level);
|
||||
return true;
|
||||
return TexturePackUtils::processZIP(pack, level);
|
||||
default:
|
||||
qWarning() << "Invalid type for resource pack parse task!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void processFolder(TexturePack& pack, ProcessingLevel level)
|
||||
bool processFolder(TexturePack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||
|
||||
@ -51,39 +49,51 @@ void processFolder(TexturePack& pack, ProcessingLevel level)
|
||||
if (mcmeta_file_info.isFile()) {
|
||||
QFile mcmeta_file(mcmeta_file_info.filePath());
|
||||
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
return false;
|
||||
|
||||
auto data = mcmeta_file.readAll();
|
||||
|
||||
TexturePackUtils::processPackTXT(pack, std::move(data));
|
||||
bool packTXT_result = TexturePackUtils::processPackTXT(pack, std::move(data));
|
||||
|
||||
mcmeta_file.close();
|
||||
if (!packTXT_result) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly)
|
||||
return;
|
||||
return true;
|
||||
|
||||
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;
|
||||
return false;
|
||||
|
||||
auto data = mcmeta_file.readAll();
|
||||
|
||||
TexturePackUtils::processPackPNG(pack, std::move(data));
|
||||
bool packPNG_result = TexturePackUtils::processPackPNG(pack, std::move(data));
|
||||
|
||||
mcmeta_file.close();
|
||||
if (!packPNG_result) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void processZIP(TexturePack& pack, ProcessingLevel level)
|
||||
bool processZIP(TexturePack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
|
||||
|
||||
QuaZip zip(pack.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return;
|
||||
return false;
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
@ -91,51 +101,62 @@ void processZIP(TexturePack& pack, ProcessingLevel level)
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file in zip.";
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
TexturePackUtils::processPackTXT(pack, std::move(data));
|
||||
bool packTXT_result = TexturePackUtils::processPackTXT(pack, std::move(data));
|
||||
|
||||
file.close();
|
||||
if (!packTXT_result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
zip.close();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (zip.setCurrentFile("pack.png")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open file in zip.";
|
||||
zip.close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto data = file.readAll();
|
||||
|
||||
TexturePackUtils::processPackPNG(pack, std::move(data));
|
||||
bool packPNG_result = TexturePackUtils::processPackPNG(pack, std::move(data));
|
||||
|
||||
file.close();
|
||||
if (!packPNG_result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
zip.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void processPackTXT(TexturePack& pack, QByteArray&& raw_data)
|
||||
bool processPackTXT(TexturePack& pack, QByteArray&& raw_data)
|
||||
{
|
||||
pack.setDescription(QString(raw_data));
|
||||
return true;
|
||||
}
|
||||
|
||||
void processPackPNG(TexturePack& pack, QByteArray&& raw_data)
|
||||
bool 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.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validate(QFileInfo file)
|
||||
|
@ -32,11 +32,11 @@ enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processZIP(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
void processFolder(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processZIP(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processFolder(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processPackTXT(TexturePack& pack, QByteArray&& raw_data);
|
||||
void processPackPNG(TexturePack& pack, QByteArray&& raw_data);
|
||||
bool processPackTXT(TexturePack& pack, QByteArray&& raw_data);
|
||||
bool processPackPNG(TexturePack& pack, QByteArray&& raw_data);
|
||||
|
||||
/** Checks whether a file is valid as a texture pack or not. */
|
||||
bool validate(QFileInfo file);
|
||||
|
190
launcher/minecraft/mod/tasks/LocalWorldSaveParseTask.cpp
Normal file
190
launcher/minecraft/mod/tasks/LocalWorldSaveParseTask.cpp
Normal file
@ -0,0 +1,190 @@
|
||||
|
||||
// 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 "LocalWorldSaveParseTask.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include <quazip/quazip.h>
|
||||
#include <quazip/quazipdir.h>
|
||||
#include <quazip/quazipfile.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace WorldSaveUtils {
|
||||
|
||||
bool process(WorldSave& pack, ProcessingLevel level)
|
||||
{
|
||||
switch (pack.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
return WorldSaveUtils::processFolder(pack, level);
|
||||
case ResourceType::ZIPFILE:
|
||||
return WorldSaveUtils::processZIP(pack, level);
|
||||
default:
|
||||
qWarning() << "Invalid type for world save parse task!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief checks a folder structure to see if it contains a level.dat
|
||||
/// @param dir the path to check
|
||||
/// @param saves used in recursive call if a "saves" dir was found
|
||||
/// @return std::tuple of (
|
||||
/// bool <found level.dat>,
|
||||
/// QString <name of folder containing level.dat>,
|
||||
/// bool <saves folder found>
|
||||
/// )
|
||||
static std::tuple<bool, QString, bool> contains_level_dat(QDir dir, bool saves = false)
|
||||
{
|
||||
for (auto const& entry : dir.entryInfoList()) {
|
||||
if (!entry.isDir()) {
|
||||
continue;
|
||||
}
|
||||
if (!saves && entry.fileName() == "saves") {
|
||||
return contains_level_dat(QDir(entry.filePath()), true);
|
||||
}
|
||||
QFileInfo level_dat(FS::PathCombine(entry.filePath(), "level.dat"));
|
||||
if (level_dat.exists() && level_dat.isFile()) {
|
||||
return std::make_tuple(true, entry.fileName(), saves);
|
||||
}
|
||||
}
|
||||
return std::make_tuple(false, "", saves);
|
||||
}
|
||||
|
||||
bool processFolder(WorldSave& save, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(save.type() == ResourceType::FOLDER);
|
||||
|
||||
auto [found, save_dir_name, found_saves_dir] = contains_level_dat(QDir(save.fileinfo().filePath()));
|
||||
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
|
||||
save.setSaveDirName(save_dir_name);
|
||||
|
||||
if (found_saves_dir) {
|
||||
save.setSaveFormat(WorldSaveFormat::MULTI);
|
||||
} else {
|
||||
save.setSaveFormat(WorldSaveFormat::SINGLE);
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
// reserved for more intensive processing
|
||||
|
||||
return true; // all tests passed
|
||||
}
|
||||
|
||||
/// @brief checks a folder structure to see if it contains a level.dat
|
||||
/// @param zip the zip file to check
|
||||
/// @return std::tuple of (
|
||||
/// bool <found level.dat>,
|
||||
/// QString <name of folder containing level.dat>,
|
||||
/// bool <saves folder found>
|
||||
/// )
|
||||
static std::tuple<bool, QString, bool> contains_level_dat(QuaZip& zip)
|
||||
{
|
||||
bool saves = false;
|
||||
QuaZipDir zipDir(&zip);
|
||||
if (zipDir.exists("/saves")) {
|
||||
saves = true;
|
||||
zipDir.cd("/saves");
|
||||
}
|
||||
|
||||
for (auto const& entry : zipDir.entryList()) {
|
||||
zipDir.cd(entry);
|
||||
if (zipDir.exists("level.dat")) {
|
||||
return std::make_tuple(true, entry, saves);
|
||||
}
|
||||
zipDir.cd("..");
|
||||
}
|
||||
return std::make_tuple(false, "", saves);
|
||||
}
|
||||
|
||||
bool processZIP(WorldSave& save, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(save.type() == ResourceType::ZIPFILE);
|
||||
|
||||
QuaZip zip(save.fileinfo().filePath());
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return false; // can't open zip file
|
||||
|
||||
auto [found, save_dir_name, found_saves_dir] = contains_level_dat(zip);
|
||||
|
||||
if (save_dir_name.endsWith("/")) {
|
||||
save_dir_name.chop(1);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
|
||||
save.setSaveDirName(save_dir_name);
|
||||
|
||||
if (found_saves_dir) {
|
||||
save.setSaveFormat(WorldSaveFormat::MULTI);
|
||||
} else {
|
||||
save.setSaveFormat(WorldSaveFormat::SINGLE);
|
||||
}
|
||||
|
||||
if (level == ProcessingLevel::BasicInfoOnly) {
|
||||
zip.close();
|
||||
return true; // only need basic info already checked
|
||||
}
|
||||
|
||||
// reserved for more intensive processing
|
||||
|
||||
zip.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validate(QFileInfo file)
|
||||
{
|
||||
WorldSave sp{ file };
|
||||
return WorldSaveUtils::process(sp, ProcessingLevel::BasicInfoOnly) && sp.valid();
|
||||
}
|
||||
|
||||
} // namespace WorldSaveUtils
|
||||
|
||||
LocalWorldSaveParseTask::LocalWorldSaveParseTask(int token, WorldSave& save) : Task(nullptr, false), m_token(token), m_save(save) {}
|
||||
|
||||
bool LocalWorldSaveParseTask::abort()
|
||||
{
|
||||
m_aborted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LocalWorldSaveParseTask::executeTask()
|
||||
{
|
||||
if (!WorldSaveUtils::process(m_save))
|
||||
return;
|
||||
|
||||
if (m_aborted)
|
||||
emitAborted();
|
||||
else
|
||||
emitSucceeded();
|
||||
}
|
62
launcher/minecraft/mod/tasks/LocalWorldSaveParseTask.h
Normal file
62
launcher/minecraft/mod/tasks/LocalWorldSaveParseTask.h
Normal file
@ -0,0 +1,62 @@
|
||||
// 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 <QObject>
|
||||
|
||||
#include "minecraft/mod/WorldSave.h"
|
||||
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace WorldSaveUtils {
|
||||
|
||||
enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(WorldSave& save, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
bool processZIP(WorldSave& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
bool processFolder(WorldSave& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
bool validate(QFileInfo file);
|
||||
|
||||
} // namespace WorldSaveUtils
|
||||
|
||||
class LocalWorldSaveParseTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocalWorldSaveParseTask(int token, WorldSave& save);
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
bool abort() override;
|
||||
|
||||
void executeTask() override;
|
||||
|
||||
[[nodiscard]] int token() const { return m_token; }
|
||||
|
||||
private:
|
||||
int m_token;
|
||||
|
||||
WorldSave& m_save;
|
||||
|
||||
bool m_aborted = false;
|
||||
};
|
@ -53,6 +53,13 @@
|
||||
#include "ui/dialogs/BlockedModsDialog.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "minecraft/World.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" },
|
||||
{ "1.4.7", "6.6.2.534" },
|
||||
@ -401,6 +408,10 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
||||
QList<BlockedMod> blocked_mods;
|
||||
auto anyBlocked = false;
|
||||
for (const auto& result : results.files.values()) {
|
||||
if (result.fileName.endsWith(".zip")) {
|
||||
m_ZIP_resources.append(std::make_pair(result.fileName, result.targetFolder));
|
||||
}
|
||||
|
||||
if (!result.resolved || result.url.isEmpty()) {
|
||||
BlockedMod blocked_mod;
|
||||
blocked_mod.name = result.fileName;
|
||||
@ -439,38 +450,6 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief copy the matched blocked mods to the instance staging area
|
||||
/// @param blocked_mods list of the blocked mods and their matched paths
|
||||
void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
||||
{
|
||||
setStatus(tr("Copying Blocked Mods..."));
|
||||
setAbortable(false);
|
||||
int i = 0;
|
||||
int total = blocked_mods.length();
|
||||
setProgress(i, total);
|
||||
for (auto const& mod : blocked_mods) {
|
||||
if (!mod.matched) {
|
||||
qDebug() << mod.name << "was not matched to a local file, skipping copy";
|
||||
continue;
|
||||
}
|
||||
|
||||
auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", mod.targetFolder, mod.name);
|
||||
|
||||
setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total)));
|
||||
|
||||
qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path;
|
||||
|
||||
if (!FS::copy(mod.localPath, dest_path)()) {
|
||||
qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed";
|
||||
}
|
||||
|
||||
i++;
|
||||
setProgress(i, total);
|
||||
}
|
||||
|
||||
setAbortable(true);
|
||||
}
|
||||
|
||||
void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
|
||||
{
|
||||
m_files_job = new NetJob(tr("Mod download"), APPLICATION->network());
|
||||
@ -509,7 +488,10 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
|
||||
}
|
||||
|
||||
m_mod_id_resolver.reset();
|
||||
connect(m_files_job.get(), &NetJob::succeeded, this, [&]() { m_files_job.reset(); });
|
||||
connect(m_files_job.get(), &NetJob::succeeded, this, [&]() {
|
||||
m_files_job.reset();
|
||||
validateZIPResouces();
|
||||
});
|
||||
connect(m_files_job.get(), &NetJob::failed, [&](QString reason) {
|
||||
m_files_job.reset();
|
||||
setError(reason);
|
||||
@ -520,3 +502,103 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
|
||||
setStatus(tr("Downloading mods..."));
|
||||
m_files_job->start();
|
||||
}
|
||||
|
||||
/// @brief copy the matched blocked mods to the instance staging area
|
||||
/// @param blocked_mods list of the blocked mods and their matched paths
|
||||
void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
||||
{
|
||||
setStatus(tr("Copying Blocked Mods..."));
|
||||
setAbortable(false);
|
||||
int i = 0;
|
||||
int total = blocked_mods.length();
|
||||
setProgress(i, total);
|
||||
for (auto const& mod : blocked_mods) {
|
||||
if (!mod.matched) {
|
||||
qDebug() << mod.name << "was not matched to a local file, skipping copy";
|
||||
continue;
|
||||
}
|
||||
|
||||
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", mod.targetFolder, mod.name);
|
||||
|
||||
setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total)));
|
||||
|
||||
qDebug() << "Will try to copy" << mod.localPath << "to" << destPath;
|
||||
|
||||
if (!FS::copy(mod.localPath, destPath)()) {
|
||||
qDebug() << "Copy of" << mod.localPath << "to" << destPath << "Failed";
|
||||
}
|
||||
|
||||
i++;
|
||||
setProgress(i, total);
|
||||
}
|
||||
|
||||
setAbortable(true);
|
||||
}
|
||||
|
||||
|
||||
void FlameCreationTask::validateZIPResouces()
|
||||
{
|
||||
qDebug() << "Validating whether resources stored as .zip are in the right place";
|
||||
for (auto [fileName, targetFolder] : m_ZIP_resources) {
|
||||
qDebug() << "Checking" << fileName << "...";
|
||||
auto localPath = FS::PathCombine(m_stagingPath, "minecraft", targetFolder, fileName);
|
||||
|
||||
/// @brief check the target and move the the file
|
||||
/// @return path where file can now be found
|
||||
auto validatePath = [&localPath, this](QString fileName, QString targetFolder, QString realTarget) {
|
||||
if (targetFolder != realTarget) {
|
||||
qDebug() << "Target folder of" << fileName << "is incorrect, it belongs in" << realTarget;
|
||||
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", realTarget, fileName);
|
||||
qDebug() << "Moving" << localPath << "to" << destPath;
|
||||
if (FS::move(localPath, destPath)) {
|
||||
return destPath;
|
||||
}
|
||||
}
|
||||
return localPath;
|
||||
};
|
||||
|
||||
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"));
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
validatePath(fileName, targetFolder, "shaderpacks");
|
||||
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.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ class FlameCreationTask final : public InstanceCreationTask {
|
||||
void idResolverSucceeded(QEventLoop&);
|
||||
void setupDownloadJob(QEventLoop&);
|
||||
void copyBlockedMods(QList<BlockedMod> const& blocked_mods);
|
||||
void validateZIPResouces();
|
||||
|
||||
private:
|
||||
QWidget* m_parent = nullptr;
|
||||
@ -90,5 +91,7 @@ class FlameCreationTask final : public InstanceCreationTask {
|
||||
|
||||
QString m_managed_id, m_managed_version_id;
|
||||
|
||||
QList<std::pair<QString, QString>> m_ZIP_resources;
|
||||
|
||||
std::optional<InstancePtr> m_instance;
|
||||
};
|
||||
|
@ -172,7 +172,7 @@ void Technic::TechnicPackProcessor::run(SettingsObjectPtr globalSettings, const
|
||||
auto libraryObject = Json::ensureObject(library, {}, "");
|
||||
auto libraryName = Json::ensureString(libraryObject, "name", "", "");
|
||||
|
||||
if (libraryName.startsWith("net.minecraftforge:forge:") && libraryName.contains('-'))
|
||||
if ((libraryName.startsWith("net.minecraftforge:forge:") || libraryName.startsWith("net.minecraftforge:fmlloader:")) && libraryName.contains('-'))
|
||||
{
|
||||
QString libraryVersion = libraryName.section(':', 2);
|
||||
if (!libraryVersion.startsWith("1.7.10-"))
|
||||
|
@ -13,5 +13,17 @@
|
||||
<file alias="rory-flat-xmas">rory-flat-xmas.png</file>
|
||||
<file alias="rory-flat-bday">rory-flat-bday.png</file>
|
||||
<file alias="rory-flat-spooky">rory-flat-spooky.png</file>
|
||||
<!-- teawie images -->
|
||||
<!-- copyright (c) SympathyTea 2023 -->
|
||||
<!-- these are licensed under the CC BY-SA 4.0 and have been unmodified aside from downscaling -->
|
||||
<!-- the full license with appropriate notices is avalible at https://creativecommons.org/licenses/by-sa/4.0/ -->
|
||||
<file alias="teawie">teawie.png</file>
|
||||
<!-- https://commons.wikimedia.org/wiki/File:Teawie.png -->
|
||||
<file alias="teawie-xmas">teawie-xmas.png</file>
|
||||
<!-- https://commons.wikimedia.org/wiki/File:Teawie_Holiday.png -->
|
||||
<file alias="teawie-bday">teawie-bday.png</file>
|
||||
<!-- https://commons.wikimedia.org/wiki/File:Teawie_Party.png -->
|
||||
<file alias="teawie-spooky">teawie-spooky.png</file>
|
||||
<!-- https://commons.wikimedia.org/wiki/File:Teawie_Halloween.png -->
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
launcher/resources/backgrounds/teawie-bday.png
Normal file
BIN
launcher/resources/backgrounds/teawie-bday.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
BIN
launcher/resources/backgrounds/teawie-spooky.png
Normal file
BIN
launcher/resources/backgrounds/teawie-spooky.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 200 KiB |
BIN
launcher/resources/backgrounds/teawie-xmas.png
Normal file
BIN
launcher/resources/backgrounds/teawie-xmas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 195 KiB |
BIN
launcher/resources/backgrounds/teawie.png
Normal file
BIN
launcher/resources/backgrounds/teawie.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 184 KiB |
@ -111,6 +111,7 @@
|
||||
#include "ui/dialogs/ExportInstanceDialog.h"
|
||||
#include "ui/dialogs/ImportResourcePackDialog.h"
|
||||
#include "ui/themes/ITheme.h"
|
||||
#include "ui/themes/ThemeManager.h"
|
||||
|
||||
#include <minecraft/mod/ResourcePackFolderModel.h>
|
||||
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
|
||||
@ -1346,7 +1347,7 @@ void MainWindow::updateThemeMenu()
|
||||
themeAction->setActionGroup(themesGroup);
|
||||
|
||||
connect(themeAction, &QAction::triggered, [theme]() {
|
||||
APPLICATION->setApplicationTheme(theme->id(),false);
|
||||
APPLICATION->setApplicationTheme(theme->id());
|
||||
APPLICATION->settings()->set("ApplicationTheme", theme->id());
|
||||
});
|
||||
}
|
||||
@ -1652,32 +1653,9 @@ void MainWindow::onCatToggled(bool state)
|
||||
APPLICATION->settings()->set("TheCat", state);
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
T non_stupid_abs(T in)
|
||||
{
|
||||
if (in < 0)
|
||||
return -in;
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setCatBackground(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
|
||||
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
|
||||
QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
|
||||
QString cat = APPLICATION->settings()->get("BackgroundCat").toString();
|
||||
if (non_stupid_abs(now.daysTo(xmas)) <= 4) {
|
||||
cat += "-xmas";
|
||||
} else if (non_stupid_abs(now.daysTo(halloween)) <= 4) {
|
||||
cat += "-spooky";
|
||||
} else if (non_stupid_abs(now.daysTo(birthday)) <= 12) {
|
||||
cat += "-bday";
|
||||
}
|
||||
if (enabled) {
|
||||
view->setStyleSheet(QString(R"(
|
||||
InstanceView
|
||||
{
|
||||
@ -1688,10 +1666,8 @@ InstanceView
|
||||
background-repeat: none;
|
||||
background-color:palette(base);
|
||||
})")
|
||||
.arg(cat));
|
||||
}
|
||||
else
|
||||
{
|
||||
.arg(ThemeManager::getCatImage()));
|
||||
} else {
|
||||
view->setStyleSheet(QString());
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
#include <QWidget>
|
||||
|
||||
#include "WinDarkmode.h"
|
||||
|
||||
namespace WinDarkmode {
|
||||
|
||||
/* See https://github.com/statiolake/neovim-qt/commit/da8eaba7f0e38b6b51f3bacd02a8cc2d1f7a34d8 */
|
||||
void setDarkWinTitlebar(WId winid, bool darkmode)
|
||||
{
|
||||
HWND hwnd = reinterpret_cast<HWND>(winid);
|
||||
BOOL dark = (BOOL) darkmode;
|
||||
|
||||
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
|
||||
fnAllowDarkModeForWindow AllowDarkModeForWindow
|
||||
= reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
|
||||
fnSetPreferredAppMode SetPreferredAppMode
|
||||
= reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135)));
|
||||
fnSetWindowCompositionAttribute SetWindowCompositionAttribute
|
||||
= reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
|
||||
|
||||
SetPreferredAppMode(AllowDark);
|
||||
AllowDarkModeForWindow(hwnd, dark);
|
||||
WINDOWCOMPOSITIONATTRIBDATA data = {
|
||||
WCA_USEDARKMODECOLORS,
|
||||
&dark,
|
||||
sizeof(dark)
|
||||
};
|
||||
SetWindowCompositionAttribute(hwnd, &data);
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <dwmapi.h>
|
||||
|
||||
|
||||
namespace WinDarkmode {
|
||||
|
||||
void setDarkWinTitlebar(WId winid, bool darkmode);
|
||||
|
||||
enum PreferredAppMode {
|
||||
Default,
|
||||
AllowDark,
|
||||
ForceDark,
|
||||
ForceLight,
|
||||
Max
|
||||
};
|
||||
|
||||
enum WINDOWCOMPOSITIONATTRIB {
|
||||
WCA_UNDEFINED = 0,
|
||||
WCA_NCRENDERING_ENABLED = 1,
|
||||
WCA_NCRENDERING_POLICY = 2,
|
||||
WCA_TRANSITIONS_FORCEDISABLED = 3,
|
||||
WCA_ALLOW_NCPAINT = 4,
|
||||
WCA_CAPTION_BUTTON_BOUNDS = 5,
|
||||
WCA_NONCLIENT_RTL_LAYOUT = 6,
|
||||
WCA_FORCE_ICONIC_REPRESENTATION = 7,
|
||||
WCA_EXTENDED_FRAME_BOUNDS = 8,
|
||||
WCA_HAS_ICONIC_BITMAP = 9,
|
||||
WCA_THEME_ATTRIBUTES = 10,
|
||||
WCA_NCRENDERING_EXILED = 11,
|
||||
WCA_NCADORNMENTINFO = 12,
|
||||
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
|
||||
WCA_VIDEO_OVERLAY_ACTIVE = 14,
|
||||
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
|
||||
WCA_DISALLOW_PEEK = 16,
|
||||
WCA_CLOAK = 17,
|
||||
WCA_CLOAKED = 18,
|
||||
WCA_ACCENT_POLICY = 19,
|
||||
WCA_FREEZE_REPRESENTATION = 20,
|
||||
WCA_EVER_UNCLOAKED = 21,
|
||||
WCA_VISUAL_OWNER = 22,
|
||||
WCA_HOLOGRAPHIC = 23,
|
||||
WCA_EXCLUDED_FROM_DDA = 24,
|
||||
WCA_PASSIVEUPDATEMODE = 25,
|
||||
WCA_USEDARKMODECOLORS = 26,
|
||||
WCA_LAST = 27
|
||||
};
|
||||
|
||||
struct WINDOWCOMPOSITIONATTRIBDATA {
|
||||
WINDOWCOMPOSITIONATTRIB Attrib;
|
||||
PVOID pvData;
|
||||
SIZE_T cbData;
|
||||
};
|
||||
|
||||
using fnAllowDarkModeForWindow = BOOL (WINAPI *)(HWND hWnd, BOOL allow);
|
||||
using fnSetPreferredAppMode = PreferredAppMode (WINAPI *)(PreferredAppMode appMode);
|
||||
using fnSetWindowCompositionAttribute = BOOL (WINAPI *)(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *);
|
||||
|
||||
}
|
@ -286,72 +286,6 @@ void LauncherPage::applySettings()
|
||||
}
|
||||
|
||||
s->set("UpdateChannel", m_currentUpdateChannel);
|
||||
auto original = s->get("IconTheme").toString();
|
||||
//FIXME: make generic
|
||||
switch (ui->themeComboBox->currentIndex())
|
||||
{
|
||||
case 0:
|
||||
s->set("IconTheme", "pe_colored");
|
||||
break;
|
||||
case 1:
|
||||
s->set("IconTheme", "pe_light");
|
||||
break;
|
||||
case 2:
|
||||
s->set("IconTheme", "pe_dark");
|
||||
break;
|
||||
case 3:
|
||||
s->set("IconTheme", "pe_blue");
|
||||
break;
|
||||
case 4:
|
||||
s->set("IconTheme", "breeze_light");
|
||||
break;
|
||||
case 5:
|
||||
s->set("IconTheme", "breeze_dark");
|
||||
break;
|
||||
case 6:
|
||||
s->set("IconTheme", "OSX");
|
||||
break;
|
||||
case 7:
|
||||
s->set("IconTheme", "iOS");
|
||||
break;
|
||||
case 8:
|
||||
s->set("IconTheme", "flat");
|
||||
break;
|
||||
case 9:
|
||||
s->set("IconTheme", "flat_white");
|
||||
break;
|
||||
case 10:
|
||||
s->set("IconTheme", "multimc");
|
||||
break;
|
||||
case 11:
|
||||
s->set("IconTheme", "custom");
|
||||
break;
|
||||
}
|
||||
|
||||
if(original != s->get("IconTheme"))
|
||||
{
|
||||
APPLICATION->setIconTheme(s->get("IconTheme").toString());
|
||||
}
|
||||
|
||||
auto originalAppTheme = s->get("ApplicationTheme").toString();
|
||||
auto newAppTheme = ui->themeComboBoxColors->currentData().toString();
|
||||
if(originalAppTheme != newAppTheme)
|
||||
{
|
||||
s->set("ApplicationTheme", newAppTheme);
|
||||
APPLICATION->setApplicationTheme(newAppTheme, false);
|
||||
}
|
||||
|
||||
switch (ui->themeBackgroundCat->currentIndex()) {
|
||||
case 0: // original cat
|
||||
s->set("BackgroundCat", "kitteh");
|
||||
break;
|
||||
case 1: // rory the cat
|
||||
s->set("BackgroundCat", "rory");
|
||||
break;
|
||||
case 2: // rory the cat flat edition
|
||||
s->set("BackgroundCat", "rory-flat");
|
||||
break;
|
||||
}
|
||||
|
||||
s->set("MenuBarInsteadOfToolBar", ui->preferMenuBarCheckBox->isChecked());
|
||||
|
||||
@ -401,45 +335,6 @@ void LauncherPage::loadSettings()
|
||||
}
|
||||
|
||||
m_currentUpdateChannel = s->get("UpdateChannel").toString();
|
||||
//FIXME: make generic
|
||||
auto theme = s->get("IconTheme").toString();
|
||||
QStringList iconThemeOptions{"pe_colored",
|
||||
"pe_light",
|
||||
"pe_dark",
|
||||
"pe_blue",
|
||||
"breeze_light",
|
||||
"breeze_dark",
|
||||
"OSX",
|
||||
"iOS",
|
||||
"flat",
|
||||
"flat_white",
|
||||
"multimc",
|
||||
"custom"};
|
||||
ui->themeComboBox->setCurrentIndex(iconThemeOptions.indexOf(theme));
|
||||
|
||||
auto cat = s->get("BackgroundCat").toString();
|
||||
if (cat == "kitteh") {
|
||||
ui->themeBackgroundCat->setCurrentIndex(0);
|
||||
} else if (cat == "rory") {
|
||||
ui->themeBackgroundCat->setCurrentIndex(1);
|
||||
} else if (cat == "rory-flat") {
|
||||
ui->themeBackgroundCat->setCurrentIndex(2);
|
||||
}
|
||||
|
||||
{
|
||||
auto currentTheme = s->get("ApplicationTheme").toString();
|
||||
auto themes = APPLICATION->getValidApplicationThemes();
|
||||
int idx = 0;
|
||||
for(auto &theme: themes)
|
||||
{
|
||||
ui->themeComboBoxColors->addItem(theme->name(), theme->id());
|
||||
if(currentTheme == theme->id())
|
||||
{
|
||||
ui->themeComboBoxColors->setCurrentIndex(idx);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
// Toolbar/menu bar settings (not applicable if native menu bar is present)
|
||||
ui->toolsBox->setEnabled(!QMenuBar().isNativeMenuBar());
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>514</width>
|
||||
<width>511</width>
|
||||
<height>629</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -38,7 +38,7 @@
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="featuresTab">
|
||||
<attribute name="title">
|
||||
@ -243,150 +243,9 @@
|
||||
<property name="title">
|
||||
<string>Theme</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>&Icons</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>themeComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="themeComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Simple (Colored Icons)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Simple (Light Icons)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Simple (Dark Icons)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Simple (Blue Icons)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Breeze Light</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Breeze Dark</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">OSX</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">iOS</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Flat</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Flat (White)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Legacy</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>&Colors</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>themeComboBoxColors</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="themeComboBoxColors">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>C&at</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>themeBackgroundCat</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="themeBackgroundCat">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Background Cat (from MultiMC)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Rory ID 11 (drawn by Ashtaka)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Rory ID 11 (flat edition, drawn by Ashtaka)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="ThemeCustomizationWidget" name="themeCustomizationWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -570,6 +429,14 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ThemeCustomizationWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ui/widgets/ThemeCustomizationWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>autoUpdateCheckBox</tabstop>
|
||||
@ -582,8 +449,6 @@
|
||||
<tabstop>iconsDirBrowseBtn</tabstop>
|
||||
<tabstop>sortLastLaunchedBtn</tabstop>
|
||||
<tabstop>sortByNameBtn</tabstop>
|
||||
<tabstop>themeComboBox</tabstop>
|
||||
<tabstop>themeComboBoxColors</tabstop>
|
||||
<tabstop>showConsoleCheck</tabstop>
|
||||
<tabstop>autoCloseConsoleCheck</tabstop>
|
||||
<tabstop>showConsoleErrorCheck</tabstop>
|
||||
|
@ -428,6 +428,10 @@ void ModPage::updateUi()
|
||||
text += "<hr>";
|
||||
|
||||
HoeDown h;
|
||||
|
||||
// hoedown bug: it doesn't handle markdown surrounded by block tags (like center, div) so strip them
|
||||
current.extraData.body.remove(QRegularExpression("<[^>]*(?:center|div)\\W*>"));
|
||||
|
||||
ui->packDescription->setHtml(text + (current.extraData.body.isEmpty() ? current.description : h.process(current.extraData.body.toUtf8())));
|
||||
ui->packDescription->flush();
|
||||
}
|
||||
|
@ -13,7 +13,8 @@
|
||||
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
|
||||
{
|
||||
setObjectName(QStringLiteral("SetupWizard"));
|
||||
resize(615, 659);
|
||||
resize(620, 660);
|
||||
setMinimumSize(300, 400);
|
||||
// make it ugly everywhere to avoid variability in theming
|
||||
setWizardStyle(QWizard::ClassicStyle);
|
||||
setOptions(QWizard::NoCancelButton | QWizard::IndependentPages | QWizard::HaveCustomButton1);
|
||||
|
70
launcher/ui/setupwizard/ThemeWizardPage.cpp
Normal file
70
launcher/ui/setupwizard/ThemeWizardPage.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 "ThemeWizardPage.h"
|
||||
#include "ui_ThemeWizardPage.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "ui/themes/ITheme.h"
|
||||
#include "ui/themes/ThemeManager.h"
|
||||
#include "ui/widgets/ThemeCustomizationWidget.h"
|
||||
#include "ui_ThemeCustomizationWidget.h"
|
||||
|
||||
ThemeWizardPage::ThemeWizardPage(QWidget* parent) : BaseWizardPage(parent), ui(new Ui::ThemeWizardPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentIconThemeChanged, this, &ThemeWizardPage::updateIcons);
|
||||
connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentCatChanged, this, &ThemeWizardPage::updateCat);
|
||||
|
||||
updateIcons();
|
||||
updateCat();
|
||||
}
|
||||
|
||||
ThemeWizardPage::~ThemeWizardPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ThemeWizardPage::updateIcons()
|
||||
{
|
||||
qDebug() << "Setting Icons";
|
||||
ui->previewIconButton0->setIcon(APPLICATION->getThemedIcon("new"));
|
||||
ui->previewIconButton1->setIcon(APPLICATION->getThemedIcon("centralmods"));
|
||||
ui->previewIconButton2->setIcon(APPLICATION->getThemedIcon("viewfolder"));
|
||||
ui->previewIconButton3->setIcon(APPLICATION->getThemedIcon("launch"));
|
||||
ui->previewIconButton4->setIcon(APPLICATION->getThemedIcon("copy"));
|
||||
ui->previewIconButton5->setIcon(APPLICATION->getThemedIcon("export"));
|
||||
ui->previewIconButton6->setIcon(APPLICATION->getThemedIcon("delete"));
|
||||
ui->previewIconButton7->setIcon(APPLICATION->getThemedIcon("about"));
|
||||
ui->previewIconButton8->setIcon(APPLICATION->getThemedIcon("settings"));
|
||||
ui->previewIconButton9->setIcon(APPLICATION->getThemedIcon("cat"));
|
||||
update();
|
||||
repaint();
|
||||
parentWidget()->update();
|
||||
}
|
||||
|
||||
void ThemeWizardPage::updateCat()
|
||||
{
|
||||
qDebug() << "Setting Cat";
|
||||
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(:/backgrounds/%1)").arg(ThemeManager::getCatImage())));
|
||||
}
|
||||
|
||||
void ThemeWizardPage::retranslate()
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
43
launcher/ui/setupwizard/ThemeWizardPage.h
Normal file
43
launcher/ui/setupwizard/ThemeWizardPage.h
Normal file
@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 <QWidget>
|
||||
#include "BaseWizardPage.h"
|
||||
|
||||
namespace Ui {
|
||||
class ThemeWizardPage;
|
||||
}
|
||||
|
||||
class ThemeWizardPage : public BaseWizardPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ThemeWizardPage(QWidget* parent = nullptr);
|
||||
~ThemeWizardPage();
|
||||
|
||||
bool validatePage() override { return true; };
|
||||
void retranslate() override;
|
||||
|
||||
private slots:
|
||||
void updateIcons();
|
||||
void updateCat();
|
||||
|
||||
private:
|
||||
Ui::ThemeWizardPage* ui;
|
||||
};
|
371
launcher/ui/setupwizard/ThemeWizardPage.ui
Normal file
371
launcher/ui/setupwizard/ThemeWizardPage.ui
Normal file
@ -0,0 +1,371 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ThemeWizardPage</class>
|
||||
<widget class="QWizardPage" name="ThemeWizardPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>510</width>
|
||||
<height>552</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>WizardPage</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Select the Theme you wish to use</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ThemeCustomizationWidget" name="themeCustomizationWidget" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Hint: The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string> Preview:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="iconPreview">
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="previewIconButton2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<widget class="QPushButton" name="previewIconButton5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="7">
|
||||
<widget class="QPushButton" name="previewIconButton7">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QPushButton" name="previewIconButton4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="previewIconButton1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="centralmods">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="previewIconButton0">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="9">
|
||||
<widget class="QPushButton" name="previewIconButton9">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="viewfolder">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<widget class="QPushButton" name="previewIconButton6">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="new">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="previewIconButton3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="8">
|
||||
<widget class="QPushButton" name="previewIconButton8">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="applications-engineering">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="catImagePreviewButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>256</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The cat appears in the background and does not serve a purpose, it is purely visual.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>256</width>
|
||||
<height>256</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>193</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ThemeCustomizationWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ui/widgets/ThemeCustomizationWidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -167,8 +167,6 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest
|
||||
|
||||
if (!FS::ensureFolderPathExists(path) || !FS::ensureFolderPathExists(pathResources)) {
|
||||
themeWarningLog() << "couldn't create folder for theme!";
|
||||
m_palette = baseTheme->colorScheme();
|
||||
m_styleSheet = baseTheme->appStyleSheet();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -177,18 +175,15 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest
|
||||
bool jsonDataIncomplete = false;
|
||||
|
||||
m_palette = baseTheme->colorScheme();
|
||||
if (!readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) {
|
||||
themeDebugLog() << "Did not read theme json file correctly, writing new one to: " << themeFilePath;
|
||||
m_name = "Custom";
|
||||
m_palette = baseTheme->colorScheme();
|
||||
m_fadeColor = baseTheme->fadeColor();
|
||||
m_fadeAmount = baseTheme->fadeAmount();
|
||||
m_widgets = baseTheme->qtTheme();
|
||||
m_qssFilePath = "themeStyle.css";
|
||||
} else {
|
||||
if (readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) {
|
||||
// If theme data was found, fade "Disabled" color of each role according to FadeAmount
|
||||
m_palette = fadeInactive(m_palette, m_fadeAmount, m_fadeColor);
|
||||
} else {
|
||||
themeDebugLog() << "Did not read theme json file correctly, not changing theme, keeping previous.";
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: This is kinda jank, it only actually checks if the qss file path is not present. It should actually check for any relevant missing data (e.g. name, colors)
|
||||
if (jsonDataIncomplete) {
|
||||
writeThemeJson(fileInfo.absoluteFilePath(), m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath);
|
||||
}
|
||||
@ -197,20 +192,14 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest
|
||||
QFileInfo info(qssFilePath);
|
||||
if (info.isFile()) {
|
||||
try {
|
||||
// TODO: validate css?
|
||||
// TODO: validate qss?
|
||||
m_styleSheet = QString::fromUtf8(FS::read(qssFilePath));
|
||||
} catch (const Exception& e) {
|
||||
themeWarningLog() << "Couldn't load css:" << e.cause() << "from" << qssFilePath;
|
||||
m_styleSheet = baseTheme->appStyleSheet();
|
||||
themeWarningLog() << "Couldn't load qss:" << e.cause() << "from" << qssFilePath;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
themeDebugLog() << "No theme css present.";
|
||||
m_styleSheet = baseTheme->appStyleSheet();
|
||||
try {
|
||||
FS::write(qssFilePath, m_styleSheet.toUtf8());
|
||||
} catch (const Exception& e) {
|
||||
themeWarningLog() << "Couldn't write css:" << e.cause() << "to" << qssFilePath;
|
||||
}
|
||||
themeDebugLog() << "No theme qss present.";
|
||||
}
|
||||
} else {
|
||||
m_id = fileInfo.fileName();
|
||||
|
@ -1,19 +1,51 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 "ITheme.h"
|
||||
#include "rainbow.h"
|
||||
#include <QStyleFactory>
|
||||
#include <QDir>
|
||||
#include "Application.h"
|
||||
|
||||
void ITheme::apply(bool)
|
||||
void ITheme::apply()
|
||||
{
|
||||
APPLICATION->setStyleSheet(QString());
|
||||
QApplication::setStyle(QStyleFactory::create(qtTheme()));
|
||||
if (hasColorScheme()) {
|
||||
QApplication::setPalette(colorScheme());
|
||||
}
|
||||
if (hasStyleSheet())
|
||||
APPLICATION->setStyleSheet(appStyleSheet());
|
||||
|
||||
APPLICATION->setStyleSheet(appStyleSheet());
|
||||
QDir::setSearchPaths("theme", searchPaths());
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 <QString>
|
||||
#include <QPalette>
|
||||
#include <QString>
|
||||
|
||||
class QStyle;
|
||||
|
||||
class ITheme
|
||||
{
|
||||
public:
|
||||
class ITheme {
|
||||
public:
|
||||
virtual ~ITheme() {}
|
||||
virtual void apply(bool initial);
|
||||
virtual void apply();
|
||||
virtual QString id() = 0;
|
||||
virtual QString name() = 0;
|
||||
virtual bool hasStyleSheet() = 0;
|
||||
@ -18,10 +51,7 @@ public:
|
||||
virtual QPalette colorScheme() = 0;
|
||||
virtual QColor fadeColor() = 0;
|
||||
virtual double fadeAmount() = 0;
|
||||
virtual QStringList searchPaths()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
virtual QStringList searchPaths() { return {}; }
|
||||
|
||||
static QPalette fadeInactive(QPalette in, qreal bias, QColor color);
|
||||
};
|
||||
|
@ -34,24 +34,22 @@
|
||||
*/
|
||||
#include "SystemTheme.h"
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QStyle>
|
||||
#include <QStyleFactory>
|
||||
#include <QDebug>
|
||||
#include "ThemeManager.h"
|
||||
|
||||
SystemTheme::SystemTheme()
|
||||
{
|
||||
themeDebugLog() << "Determining System Theme...";
|
||||
const auto & style = QApplication::style();
|
||||
const auto& style = QApplication::style();
|
||||
systemPalette = style->standardPalette();
|
||||
QString lowerThemeName = style->objectName();
|
||||
themeDebugLog() << "System theme seems to be:" << lowerThemeName;
|
||||
QStringList styles = QStyleFactory::keys();
|
||||
for(auto &st: styles)
|
||||
{
|
||||
for (auto& st : styles) {
|
||||
themeDebugLog() << "Considering theme from theme factory:" << st.toLower();
|
||||
if(st.toLower() == lowerThemeName)
|
||||
{
|
||||
if (st.toLower() == lowerThemeName) {
|
||||
systemTheme = st;
|
||||
themeDebugLog() << "System theme has been determined to be:" << systemTheme;
|
||||
return;
|
||||
@ -62,14 +60,9 @@ SystemTheme::SystemTheme()
|
||||
themeDebugLog() << "System theme not found, defaulted to Fusion";
|
||||
}
|
||||
|
||||
void SystemTheme::apply(bool initial)
|
||||
void SystemTheme::apply()
|
||||
{
|
||||
// if we are applying the system theme as the first theme, just don't touch anything. it's for the better...
|
||||
if(initial)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ITheme::apply(initial);
|
||||
ITheme::apply();
|
||||
}
|
||||
|
||||
QString SystemTheme::id()
|
||||
@ -104,7 +97,7 @@ double SystemTheme::fadeAmount()
|
||||
|
||||
QColor SystemTheme::fadeColor()
|
||||
{
|
||||
return QColor(128,128,128);
|
||||
return QColor(128, 128, 128);
|
||||
}
|
||||
|
||||
bool SystemTheme::hasStyleSheet()
|
||||
|
@ -1,13 +1,46 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 "ITheme.h"
|
||||
|
||||
class SystemTheme: public ITheme
|
||||
{
|
||||
public:
|
||||
class SystemTheme : public ITheme {
|
||||
public:
|
||||
SystemTheme();
|
||||
virtual ~SystemTheme() {}
|
||||
void apply(bool initial) override;
|
||||
void apply() override;
|
||||
|
||||
QString id() override;
|
||||
QString name() override;
|
||||
@ -18,7 +51,8 @@ public:
|
||||
QPalette colorScheme() override;
|
||||
double fadeAmount() override;
|
||||
QColor fadeColor() override;
|
||||
private:
|
||||
|
||||
private:
|
||||
QPalette systemPalette;
|
||||
QString systemTheme;
|
||||
};
|
||||
|
@ -1,155 +1,155 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 "ThemeManager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QIcon>
|
||||
#include "ui/themes/BrightTheme.h"
|
||||
#include "ui/themes/CustomTheme.h"
|
||||
#include "ui/themes/DarkTheme.h"
|
||||
#include "ui/themes/SystemTheme.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
// this is needed for versionhelpers.h, it is also included in WinDarkmode, but we can't rely on that.
|
||||
// Ultimately this should be included in versionhelpers, but that is outside of the project.
|
||||
#include "ui/WinDarkmode.h"
|
||||
#include <versionhelpers.h>
|
||||
#endif
|
||||
|
||||
ThemeManager::ThemeManager(MainWindow* mainWindow)
|
||||
{
|
||||
m_mainWindow = mainWindow;
|
||||
InitializeThemes();
|
||||
}
|
||||
|
||||
/// @brief Adds the Theme to the list of themes
|
||||
/// @param theme The Theme to add
|
||||
/// @return Theme ID
|
||||
QString ThemeManager::AddTheme(std::unique_ptr<ITheme> theme)
|
||||
{
|
||||
QString id = theme->id();
|
||||
m_themes.emplace(id, std::move(theme));
|
||||
return id;
|
||||
}
|
||||
|
||||
/// @brief Gets the Theme from the List via ID
|
||||
/// @param themeId Theme ID of theme to fetch
|
||||
/// @return Theme at themeId
|
||||
ITheme* ThemeManager::GetTheme(QString themeId)
|
||||
{
|
||||
return m_themes[themeId].get();
|
||||
}
|
||||
|
||||
void ThemeManager::InitializeThemes()
|
||||
{
|
||||
// Icon themes
|
||||
{
|
||||
// TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
|
||||
// set icon theme search path!
|
||||
auto searchPaths = QIcon::themeSearchPaths();
|
||||
searchPaths.append("iconthemes");
|
||||
QIcon::setThemeSearchPaths(searchPaths);
|
||||
themeDebugLog() << "<> Icon themes initialized.";
|
||||
}
|
||||
|
||||
// Initialize widget themes
|
||||
{
|
||||
themeDebugLog() << "<> Initializing Widget Themes";
|
||||
themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<SystemTheme>());
|
||||
auto darkThemeId = AddTheme(std::make_unique<DarkTheme>());
|
||||
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
|
||||
themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<BrightTheme>());
|
||||
|
||||
// TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
|
||||
// dropdown?)
|
||||
QString themeFolder = QDir("./themes/").absoluteFilePath("");
|
||||
themeDebugLog() << "Theme Folder Path: " << themeFolder;
|
||||
|
||||
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||
while (directoryIterator.hasNext()) {
|
||||
QDir dir(directoryIterator.next());
|
||||
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
|
||||
if (themeJson.exists()) {
|
||||
// Load "theme.json" based themes
|
||||
themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
|
||||
AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), themeJson, true));
|
||||
} else {
|
||||
// Load pure QSS Themes
|
||||
QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
|
||||
while (stylesheetFileIterator.hasNext()) {
|
||||
QFile customThemeFile(stylesheetFileIterator.next());
|
||||
QFileInfo customThemeFileInfo(customThemeFile);
|
||||
themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
|
||||
AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), customThemeFileInfo, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
themeDebugLog() << "<> Widget themes initialized.";
|
||||
}
|
||||
}
|
||||
|
||||
QList<ITheme*> ThemeManager::getValidApplicationThemes()
|
||||
{
|
||||
QList<ITheme*> ret;
|
||||
ret.reserve(m_themes.size());
|
||||
for (auto&& [id, theme] : m_themes) {
|
||||
ret.append(theme.get());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ThemeManager::setIconTheme(const QString& name)
|
||||
{
|
||||
QIcon::setThemeName(name);
|
||||
}
|
||||
|
||||
void ThemeManager::applyCurrentlySelectedTheme()
|
||||
{
|
||||
setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
|
||||
themeDebugLog() << "<> Icon theme set.";
|
||||
setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), true);
|
||||
themeDebugLog() << "<> Application theme set.";
|
||||
}
|
||||
|
||||
void ThemeManager::setApplicationTheme(const QString& name, bool initial)
|
||||
{
|
||||
auto systemPalette = qApp->palette();
|
||||
auto themeIter = m_themes.find(name);
|
||||
if (themeIter != m_themes.end()) {
|
||||
auto& theme = themeIter->second;
|
||||
themeDebugLog() << "applying theme" << theme->name();
|
||||
theme->apply(initial);
|
||||
#ifdef Q_OS_WIN
|
||||
if (m_mainWindow && IsWindows10OrGreater()) {
|
||||
if (QString::compare(theme->id(), "dark") == 0) {
|
||||
WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true);
|
||||
} else {
|
||||
WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
themeWarningLog() << "Tried to set invalid theme:" << name;
|
||||
}
|
||||
}
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 "ThemeManager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QIcon>
|
||||
#include "ui/themes/BrightTheme.h"
|
||||
#include "ui/themes/CustomTheme.h"
|
||||
#include "ui/themes/DarkTheme.h"
|
||||
#include "ui/themes/SystemTheme.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
ThemeManager::ThemeManager(MainWindow* mainWindow)
|
||||
{
|
||||
m_mainWindow = mainWindow;
|
||||
initializeThemes();
|
||||
}
|
||||
|
||||
/// @brief Adds the Theme to the list of themes
|
||||
/// @param theme The Theme to add
|
||||
/// @return Theme ID
|
||||
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
|
||||
{
|
||||
QString id = theme->id();
|
||||
m_themes.emplace(id, std::move(theme));
|
||||
return id;
|
||||
}
|
||||
|
||||
/// @brief Gets the Theme from the List via ID
|
||||
/// @param themeId Theme ID of theme to fetch
|
||||
/// @return Theme at themeId
|
||||
ITheme* ThemeManager::getTheme(QString themeId)
|
||||
{
|
||||
return m_themes[themeId].get();
|
||||
}
|
||||
|
||||
void ThemeManager::initializeThemes()
|
||||
{
|
||||
// Icon themes
|
||||
{
|
||||
// TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
|
||||
// set icon theme search path!
|
||||
auto searchPaths = QIcon::themeSearchPaths();
|
||||
searchPaths.append("iconthemes");
|
||||
QIcon::setThemeSearchPaths(searchPaths);
|
||||
themeDebugLog() << "<> Icon themes initialized.";
|
||||
}
|
||||
|
||||
// Initialize widget themes
|
||||
{
|
||||
themeDebugLog() << "<> Initializing Widget Themes";
|
||||
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
|
||||
auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
|
||||
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
|
||||
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
|
||||
|
||||
// TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
|
||||
// dropdown?)
|
||||
QString themeFolder = QDir("./themes/").absoluteFilePath("");
|
||||
themeDebugLog() << "Theme Folder Path: " << themeFolder;
|
||||
|
||||
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||
while (directoryIterator.hasNext()) {
|
||||
QDir dir(directoryIterator.next());
|
||||
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
|
||||
if (themeJson.exists()) {
|
||||
// Load "theme.json" based themes
|
||||
themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
|
||||
addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
|
||||
} else {
|
||||
// Load pure QSS Themes
|
||||
QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
|
||||
while (stylesheetFileIterator.hasNext()) {
|
||||
QFile customThemeFile(stylesheetFileIterator.next());
|
||||
QFileInfo customThemeFileInfo(customThemeFile);
|
||||
themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
|
||||
addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
themeDebugLog() << "<> Widget themes initialized.";
|
||||
}
|
||||
}
|
||||
|
||||
QList<ITheme*> ThemeManager::getValidApplicationThemes()
|
||||
{
|
||||
QList<ITheme*> ret;
|
||||
ret.reserve(m_themes.size());
|
||||
for (auto&& [id, theme] : m_themes) {
|
||||
ret.append(theme.get());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ThemeManager::setIconTheme(const QString& name)
|
||||
{
|
||||
QIcon::setThemeName(name);
|
||||
}
|
||||
|
||||
void ThemeManager::applyCurrentlySelectedTheme()
|
||||
{
|
||||
setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
|
||||
themeDebugLog() << "<> Icon theme set.";
|
||||
setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString());
|
||||
themeDebugLog() << "<> Application theme set.";
|
||||
}
|
||||
|
||||
void ThemeManager::setApplicationTheme(const QString& name)
|
||||
{
|
||||
auto systemPalette = qApp->palette();
|
||||
auto themeIter = m_themes.find(name);
|
||||
if (themeIter != m_themes.end()) {
|
||||
auto& theme = themeIter->second;
|
||||
themeDebugLog() << "applying theme" << theme->name();
|
||||
theme->apply();
|
||||
} else {
|
||||
themeWarningLog() << "Tried to set invalid theme:" << name;
|
||||
}
|
||||
}
|
||||
|
||||
QString ThemeManager::getCatImage(QString catName)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
|
||||
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
|
||||
QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
|
||||
QString cat = !catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString();
|
||||
if (std::abs(now.daysTo(xmas)) <= 4) {
|
||||
cat += "-xmas";
|
||||
} else if (std::abs(now.daysTo(halloween)) <= 4) {
|
||||
cat += "-spooky";
|
||||
} else if (std::abs(now.daysTo(birthday)) <= 12) {
|
||||
cat += "-bday";
|
||||
}
|
||||
return cat;
|
||||
}
|
||||
|
@ -1,52 +1,57 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 <QString>
|
||||
|
||||
#include "ui/MainWindow.h"
|
||||
#include "ui/themes/ITheme.h"
|
||||
|
||||
inline auto themeDebugLog()
|
||||
{
|
||||
return qDebug() << "[Theme]";
|
||||
}
|
||||
inline auto themeWarningLog()
|
||||
{
|
||||
return qWarning() << "[Theme]";
|
||||
}
|
||||
|
||||
class ThemeManager {
|
||||
public:
|
||||
ThemeManager(MainWindow* mainWindow);
|
||||
|
||||
// maybe make private? Or put in ctor?
|
||||
void InitializeThemes();
|
||||
|
||||
QList<ITheme*> getValidApplicationThemes();
|
||||
void setIconTheme(const QString& name);
|
||||
void applyCurrentlySelectedTheme();
|
||||
void setApplicationTheme(const QString& name, bool initial);
|
||||
|
||||
private:
|
||||
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
||||
MainWindow* m_mainWindow;
|
||||
|
||||
QString AddTheme(std::unique_ptr<ITheme> theme);
|
||||
ITheme* GetTheme(QString themeId);
|
||||
};
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 <QString>
|
||||
|
||||
#include "ui/MainWindow.h"
|
||||
#include "ui/themes/ITheme.h"
|
||||
|
||||
inline auto themeDebugLog()
|
||||
{
|
||||
return qDebug() << "[Theme]";
|
||||
}
|
||||
inline auto themeWarningLog()
|
||||
{
|
||||
return qWarning() << "[Theme]";
|
||||
}
|
||||
|
||||
class ThemeManager {
|
||||
public:
|
||||
ThemeManager(MainWindow* mainWindow);
|
||||
|
||||
QList<ITheme*> getValidApplicationThemes();
|
||||
void setIconTheme(const QString& name);
|
||||
void applyCurrentlySelectedTheme();
|
||||
void setApplicationTheme(const QString& name);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
||||
/// </summary>
|
||||
/// <param name="catName">Optional, if you need a specific cat.</param>
|
||||
/// <returns></returns>
|
||||
static QString getCatImage(QString catName = "");
|
||||
|
||||
private:
|
||||
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
||||
MainWindow* m_mainWindow;
|
||||
|
||||
void initializeThemes();
|
||||
QString addTheme(std::unique_ptr<ITheme> theme);
|
||||
ITheme* getTheme(QString themeId);
|
||||
};
|
||||
|
150
launcher/ui/widgets/ThemeCustomizationWidget.cpp
Normal file
150
launcher/ui/widgets/ThemeCustomizationWidget.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 "ThemeCustomizationWidget.h"
|
||||
#include "ui_ThemeCustomizationWidget.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "ui/themes/ITheme.h"
|
||||
#include "ui/themes/ThemeManager.h"
|
||||
|
||||
ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
loadSettings();
|
||||
|
||||
connect(ui->iconsComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyIconTheme);
|
||||
connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyWidgetTheme);
|
||||
connect(ui->backgroundCatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyCatTheme);
|
||||
}
|
||||
|
||||
ThemeCustomizationWidget::~ThemeCustomizationWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The layout was not quite right, so currently this just disables the UI elements, which should be hidden instead
|
||||
/// TODO FIXME
|
||||
///
|
||||
/// Original Method One:
|
||||
/// ui->iconsComboBox->setVisible(features& ThemeFields::ICONS);
|
||||
/// ui->iconsLabel->setVisible(features& ThemeFields::ICONS);
|
||||
/// ui->widgetStyleComboBox->setVisible(features& ThemeFields::WIDGETS);
|
||||
/// ui->widgetThemeLabel->setVisible(features& ThemeFields::WIDGETS);
|
||||
/// ui->backgroundCatComboBox->setVisible(features& ThemeFields::CAT);
|
||||
/// ui->backgroundCatLabel->setVisible(features& ThemeFields::CAT);
|
||||
///
|
||||
/// original Method Two:
|
||||
/// if (!(features & ThemeFields::ICONS)) {
|
||||
/// ui->formLayout->setRowVisible(0, false);
|
||||
/// }
|
||||
/// if (!(features & ThemeFields::WIDGETS)) {
|
||||
/// ui->formLayout->setRowVisible(1, false);
|
||||
/// }
|
||||
/// if (!(features & ThemeFields::CAT)) {
|
||||
/// ui->formLayout->setRowVisible(2, false);
|
||||
/// }
|
||||
/// </summary>
|
||||
/// <param name="features"></param>
|
||||
void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
|
||||
ui->iconsComboBox->setEnabled(features & ThemeFields::ICONS);
|
||||
ui->iconsLabel->setEnabled(features & ThemeFields::ICONS);
|
||||
ui->widgetStyleComboBox->setEnabled(features & ThemeFields::WIDGETS);
|
||||
ui->widgetThemeLabel->setEnabled(features & ThemeFields::WIDGETS);
|
||||
ui->backgroundCatComboBox->setEnabled(features & ThemeFields::CAT);
|
||||
ui->backgroundCatLabel->setEnabled(features & ThemeFields::CAT);
|
||||
}
|
||||
|
||||
void ThemeCustomizationWidget::applyIconTheme(int index) {
|
||||
auto settings = APPLICATION->settings();
|
||||
auto originalIconTheme = settings->get("IconTheme").toString();
|
||||
auto& newIconTheme = m_iconThemeOptions[index].first;
|
||||
settings->set("IconTheme", newIconTheme);
|
||||
|
||||
if (originalIconTheme != newIconTheme) {
|
||||
APPLICATION->applyCurrentlySelectedTheme();
|
||||
}
|
||||
|
||||
emit currentIconThemeChanged(index);
|
||||
}
|
||||
|
||||
void ThemeCustomizationWidget::applyWidgetTheme(int index) {
|
||||
auto settings = APPLICATION->settings();
|
||||
auto originalAppTheme = settings->get("ApplicationTheme").toString();
|
||||
auto newAppTheme = ui->widgetStyleComboBox->currentData().toString();
|
||||
if (originalAppTheme != newAppTheme) {
|
||||
settings->set("ApplicationTheme", newAppTheme);
|
||||
APPLICATION->applyCurrentlySelectedTheme();
|
||||
}
|
||||
|
||||
emit currentWidgetThemeChanged(index);
|
||||
}
|
||||
|
||||
void ThemeCustomizationWidget::applyCatTheme(int index) {
|
||||
auto settings = APPLICATION->settings();
|
||||
settings->set("BackgroundCat", m_catOptions[index].first);
|
||||
|
||||
emit currentCatChanged(index);
|
||||
}
|
||||
|
||||
void ThemeCustomizationWidget::applySettings()
|
||||
{
|
||||
applyIconTheme(ui->iconsComboBox->currentIndex());
|
||||
applyWidgetTheme(ui->widgetStyleComboBox->currentIndex());
|
||||
applyCatTheme(ui->backgroundCatComboBox->currentIndex());
|
||||
}
|
||||
void ThemeCustomizationWidget::loadSettings()
|
||||
{
|
||||
auto settings = APPLICATION->settings();
|
||||
|
||||
auto iconTheme = settings->get("IconTheme").toString();
|
||||
for (auto& iconThemeFromList : m_iconThemeOptions) {
|
||||
QIcon iconForComboBox = QIcon(QString(":/icons/%1/scalable/settings").arg(iconThemeFromList.first));
|
||||
ui->iconsComboBox->addItem(iconForComboBox, iconThemeFromList.second);
|
||||
if (iconTheme == iconThemeFromList.first) {
|
||||
ui->iconsComboBox->setCurrentIndex(ui->iconsComboBox->count() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto currentTheme = settings->get("ApplicationTheme").toString();
|
||||
auto themes = APPLICATION->getValidApplicationThemes();
|
||||
int idx = 0;
|
||||
for (auto& theme : themes) {
|
||||
ui->widgetStyleComboBox->addItem(theme->name(), theme->id());
|
||||
if (currentTheme == theme->id()) {
|
||||
ui->widgetStyleComboBox->setCurrentIndex(idx);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
auto cat = settings->get("BackgroundCat").toString();
|
||||
for (auto& catFromList : m_catOptions) {
|
||||
QIcon catIcon = QIcon(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage(catFromList.first)));
|
||||
ui->backgroundCatComboBox->addItem(catIcon, catFromList.second);
|
||||
if (cat == catFromList.first) {
|
||||
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThemeCustomizationWidget::retranslate()
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
77
launcher/ui/widgets/ThemeCustomizationWidget.h
Normal file
77
launcher/ui/widgets/ThemeCustomizationWidget.h
Normal file
@ -0,0 +1,77 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Tayou <tayou@gmx.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 <QWidget>
|
||||
#include "translations/TranslationsModel.h"
|
||||
|
||||
enum ThemeFields { NONE = 0b0000, ICONS = 0b0001, WIDGETS = 0b0010, CAT = 0b0100 };
|
||||
|
||||
namespace Ui {
|
||||
class ThemeCustomizationWidget;
|
||||
}
|
||||
|
||||
class ThemeCustomizationWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ThemeCustomizationWidget(QWidget* parent = nullptr);
|
||||
~ThemeCustomizationWidget();
|
||||
|
||||
void showFeatures(ThemeFields features);
|
||||
|
||||
void applySettings();
|
||||
|
||||
void loadSettings();
|
||||
void retranslate();
|
||||
|
||||
private slots:
|
||||
void applyIconTheme(int index);
|
||||
void applyWidgetTheme(int index);
|
||||
void applyCatTheme(int index);
|
||||
|
||||
signals:
|
||||
int currentIconThemeChanged(int index);
|
||||
int currentWidgetThemeChanged(int index);
|
||||
int currentCatChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::ThemeCustomizationWidget* ui;
|
||||
|
||||
//TODO finish implementing
|
||||
QList<std::pair<QString, QString>> m_iconThemeOptions{
|
||||
{ "pe_colored", QObject::tr("Simple (Colored Icons)") },
|
||||
{ "pe_light", QObject::tr("Simple (Light Icons)") },
|
||||
{ "pe_dark", QObject::tr("Simple (Dark Icons)") },
|
||||
{ "pe_blue", QObject::tr("Simple (Blue Icons)") },
|
||||
{ "breeze_light", QObject::tr("Breeze Light") },
|
||||
{ "breeze_dark", QObject::tr("Breeze Dark") },
|
||||
{ "OSX", QObject::tr("OSX") },
|
||||
{ "iOS", QObject::tr("iOS") },
|
||||
{ "flat", QObject::tr("Flat") },
|
||||
{ "flat_white", QObject::tr("Flat (White)") },
|
||||
{ "multimc", QObject::tr("Legacy") },
|
||||
{ "custom", QObject::tr("Custom") }
|
||||
};
|
||||
QList<std::pair<QString, QString>> m_catOptions{
|
||||
{ "kitteh", QObject::tr("Background Cat (from MultiMC)") },
|
||||
{ "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
|
||||
{ "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
|
||||
{ "teawie", QObject::tr("Teawie (drawn by SympathyTea)") }
|
||||
};
|
||||
};
|
132
launcher/ui/widgets/ThemeCustomizationWidget.ui
Normal file
132
launcher/ui/widgets/ThemeCustomizationWidget.ui
Normal file
@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ThemeCustomizationWidget</class>
|
||||
<widget class="QWidget" name="ThemeCustomizationWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Form</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="iconsLabel">
|
||||
<property name="text">
|
||||
<string>&Icons</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>iconsComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="iconsComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="widgetThemeLabel">
|
||||
<property name="text">
|
||||
<string>&Colors</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>widgetStyleComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="widgetStyleComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="backgroundCatLabel">
|
||||
<property name="toolTip">
|
||||
<string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>C&at</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>backgroundCatComboBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="backgroundCatComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="catInfoLabel">
|
||||
<property name="toolTip">
|
||||
<string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="about">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -27,6 +27,15 @@ ecm_add_test(ResourcePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VER
|
||||
ecm_add_test(TexturePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME TexturePackParse)
|
||||
|
||||
ecm_add_test(DataPackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME DataPackParse)
|
||||
|
||||
ecm_add_test(ShaderPackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME ShaderPackParse)
|
||||
|
||||
ecm_add_test(WorldSaveParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME WorldSaveParse)
|
||||
|
||||
ecm_add_test(ParseUtils_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME ParseUtils)
|
||||
|
||||
|
79
tests/DataPackParse_test.cpp
Normal file
79
tests/DataPackParse_test.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
// 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 <QTest>
|
||||
#include <QTimer>
|
||||
|
||||
#include <FileSystem.h>
|
||||
|
||||
#include <minecraft/mod/DataPack.h>
|
||||
#include <minecraft/mod/tasks/LocalDataPackParseTask.h>
|
||||
|
||||
class DataPackParseTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void test_parseZIP()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/DataPackParse");
|
||||
|
||||
QString zip_dp = FS::PathCombine(source, "test_data_pack_boogaloo.zip");
|
||||
DataPack pack { QFileInfo(zip_dp) };
|
||||
|
||||
bool valid = DataPackUtils::processZIP(pack);
|
||||
|
||||
QVERIFY(pack.packFormat() == 4);
|
||||
QVERIFY(pack.description() == "Some data pack 2 boobgaloo");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/DataPackParse");
|
||||
|
||||
QString folder_dp = FS::PathCombine(source, "test_folder");
|
||||
DataPack pack { QFileInfo(folder_dp) };
|
||||
|
||||
bool valid = DataPackUtils::processFolder(pack);
|
||||
|
||||
QVERIFY(pack.packFormat() == 10);
|
||||
QVERIFY(pack.description() == "Some data pack, maybe");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder2()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/DataPackParse");
|
||||
|
||||
QString folder_dp = FS::PathCombine(source, "another_test_folder");
|
||||
DataPack pack { QFileInfo(folder_dp) };
|
||||
|
||||
bool valid = DataPackUtils::process(pack);
|
||||
|
||||
QVERIFY(pack.packFormat() == 6);
|
||||
QVERIFY(pack.description() == "Some data pack three, leaves on the tree");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(DataPackParseTest)
|
||||
|
||||
#include "DataPackParse_test.moc"
|
@ -35,10 +35,11 @@ class ResourcePackParseTest : public QObject {
|
||||
QString zip_rp = FS::PathCombine(source, "test_resource_pack_idk.zip");
|
||||
ResourcePack pack { QFileInfo(zip_rp) };
|
||||
|
||||
ResourcePackUtils::processZIP(pack);
|
||||
bool valid = ResourcePackUtils::processZIP(pack, ResourcePackUtils::ProcessingLevel::BasicInfoOnly);
|
||||
|
||||
QVERIFY(pack.packFormat() == 3);
|
||||
QVERIFY(pack.description() == "um dois, feijão com arroz, três quatro, feijão no prato, cinco seis, café inglês, sete oito, comer biscoito, nove dez comer pastéis!!");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder()
|
||||
@ -48,10 +49,11 @@ class ResourcePackParseTest : public QObject {
|
||||
QString folder_rp = FS::PathCombine(source, "test_folder");
|
||||
ResourcePack pack { QFileInfo(folder_rp) };
|
||||
|
||||
ResourcePackUtils::processFolder(pack);
|
||||
bool valid = ResourcePackUtils::processFolder(pack, ResourcePackUtils::ProcessingLevel::BasicInfoOnly);
|
||||
|
||||
QVERIFY(pack.packFormat() == 1);
|
||||
QVERIFY(pack.description() == "Some resource pack maybe");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder2()
|
||||
@ -61,10 +63,11 @@ class ResourcePackParseTest : public QObject {
|
||||
QString folder_rp = FS::PathCombine(source, "another_test_folder");
|
||||
ResourcePack pack { QFileInfo(folder_rp) };
|
||||
|
||||
ResourcePackUtils::process(pack);
|
||||
bool valid = ResourcePackUtils::process(pack, ResourcePackUtils::ProcessingLevel::BasicInfoOnly);
|
||||
|
||||
QVERIFY(pack.packFormat() == 6);
|
||||
QVERIFY(pack.description() == "o quartel pegou fogo, policia deu sinal, acode acode acode a bandeira nacional");
|
||||
QVERIFY(valid == false); // no assets dir
|
||||
}
|
||||
};
|
||||
|
||||
|
77
tests/ShaderPackParse_test.cpp
Normal file
77
tests/ShaderPackParse_test.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
// 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 <QTest>
|
||||
#include <QTimer>
|
||||
|
||||
#include <FileSystem.h>
|
||||
|
||||
#include <minecraft/mod/ShaderPack.h>
|
||||
#include <minecraft/mod/tasks/LocalShaderPackParseTask.h>
|
||||
|
||||
class ShaderPackParseTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void test_parseZIP()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/ShaderPackParse");
|
||||
|
||||
QString zip_sp = FS::PathCombine(source, "shaderpack1.zip");
|
||||
ShaderPack pack { QFileInfo(zip_sp) };
|
||||
|
||||
bool valid = ShaderPackUtils::processZIP(pack);
|
||||
|
||||
QVERIFY(pack.packFormat() == ShaderPackFormat::VALID);
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/ShaderPackParse");
|
||||
|
||||
QString folder_sp = FS::PathCombine(source, "shaderpack2");
|
||||
ShaderPack pack { QFileInfo(folder_sp) };
|
||||
|
||||
bool valid = ShaderPackUtils::processFolder(pack);
|
||||
|
||||
QVERIFY(pack.packFormat() == ShaderPackFormat::VALID);
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseZIP2()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/ShaderPackParse");
|
||||
|
||||
QString folder_sp = FS::PathCombine(source, "shaderpack3.zip");
|
||||
ShaderPack pack { QFileInfo(folder_sp) };
|
||||
|
||||
bool valid = ShaderPackUtils::process(pack);
|
||||
|
||||
QVERIFY(pack.packFormat() == ShaderPackFormat::INVALID);
|
||||
QVERIFY(valid == false);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(ShaderPackParseTest)
|
||||
|
||||
#include "ShaderPackParse_test.moc"
|
@ -36,9 +36,10 @@ class TexturePackParseTest : public QObject {
|
||||
QString zip_rp = FS::PathCombine(source, "test_texture_pack_idk.zip");
|
||||
TexturePack pack { QFileInfo(zip_rp) };
|
||||
|
||||
TexturePackUtils::processZIP(pack);
|
||||
bool valid = TexturePackUtils::processZIP(pack);
|
||||
|
||||
QVERIFY(pack.description() == "joe biden, wake up");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder()
|
||||
@ -48,9 +49,10 @@ class TexturePackParseTest : public QObject {
|
||||
QString folder_rp = FS::PathCombine(source, "test_texturefolder");
|
||||
TexturePack pack { QFileInfo(folder_rp) };
|
||||
|
||||
TexturePackUtils::processFolder(pack);
|
||||
bool valid = TexturePackUtils::processFolder(pack, TexturePackUtils::ProcessingLevel::BasicInfoOnly);
|
||||
|
||||
QVERIFY(pack.description() == "Some texture pack surely");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder2()
|
||||
@ -60,9 +62,10 @@ class TexturePackParseTest : public QObject {
|
||||
QString folder_rp = FS::PathCombine(source, "another_test_texturefolder");
|
||||
TexturePack pack { QFileInfo(folder_rp) };
|
||||
|
||||
TexturePackUtils::process(pack);
|
||||
bool valid = TexturePackUtils::process(pack, TexturePackUtils::ProcessingLevel::BasicInfoOnly);
|
||||
|
||||
QVERIFY(pack.description() == "quieres\nfor real");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
};
|
||||
|
||||
|
94
tests/WorldSaveParse_test.cpp
Normal file
94
tests/WorldSaveParse_test.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
|
||||
// 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 <QTest>
|
||||
#include <QTimer>
|
||||
|
||||
#include <FileSystem.h>
|
||||
|
||||
#include <minecraft/mod/WorldSave.h>
|
||||
#include <minecraft/mod/tasks/LocalWorldSaveParseTask.h>
|
||||
|
||||
class WorldSaveParseTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void test_parseZIP()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/WorldSaveParse");
|
||||
|
||||
QString zip_ws = FS::PathCombine(source, "minecraft_save_1.zip") ;
|
||||
WorldSave save { QFileInfo(zip_ws) };
|
||||
|
||||
bool valid = WorldSaveUtils::processZIP(save);
|
||||
|
||||
QVERIFY(save.saveFormat() == WorldSaveFormat::SINGLE);
|
||||
QVERIFY(save.saveDirName() == "world_1");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parse_ZIP2()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/WorldSaveParse");
|
||||
|
||||
QString zip_ws = FS::PathCombine(source, "minecraft_save_2.zip") ;
|
||||
WorldSave save { QFileInfo(zip_ws) };
|
||||
|
||||
bool valid = WorldSaveUtils::processZIP(save);
|
||||
|
||||
QVERIFY(save.saveFormat() == WorldSaveFormat::MULTI);
|
||||
QVERIFY(save.saveDirName() == "world_2");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/WorldSaveParse");
|
||||
|
||||
QString folder_ws = FS::PathCombine(source, "minecraft_save_3");
|
||||
WorldSave save { QFileInfo(folder_ws) };
|
||||
|
||||
bool valid = WorldSaveUtils::processFolder(save);
|
||||
|
||||
QVERIFY(save.saveFormat() == WorldSaveFormat::SINGLE);
|
||||
QVERIFY(save.saveDirName() == "world_3");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
void test_parseFolder2()
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/WorldSaveParse");
|
||||
|
||||
QString folder_ws = FS::PathCombine(source, "minecraft_save_4");
|
||||
WorldSave save { QFileInfo(folder_ws) };
|
||||
|
||||
bool valid = WorldSaveUtils::process(save);
|
||||
|
||||
QVERIFY(save.saveFormat() == WorldSaveFormat::MULTI);
|
||||
QVERIFY(save.saveDirName() == "world_4");
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(WorldSaveParseTest)
|
||||
|
||||
#include "WorldSaveParse_test.moc"
|
BIN
tests/testdata/DataPackParse/another_test_folder/data/dummy/tags/item/foo_proof/bar.json
vendored
Normal file
BIN
tests/testdata/DataPackParse/another_test_folder/data/dummy/tags/item/foo_proof/bar.json
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/DataPackParse/another_test_folder/pack.mcmeta
vendored
Normal file
BIN
tests/testdata/DataPackParse/another_test_folder/pack.mcmeta
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/DataPackParse/test_data_pack_boogaloo.zip
vendored
Normal file
BIN
tests/testdata/DataPackParse/test_data_pack_boogaloo.zip
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/DataPackParse/test_folder/data/dummy/tags/item/foo_proof/bar.json
vendored
Normal file
BIN
tests/testdata/DataPackParse/test_folder/data/dummy/tags/item/foo_proof/bar.json
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/DataPackParse/test_folder/pack.mcmeta
vendored
Normal file
BIN
tests/testdata/DataPackParse/test_folder/pack.mcmeta
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/testdata/ShaderPackParse/shaderpack1.zip
vendored
Normal file
BIN
tests/testdata/ShaderPackParse/shaderpack1.zip
vendored
Normal file
Binary file not shown.
0
tests/testdata/ShaderPackParse/shaderpack2/shaders/shaders.properties
vendored
Normal file
0
tests/testdata/ShaderPackParse/shaderpack2/shaders/shaders.properties
vendored
Normal file
BIN
tests/testdata/ShaderPackParse/shaderpack3.zip
vendored
Normal file
BIN
tests/testdata/ShaderPackParse/shaderpack3.zip
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/WorldSaveParse/minecraft_save_1.zip
vendored
Normal file
BIN
tests/testdata/WorldSaveParse/minecraft_save_1.zip
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/WorldSaveParse/minecraft_save_2.zip
vendored
Normal file
BIN
tests/testdata/WorldSaveParse/minecraft_save_2.zip
vendored
Normal file
Binary file not shown.
0
tests/testdata/WorldSaveParse/minecraft_save_3/world_3/level.dat
vendored
Normal file
0
tests/testdata/WorldSaveParse/minecraft_save_3/world_3/level.dat
vendored
Normal file
0
tests/testdata/WorldSaveParse/minecraft_save_4/saves/world_4/level.dat
vendored
Normal file
0
tests/testdata/WorldSaveParse/minecraft_save_4/saves/world_4/level.dat
vendored
Normal file
Loading…
Reference in New Issue
Block a user