2022-05-10 23:57:47 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2023-08-04 18:41:47 +01:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2023-08-14 17:16:53 +01:00
|
|
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.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/>.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-05-10 23:57:47 +01:00
|
|
|
|
2019-08-04 02:27:53 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-17 13:30:32 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2019-08-04 02:27:53 +01:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2023-05-05 07:42:42 +01:00
|
|
|
#include <QUrl>
|
2019-08-04 02:27:53 +01:00
|
|
|
|
2022-04-17 13:30:32 +01:00
|
|
|
#include "minecraft/mod/MetadataHandler.h"
|
|
|
|
|
2022-04-20 22:45:39 +01:00
|
|
|
enum class ModStatus {
|
2023-08-14 17:16:53 +01:00
|
|
|
Installed, // Both JAR and Metadata are present
|
|
|
|
NotInstalled, // Only the Metadata is present
|
|
|
|
NoMetadata, // Only the JAR is present
|
|
|
|
Unknown, // Default status
|
2022-04-20 22:45:39 +01:00
|
|
|
};
|
|
|
|
|
2023-05-05 07:42:42 +01:00
|
|
|
struct ModLicense {
|
|
|
|
QString name = {};
|
|
|
|
QString id = {};
|
|
|
|
QString url = {};
|
|
|
|
QString description = {};
|
|
|
|
|
|
|
|
ModLicense() {}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
ModLicense(const QString license)
|
|
|
|
{
|
|
|
|
// FIXME: come up with a better license parsing.
|
2023-05-05 07:42:42 +01:00
|
|
|
// handle SPDX identifiers? https://spdx.org/licenses/
|
|
|
|
auto parts = license.split(' ');
|
2023-08-14 17:16:53 +01:00
|
|
|
QStringList notNameParts = {};
|
2023-05-05 07:42:42 +01:00
|
|
|
for (auto part : parts) {
|
2023-07-01 07:51:15 +01:00
|
|
|
auto _url = QUrl(part);
|
2023-05-05 21:46:38 +01:00
|
|
|
if (part.startsWith("(") && part.endsWith(")"))
|
2023-07-01 07:51:15 +01:00
|
|
|
_url = QUrl(part.mid(1, part.size() - 2));
|
2023-05-05 21:46:38 +01:00
|
|
|
|
2023-07-01 07:51:15 +01:00
|
|
|
if (_url.isValid() && !_url.scheme().isEmpty() && !_url.host().isEmpty()) {
|
|
|
|
this->url = _url.toString();
|
2023-05-05 07:42:42 +01:00
|
|
|
notNameParts.append(part);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto part : notNameParts) {
|
|
|
|
parts.removeOne(part);
|
|
|
|
}
|
2023-08-14 17:16:53 +01:00
|
|
|
|
2023-05-05 07:42:42 +01:00
|
|
|
auto licensePart = parts.join(' ');
|
|
|
|
this->name = licensePart;
|
|
|
|
this->description = licensePart;
|
|
|
|
|
|
|
|
if (parts.size() == 1) {
|
|
|
|
this->id = parts.first();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-01 07:51:15 +01:00
|
|
|
ModLicense(const QString& name_, const QString& id_, const QString& url_, const QString& description_)
|
|
|
|
: name(name_), id(id_), url(url_), description(description_)
|
|
|
|
{}
|
2023-05-05 07:42:42 +01:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
ModLicense(const ModLicense& other) : name(other.name), id(other.id), url(other.url), description(other.description) {}
|
2023-05-05 07:42:42 +01:00
|
|
|
|
|
|
|
ModLicense& operator=(const ModLicense& other)
|
|
|
|
{
|
|
|
|
this->name = other.name;
|
|
|
|
this->id = other.id;
|
|
|
|
this->url = other.url;
|
|
|
|
this->description = other.description;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModLicense& operator=(const ModLicense&& other)
|
|
|
|
{
|
|
|
|
this->name = other.name;
|
|
|
|
this->id = other.id;
|
|
|
|
this->url = other.url;
|
|
|
|
this->description = other.description;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2023-05-05 21:46:38 +01:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool isEmpty() { return this->name.isEmpty() && this->id.isEmpty() && this->url.isEmpty() && this->description.isEmpty(); }
|
2023-05-05 07:42:42 +01:00
|
|
|
};
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
struct ModDetails {
|
2022-04-16 02:07:35 +01:00
|
|
|
/* Mod ID as defined in the ModLoader-specific metadata */
|
2022-08-12 21:06:20 +01:00
|
|
|
QString mod_id = {};
|
2023-08-14 17:16:53 +01:00
|
|
|
|
2022-04-16 02:07:35 +01:00
|
|
|
/* Human-readable name */
|
2022-08-12 21:06:20 +01:00
|
|
|
QString name = {};
|
2023-08-14 17:16:53 +01:00
|
|
|
|
2022-04-16 02:07:35 +01:00
|
|
|
/* Human-readable mod version */
|
2022-08-12 21:06:20 +01:00
|
|
|
QString version = {};
|
2023-08-14 17:16:53 +01:00
|
|
|
|
2022-04-16 02:07:35 +01:00
|
|
|
/* Human-readable minecraft version */
|
2022-08-12 21:06:20 +01:00
|
|
|
QString mcversion = {};
|
2023-08-14 17:16:53 +01:00
|
|
|
|
2022-04-16 02:07:35 +01:00
|
|
|
/* URL for mod's home page */
|
2022-08-12 21:06:20 +01:00
|
|
|
QString homeurl = {};
|
2023-08-14 17:16:53 +01:00
|
|
|
|
2022-04-16 02:07:35 +01:00
|
|
|
/* Human-readable description */
|
2022-08-12 21:06:20 +01:00
|
|
|
QString description = {};
|
2022-04-16 02:07:35 +01:00
|
|
|
|
|
|
|
/* List of the author's names */
|
2022-08-12 21:06:20 +01:00
|
|
|
QStringList authors = {};
|
2022-04-17 13:30:32 +01:00
|
|
|
|
2023-05-05 07:42:42 +01:00
|
|
|
/* Issue Tracker URL */
|
|
|
|
QString issue_tracker = {};
|
|
|
|
|
|
|
|
/* License */
|
|
|
|
QList<ModLicense> licenses = {};
|
|
|
|
|
|
|
|
/* Path of mod logo */
|
|
|
|
QString icon_file = {};
|
|
|
|
|
2022-04-20 22:45:39 +01:00
|
|
|
/* Installation status of the mod */
|
2022-08-12 21:06:20 +01:00
|
|
|
ModStatus status = ModStatus::Unknown;
|
2022-04-20 22:45:39 +01:00
|
|
|
|
2022-04-17 13:30:32 +01:00
|
|
|
/* Metadata information, if any */
|
2022-08-12 21:06:20 +01:00
|
|
|
std::shared_ptr<Metadata::ModStruct> metadata = nullptr;
|
|
|
|
|
|
|
|
ModDetails() = default;
|
|
|
|
|
|
|
|
/** Metadata should be handled manually to properly set the mod status. */
|
2022-12-10 07:52:50 +00:00
|
|
|
ModDetails(const ModDetails& other)
|
2022-08-12 21:06:20 +01:00
|
|
|
: mod_id(other.mod_id)
|
|
|
|
, name(other.name)
|
|
|
|
, version(other.version)
|
|
|
|
, mcversion(other.mcversion)
|
|
|
|
, homeurl(other.homeurl)
|
|
|
|
, description(other.description)
|
|
|
|
, authors(other.authors)
|
2023-05-05 07:42:42 +01:00
|
|
|
, issue_tracker(other.issue_tracker)
|
|
|
|
, licenses(other.licenses)
|
|
|
|
, icon_file(other.icon_file)
|
2022-08-12 21:06:20 +01:00
|
|
|
, status(other.status)
|
|
|
|
{}
|
2022-08-13 18:35:44 +01:00
|
|
|
|
2022-12-10 07:52:50 +00:00
|
|
|
ModDetails& operator=(const ModDetails& other)
|
2022-08-13 18:35:44 +01:00
|
|
|
{
|
|
|
|
this->mod_id = other.mod_id;
|
|
|
|
this->name = other.name;
|
|
|
|
this->version = other.version;
|
|
|
|
this->mcversion = other.mcversion;
|
|
|
|
this->homeurl = other.homeurl;
|
|
|
|
this->description = other.description;
|
|
|
|
this->authors = other.authors;
|
2023-05-05 07:42:42 +01:00
|
|
|
this->issue_tracker = other.issue_tracker;
|
|
|
|
this->licenses = other.licenses;
|
|
|
|
this->icon_file = other.icon_file;
|
2022-08-13 18:35:44 +01:00
|
|
|
this->status = other.status;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-12-10 07:52:50 +00:00
|
|
|
ModDetails& operator=(const ModDetails&& other)
|
2022-08-13 18:35:44 +01:00
|
|
|
{
|
|
|
|
this->mod_id = other.mod_id;
|
|
|
|
this->name = other.name;
|
|
|
|
this->version = other.version;
|
|
|
|
this->mcversion = other.mcversion;
|
|
|
|
this->homeurl = other.homeurl;
|
|
|
|
this->description = other.description;
|
|
|
|
this->authors = other.authors;
|
2023-05-05 07:42:42 +01:00
|
|
|
this->issue_tracker = other.issue_tracker;
|
|
|
|
this->licenses = other.licenses;
|
|
|
|
this->icon_file = other.icon_file;
|
2022-08-13 18:35:44 +01:00
|
|
|
this->status = other.status;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2019-08-04 02:27:53 +01:00
|
|
|
};
|