2022-10-08 19:09:53 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2023-08-04 18:41:47 +01:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2022-10-08 19:09:53 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-05-09 16:16:25 +01:00
|
|
|
#pragma once
|
2016-03-26 15:56:57 +00:00
|
|
|
#include <net/NetAction.h>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QDir>
|
2014-05-11 11:37:21 +01:00
|
|
|
#include <QList>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QMap>
|
|
|
|
#include <QPair>
|
2022-08-06 23:06:32 +01:00
|
|
|
#include <QString>
|
2014-05-11 11:37:21 +01:00
|
|
|
#include <QStringList>
|
2015-05-27 00:30:18 +01:00
|
|
|
#include <QUrl>
|
2014-05-09 16:16:25 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2014-07-19 22:16:02 +01:00
|
|
|
#include "GradleSpecifier.h"
|
2016-03-26 15:56:57 +00:00
|
|
|
#include "MojangDownloadInfo.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "Rule.h"
|
2022-07-11 08:01:07 +01:00
|
|
|
#include "RuntimeContext.h"
|
2016-03-26 15:56:57 +00:00
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
class Library;
|
2016-10-01 23:26:10 +01:00
|
|
|
class MinecraftInstance;
|
2016-03-07 21:26:44 +00:00
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
typedef std::shared_ptr<Library> LibraryPtr;
|
2014-05-09 16:16:25 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
class Library {
|
2016-02-28 18:01:54 +00:00
|
|
|
friend class OneSixVersionFormat;
|
|
|
|
friend class MojangVersionFormat;
|
2016-03-26 15:56:57 +00:00
|
|
|
friend class LibraryTest;
|
2023-08-02 17:35:35 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Library() {}
|
|
|
|
Library(const QString& name) { m_name = name; }
|
2016-02-26 01:04:21 +00:00
|
|
|
/// limited copy without some data. TODO: why?
|
2016-03-07 01:01:28 +00:00
|
|
|
static LibraryPtr limitedCopy(LibraryPtr base)
|
2016-02-26 01:04:21 +00:00
|
|
|
{
|
2016-03-07 01:01:28 +00:00
|
|
|
auto newlib = std::make_shared<Library>();
|
2016-02-26 01:04:21 +00:00
|
|
|
newlib->m_name = base->m_name;
|
2016-03-26 15:56:57 +00:00
|
|
|
newlib->m_repositoryURL = base->m_repositoryURL;
|
2016-02-26 01:04:21 +00:00
|
|
|
newlib->m_hint = base->m_hint;
|
2016-03-26 15:56:57 +00:00
|
|
|
newlib->m_absoluteURL = base->m_absoluteURL;
|
|
|
|
newlib->m_extractExcludes = base->m_extractExcludes;
|
|
|
|
newlib->m_nativeClassifiers = base->m_nativeClassifiers;
|
2016-02-26 01:04:21 +00:00
|
|
|
newlib->m_rules = base->m_rules;
|
|
|
|
newlib->m_storagePrefix = base->m_storagePrefix;
|
2016-03-26 15:56:57 +00:00
|
|
|
newlib->m_mojangDownloads = base->m_mojangDownloads;
|
2017-04-17 21:51:30 +01:00
|
|
|
newlib->m_filename = base->m_filename;
|
2016-02-26 01:04:21 +00:00
|
|
|
return newlib;
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
public: /* methods */
|
2014-07-26 22:00:35 +01:00
|
|
|
/// Returns the raw name field
|
2023-08-02 17:35:35 +01:00
|
|
|
const GradleSpecifier& rawName() const { return m_name; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setRawName(const GradleSpecifier& spec) { m_name = spec; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setClassifier(const QString& spec) { m_name.setClassifier(spec); }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// returns the full group and artifact prefix
|
2023-08-02 17:35:35 +01:00
|
|
|
QString artifactPrefix() const { return m_name.artifactPrefix(); }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// get the artifact ID
|
2023-08-02 17:35:35 +01:00
|
|
|
QString artifactId() const { return m_name.artifactId(); }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// get the artifact version
|
2023-08-02 17:35:35 +01:00
|
|
|
QString version() const { return m_name.version(); }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// Returns true if the library is native
|
2023-08-02 17:35:35 +01:00
|
|
|
bool isNative() const { return m_nativeClassifiers.size() != 0; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2015-05-27 00:30:18 +01:00
|
|
|
void setStoragePrefix(QString prefix = QString());
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// Set the url base for downloads
|
2023-08-02 17:35:35 +01:00
|
|
|
void setRepositoryURL(const QString& base_url) { m_repositoryURL = base_url; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void getApplicableFiles(const RuntimeContext& runtimeContext,
|
|
|
|
QStringList& jar,
|
|
|
|
QStringList& native,
|
|
|
|
QStringList& native32,
|
|
|
|
QStringList& native64,
|
|
|
|
const QString& overridePath) const;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setAbsoluteUrl(const QString& absolute_url) { m_absoluteURL = absolute_url; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setFilename(const QString& filename) { m_filename = filename; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2017-04-17 21:51:30 +01:00
|
|
|
/// Get the file name of the library
|
2023-08-02 17:35:35 +01:00
|
|
|
QString filename(const RuntimeContext& runtimeContext) const;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2017-04-17 21:51:30 +01:00
|
|
|
// DEPRECATED: set a display name, used by jar mods only
|
2023-08-02 17:35:35 +01:00
|
|
|
void setDisplayName(const QString& displayName) { m_displayname = displayName; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2017-04-17 21:51:30 +01:00
|
|
|
/// Get the file name of the library
|
2023-08-02 17:35:35 +01:00
|
|
|
QString displayName(const RuntimeContext& runtimeContext) const;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setMojangDownloadInfo(MojangLibraryDownloadInfo::Ptr info) { m_mojangDownloads = info; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setHint(const QString& hint) { m_hint = hint; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// Set the load rules
|
2023-08-02 17:35:35 +01:00
|
|
|
void setRules(QList<std::shared_ptr<Rule>> rules) { m_rules = rules; }
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// Returns true if the library should be loaded (or extracted, in case of natives)
|
2023-08-02 17:35:35 +01:00
|
|
|
bool isActive(const RuntimeContext& runtimeContext) const;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2017-04-17 21:51:30 +01:00
|
|
|
/// Returns true if the library is contained in an instance and false if it is shared
|
|
|
|
bool isLocal() const;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2018-11-26 02:06:58 +00:00
|
|
|
/// Returns true if the library is to always be checked for updates
|
|
|
|
bool isAlwaysStale() const;
|
|
|
|
|
|
|
|
/// Return true if the library requires forge XZ hacks
|
|
|
|
bool isForge() const;
|
|
|
|
|
2016-03-26 15:56:57 +00:00
|
|
|
// Get a list of downloads for this library
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<NetAction::Ptr> getDownloads(const RuntimeContext& runtimeContext,
|
|
|
|
class HttpMetaCache* cache,
|
|
|
|
QStringList& failedLocalFiles,
|
|
|
|
const QString& overridePath) const;
|
2016-03-26 15:56:57 +00:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QString getCompatibleNative(const RuntimeContext& runtimeContext) const;
|
2022-08-06 23:06:32 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
private: /* methods */
|
2022-10-18 15:37:04 +01:00
|
|
|
/// the default storage prefix used by Prism Launcher
|
2016-03-26 15:56:57 +00:00
|
|
|
static QString defaultStoragePrefix();
|
|
|
|
|
|
|
|
/// Get the prefix - root of the storage to be used
|
|
|
|
QString storagePrefix() const;
|
|
|
|
|
2017-04-17 21:51:30 +01:00
|
|
|
/// Get the relative file path where the library should be saved
|
2023-08-02 17:35:35 +01:00
|
|
|
QString storageSuffix(const RuntimeContext& runtimeContext) const;
|
2016-03-26 15:56:57 +00:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QString hint() const { return m_hint; }
|
2014-07-26 22:00:35 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
protected: /* data */
|
2014-07-26 22:00:35 +01:00
|
|
|
/// the basic gradle dependency specifier.
|
2014-07-19 22:16:02 +01:00
|
|
|
GradleSpecifier m_name;
|
2014-07-26 22:00:35 +01:00
|
|
|
|
2016-02-24 23:29:35 +00:00
|
|
|
/// DEPRECATED URL prefix of the maven repo where the file can be downloaded
|
2016-03-26 15:56:57 +00:00
|
|
|
QString m_repositoryURL;
|
2014-07-16 01:03:52 +01:00
|
|
|
|
2022-10-18 15:37:04 +01:00
|
|
|
/// DEPRECATED: Prism Launcher-specific absolute URL. takes precedence over the implicit maven repo URL, if defined
|
2016-03-26 15:56:57 +00:00
|
|
|
QString m_absoluteURL;
|
2014-07-26 22:00:35 +01:00
|
|
|
|
2022-10-18 15:37:04 +01:00
|
|
|
/// Prism Launcher extension - filename override
|
2017-04-17 21:51:30 +01:00
|
|
|
QString m_filename;
|
|
|
|
|
2022-10-18 15:37:04 +01:00
|
|
|
/// DEPRECATED Prism Launcher extension - display name
|
2017-04-17 21:51:30 +01:00
|
|
|
QString m_displayname;
|
|
|
|
|
2016-02-24 23:29:35 +00:00
|
|
|
/**
|
2022-10-18 15:37:04 +01:00
|
|
|
* Prism Launcher-specific type hint - modifies how the library is treated
|
2016-02-24 23:29:35 +00:00
|
|
|
*/
|
2014-05-11 11:37:21 +01:00
|
|
|
QString m_hint;
|
2014-05-09 16:16:25 +01:00
|
|
|
|
2016-02-24 23:29:35 +00:00
|
|
|
/**
|
2022-10-18 15:37:04 +01:00
|
|
|
* storage - by default the local libraries folder in Prism Launcher, but could be elsewhere
|
|
|
|
* Prism Launcher specific, because of FTB.
|
2016-02-24 23:29:35 +00:00
|
|
|
*/
|
2015-05-27 00:30:18 +01:00
|
|
|
QString m_storagePrefix;
|
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// true if the library had an extract/excludes section (even empty)
|
2016-03-26 15:56:57 +00:00
|
|
|
bool m_hasExcludes = false;
|
2014-07-26 22:00:35 +01:00
|
|
|
|
|
|
|
/// a list of files that shouldn't be extracted from the library
|
2016-03-26 15:56:57 +00:00
|
|
|
QStringList m_extractExcludes;
|
2014-05-09 16:16:25 +01:00
|
|
|
|
2014-05-11 11:37:21 +01:00
|
|
|
/// native suffixes per OS
|
2022-07-11 08:01:07 +01:00
|
|
|
QMap<QString, QString> m_nativeClassifiers;
|
2014-05-09 16:16:25 +01:00
|
|
|
|
2014-07-26 22:00:35 +01:00
|
|
|
/// true if the library had a rules section (even empty)
|
2014-05-09 16:16:25 +01:00
|
|
|
bool applyRules = false;
|
2014-07-26 22:00:35 +01:00
|
|
|
|
|
|
|
/// rules associated with the library
|
2014-05-11 11:37:21 +01:00
|
|
|
QList<std::shared_ptr<Rule>> m_rules;
|
2016-03-07 01:01:28 +00:00
|
|
|
|
|
|
|
/// MOJANG: container with Mojang style download info
|
2016-03-26 15:56:57 +00:00
|
|
|
MojangLibraryDownloadInfo::Ptr m_mojangDownloads;
|
2014-05-09 16:16:25 +01:00
|
|
|
};
|