mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-25 04:44:59 +00:00
Merge branch 'MultiMC:develop' into develop
This commit is contained in:
@@ -134,6 +134,12 @@ void BaseInstance::setRunning(bool running)
|
||||
|
||||
m_isRunning = running;
|
||||
|
||||
if(!m_settings->get("RecordGameTime").toBool())
|
||||
{
|
||||
emit runningStatusChanged(running);
|
||||
return;
|
||||
}
|
||||
|
||||
if(running)
|
||||
{
|
||||
m_timeStarted = QDateTime::currentDateTime();
|
||||
|
||||
@@ -540,7 +540,7 @@ set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISI
|
||||
generate_export_header(MultiMC_logic)
|
||||
|
||||
# Link
|
||||
target_link_libraries(MultiMC_logic systeminfo MultiMC_quazip MultiMC_classparser ${NBT_NAME} ${ZLIB_LIBRARIES} optional-bare BuildConfig)
|
||||
target_link_libraries(MultiMC_logic systeminfo MultiMC_quazip MultiMC_classparser ${NBT_NAME} ${ZLIB_LIBRARIES} optional-bare tomlc99 BuildConfig)
|
||||
target_link_libraries(MultiMC_logic Qt5::Core Qt5::Xml Qt5::Network Qt5::Concurrent)
|
||||
|
||||
# Mark and export headers
|
||||
|
||||
@@ -106,6 +106,11 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
|
||||
m_settings->registerOverride(globalSettings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride);
|
||||
m_settings->registerOverride(globalSettings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride);
|
||||
|
||||
// Game time
|
||||
auto gameTimeOverride = m_settings->registerSetting("OverrideGameTime", false);
|
||||
m_settings->registerOverride(globalSettings->getSetting("ShowGameTime"), gameTimeOverride);
|
||||
m_settings->registerOverride(globalSettings->getSetting("RecordGameTime"), gameTimeOverride);
|
||||
|
||||
// DEPRECATED: Read what versions the user configuration thinks should be used
|
||||
m_settings->registerSetting({"IntendedVersion", "MinecraftVersion"}, "");
|
||||
m_settings->registerSetting("LWJGLVersion", "");
|
||||
@@ -769,7 +774,7 @@ QString MinecraftInstance::getStatusbarDescription()
|
||||
|
||||
QString description;
|
||||
description.append(tr("Minecraft %1 (%2)").arg(m_components->getComponentVersion("net.minecraft")).arg(typeName()));
|
||||
if(totalTimePlayed() > 0)
|
||||
if(m_settings->get("ShowGameTime").toBool() && totalTimePlayed() > 0)
|
||||
{
|
||||
description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed())));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QJsonValue>
|
||||
#include <quazip.h>
|
||||
#include <quazipfile.h>
|
||||
#include <toml.h>
|
||||
|
||||
#include "settings/INIFile.h"
|
||||
#include "FileSystem.h"
|
||||
@@ -90,6 +91,124 @@ std::shared_ptr<ModDetails> ReadMCModInfo(QByteArray contents)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// https://github.com/MinecraftForge/Documentation/blob/5ab4ba6cf9abc0ac4c0abd96ad187461aefd72af/docs/gettingstarted/structuring.md
|
||||
std::shared_ptr<ModDetails> ReadMCModTOML(QByteArray contents)
|
||||
{
|
||||
std::shared_ptr<ModDetails> details = std::make_shared<ModDetails>();
|
||||
|
||||
char errbuf[200];
|
||||
// top-level table
|
||||
toml_table_t* tomlData = toml_parse(contents.data(), errbuf, sizeof(errbuf));
|
||||
|
||||
if(!tomlData)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// array defined by [[mods]]
|
||||
toml_array_t* tomlModsArr = toml_array_in(tomlData, "mods");
|
||||
// we only really care about the first element, since multiple mods in one file is not supported by us at the moment
|
||||
toml_table_t* tomlModsTable0 = toml_table_at(tomlModsArr, 0);
|
||||
|
||||
// mandatory properties - always in [[mods]]
|
||||
toml_datum_t modIdDatum = toml_string_in(tomlModsTable0, "modId");
|
||||
if(modIdDatum.ok)
|
||||
{
|
||||
details->mod_id = modIdDatum.u.s;
|
||||
// library says this is required for strings
|
||||
free(modIdDatum.u.s);
|
||||
}
|
||||
toml_datum_t versionDatum = toml_string_in(tomlModsTable0, "version");
|
||||
if(versionDatum.ok)
|
||||
{
|
||||
details->version = versionDatum.u.s;
|
||||
free(versionDatum.u.s);
|
||||
}
|
||||
toml_datum_t displayNameDatum = toml_string_in(tomlModsTable0, "displayName");
|
||||
if(displayNameDatum.ok)
|
||||
{
|
||||
details->name = displayNameDatum.u.s;
|
||||
free(displayNameDatum.u.s);
|
||||
}
|
||||
toml_datum_t descriptionDatum = toml_string_in(tomlModsTable0, "description");
|
||||
if(descriptionDatum.ok)
|
||||
{
|
||||
details->description = descriptionDatum.u.s;
|
||||
free(descriptionDatum.u.s);
|
||||
}
|
||||
|
||||
// optional properties - can be in the root table or [[mods]]
|
||||
toml_datum_t authorsDatum = toml_string_in(tomlData, "authors");
|
||||
QString authors = "";
|
||||
if(authorsDatum.ok)
|
||||
{
|
||||
authors = authorsDatum.u.s;
|
||||
free(authorsDatum.u.s);
|
||||
}
|
||||
else
|
||||
{
|
||||
authorsDatum = toml_string_in(tomlModsTable0, "authors");
|
||||
if(authorsDatum.ok)
|
||||
{
|
||||
authors = authorsDatum.u.s;
|
||||
free(authorsDatum.u.s);
|
||||
}
|
||||
}
|
||||
if(!authors.isEmpty())
|
||||
{
|
||||
// author information is stored as a string now, not a list
|
||||
details->authors.append(authors);
|
||||
}
|
||||
// is credits even used anywhere? including this for completion/parity with old data version
|
||||
toml_datum_t creditsDatum = toml_string_in(tomlData, "credits");
|
||||
QString credits = "";
|
||||
if(creditsDatum.ok)
|
||||
{
|
||||
authors = creditsDatum.u.s;
|
||||
free(creditsDatum.u.s);
|
||||
}
|
||||
else
|
||||
{
|
||||
creditsDatum = toml_string_in(tomlModsTable0, "credits");
|
||||
if(creditsDatum.ok)
|
||||
{
|
||||
credits = creditsDatum.u.s;
|
||||
free(creditsDatum.u.s);
|
||||
}
|
||||
}
|
||||
details->credits = credits;
|
||||
toml_datum_t homeurlDatum = toml_string_in(tomlData, "displayURL");
|
||||
QString homeurl = "";
|
||||
if(homeurlDatum.ok)
|
||||
{
|
||||
homeurl = homeurlDatum.u.s;
|
||||
free(homeurlDatum.u.s);
|
||||
}
|
||||
else
|
||||
{
|
||||
homeurlDatum = toml_string_in(tomlModsTable0, "displayURL");
|
||||
if(homeurlDatum.ok)
|
||||
{
|
||||
homeurl = homeurlDatum.u.s;
|
||||
free(homeurlDatum.u.s);
|
||||
}
|
||||
}
|
||||
if(!homeurl.isEmpty())
|
||||
{
|
||||
// fix up url.
|
||||
if (!homeurl.startsWith("http://") && !homeurl.startsWith("https://") && !homeurl.startsWith("ftp://"))
|
||||
{
|
||||
homeurl.prepend("http://");
|
||||
}
|
||||
}
|
||||
details->homeurl = homeurl;
|
||||
|
||||
// this seems to be recursive, so it should free everything
|
||||
toml_free(tomlData);
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
// https://fabricmc.net/wiki/documentation:fabric_mod_json
|
||||
std::shared_ptr<ModDetails> ReadFabricModInfo(QByteArray contents)
|
||||
{
|
||||
@@ -198,7 +317,57 @@ void LocalModParseTask::processAsZip()
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
if (zip.setCurrentFile("mcmod.info"))
|
||||
if (zip.setCurrentFile("META-INF/mods.toml"))
|
||||
{
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
zip.close();
|
||||
return;
|
||||
}
|
||||
|
||||
m_result->details = ReadMCModTOML(file.readAll());
|
||||
file.close();
|
||||
|
||||
// to replace ${file.jarVersion} with the actual version, as needed
|
||||
if (m_result->details && m_result->details->version == "${file.jarVersion}")
|
||||
{
|
||||
if (zip.setCurrentFile("META-INF/MANIFEST.MF"))
|
||||
{
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
zip.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// quick and dirty line-by-line parser
|
||||
auto manifestLines = file.readAll().split('\n');
|
||||
QString manifestVersion = "";
|
||||
for (auto &line : manifestLines)
|
||||
{
|
||||
if (QString(line).startsWith("Implementation-Version: "))
|
||||
{
|
||||
manifestVersion = QString(line).remove("Implementation-Version: ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// some mods use ${projectversion} in their build.gradle, causing this mess to show up in MANIFEST.MF
|
||||
// also keep with forge's behavior of setting the version to "NONE" if none is found
|
||||
if (manifestVersion.contains("task ':jar' property 'archiveVersion'") || manifestVersion == "")
|
||||
{
|
||||
manifestVersion = "NONE";
|
||||
}
|
||||
|
||||
m_result->details->version = manifestVersion;
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
zip.close();
|
||||
return;
|
||||
}
|
||||
else if (zip.setCurrentFile("mcmod.info"))
|
||||
{
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
namespace ATLauncher {
|
||||
|
||||
PackInstallTask::PackInstallTask(QString pack, QString version)
|
||||
PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack, QString version)
|
||||
{
|
||||
m_support = support;
|
||||
m_pack = pack;
|
||||
m_version_name = version;
|
||||
}
|
||||
@@ -154,23 +155,56 @@ QString PackInstallTask::getVersionForLoader(QString uid)
|
||||
auto vlist = ENV.metadataIndex()->get(uid);
|
||||
if(!vlist)
|
||||
{
|
||||
emitFailed(tr("Failed to get local metadata index for ") + uid);
|
||||
emitFailed(tr("Failed to get local metadata index for %1").arg(uid));
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
// todo: filter by Minecraft version
|
||||
|
||||
if(m_version.loader.recommended) {
|
||||
return vlist.get()->getRecommended().get()->descriptor();
|
||||
if(!vlist->isLoaded()) {
|
||||
vlist->load(Net::Mode::Online);
|
||||
}
|
||||
else if(m_version.loader.latest) {
|
||||
return vlist.get()->at(0)->descriptor();
|
||||
|
||||
if(m_version.loader.recommended || m_version.loader.latest) {
|
||||
for (int i = 0; i < vlist->versions().size(); i++) {
|
||||
auto version = vlist->versions().at(i);
|
||||
auto reqs = version->requires();
|
||||
|
||||
// filter by minecraft version, if the loader depends on a certain version.
|
||||
// not all mod loaders depend on a given Minecraft version, so we won't do this
|
||||
// filtering for those loaders.
|
||||
if (m_version.loader.type != "fabric") {
|
||||
auto iter = std::find_if(reqs.begin(), reqs.end(), [](const Meta::Require &req) {
|
||||
return req.uid == "net.minecraft";
|
||||
});
|
||||
if (iter == reqs.end()) continue;
|
||||
if (iter->equalsVersion != m_version.minecraft) continue;
|
||||
}
|
||||
|
||||
if (m_version.loader.recommended) {
|
||||
// first recommended build we find, we use.
|
||||
if (!version->isRecommended()) continue;
|
||||
}
|
||||
|
||||
return version->descriptor();
|
||||
}
|
||||
|
||||
emitFailed(tr("Failed to find version for %1 loader").arg(m_version.loader.type));
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
else if(m_version.loader.choose) {
|
||||
// todo: implement
|
||||
// Fabric Loader doesn't depend on a given Minecraft version.
|
||||
if (m_version.loader.type == "fabric") {
|
||||
return m_support->chooseVersion(vlist, Q_NULLPTR);
|
||||
}
|
||||
|
||||
return m_support->chooseVersion(vlist, m_version.minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_version.loader.version == Q_NULLPTR || m_version.loader.version.isEmpty()) {
|
||||
emitFailed(tr("No loader version set for modpack!"));
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
return m_version.loader.version;
|
||||
}
|
||||
|
||||
@@ -428,6 +462,9 @@ void PackInstallTask::downloadMods()
|
||||
jarmods.clear();
|
||||
jobPtr.reset(new NetJob(tr("Mod download")));
|
||||
for(const auto& mod : m_version.mods) {
|
||||
// skip non-client mods
|
||||
if (!mod.client) continue;
|
||||
|
||||
// skip optional mods for now
|
||||
if(mod.optional) continue;
|
||||
|
||||
@@ -451,7 +488,6 @@ void PackInstallTask::downloadMods()
|
||||
auto cacheName = fileName.completeBaseName() + "-" + mod.md5 + "." + fileName.suffix();
|
||||
|
||||
if (mod.type == ModType::Extract || mod.type == ModType::TexturePackExtract || mod.type == ModType::ResourcePackExtract) {
|
||||
|
||||
auto entry = ENV.metacache()->resolveEntry("ATLauncherPacks", cacheName);
|
||||
entry->setStale(true);
|
||||
modsToExtract.insert(entry->getFullPath(), mod);
|
||||
@@ -522,7 +558,7 @@ void PackInstallTask::onModsDownloaded() {
|
||||
qDebug() << "PackInstallTask::onModsDownloaded: " << QThread::currentThreadId();
|
||||
jobPtr.reset();
|
||||
|
||||
if(modsToExtract.size() || modsToDecomp.size() || modsToCopy.size()) {
|
||||
if(!modsToExtract.empty() || !modsToDecomp.empty() || !modsToCopy.empty()) {
|
||||
m_modExtractFuture = QtConcurrent::run(QThreadPool::globalInstance(), this, &PackInstallTask::extractMods, modsToExtract, modsToDecomp, modsToCopy);
|
||||
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onModsExtracted);
|
||||
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, [&]()
|
||||
@@ -629,6 +665,7 @@ void PackInstallTask::install()
|
||||
|
||||
// Use a component to add libraries BEFORE Minecraft
|
||||
if(!createLibrariesComponent(instance.instanceRoot(), components)) {
|
||||
emitFailed(tr("Failed to create libraries component"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -666,6 +703,7 @@ void PackInstallTask::install()
|
||||
// Use a component to fill in the rest of the data
|
||||
// todo: use more detection
|
||||
if(!createPackComponent(instance.instanceRoot(), components)) {
|
||||
emitFailed(tr("Failed to create pack component"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,23 @@
|
||||
|
||||
namespace ATLauncher {
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT UserInteractionSupport {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Requests a user interaction to select a component version from a given version list
|
||||
* and constrained to a given Minecraft version.
|
||||
*/
|
||||
virtual QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) = 0;
|
||||
|
||||
};
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT PackInstallTask : public InstanceTask
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PackInstallTask(QString pack, QString version);
|
||||
explicit PackInstallTask(UserInteractionSupport *support, QString pack, QString version);
|
||||
virtual ~PackInstallTask(){}
|
||||
|
||||
bool abort() override;
|
||||
@@ -54,6 +65,8 @@ private:
|
||||
void install();
|
||||
|
||||
private:
|
||||
UserInteractionSupport *m_support;
|
||||
|
||||
NetJobPtr jobPtr;
|
||||
QByteArray response;
|
||||
|
||||
@@ -76,9 +89,6 @@ private:
|
||||
QFuture<bool> m_modExtractFuture;
|
||||
QFutureWatcher<bool> m_modExtractFutureWatcher;
|
||||
|
||||
QFuture<bool> m_decompFuture;
|
||||
QFutureWatcher<bool> m_decompFutureWatcher;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -81,12 +81,21 @@ static ATLauncher::ModType parseModType(QString rawType) {
|
||||
|
||||
static void loadVersionLoader(ATLauncher::VersionLoader & p, QJsonObject & obj) {
|
||||
p.type = Json::requireString(obj, "type");
|
||||
p.latest = Json::ensureBoolean(obj, QString("latest"), false);
|
||||
p.choose = Json::ensureBoolean(obj, QString("choose"), false);
|
||||
p.recommended = Json::ensureBoolean(obj, QString("recommended"), false);
|
||||
|
||||
auto metadata = Json::requireObject(obj, "metadata");
|
||||
p.version = Json::requireString(metadata, "version");
|
||||
p.latest = Json::ensureBoolean(metadata, QString("latest"), false);
|
||||
p.recommended = Json::ensureBoolean(metadata, QString("recommended"), false);
|
||||
|
||||
// Minecraft Forge
|
||||
if (p.type == "forge") {
|
||||
p.version = Json::ensureString(metadata, "version", "");
|
||||
}
|
||||
|
||||
// Fabric Loader
|
||||
if (p.type == "fabric") {
|
||||
p.version = Json::ensureString(metadata, "loader", "");
|
||||
}
|
||||
}
|
||||
|
||||
static void loadVersionLibrary(ATLauncher::VersionLibrary & p, QJsonObject & obj) {
|
||||
@@ -135,6 +144,7 @@ static void loadVersionMod(ATLauncher::VersionMod & p, QJsonObject & obj) {
|
||||
}
|
||||
|
||||
p.optional = Json::ensureBoolean(obj, QString("optional"), false);
|
||||
p.client = Json::ensureBoolean(obj, QString("client"), false);
|
||||
}
|
||||
|
||||
void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
@@ -169,12 +179,15 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
|
||||
}
|
||||
}
|
||||
|
||||
auto mods = Json::requireArray(obj, "mods");
|
||||
for (const auto modRaw : mods)
|
||||
{
|
||||
auto modObj = Json::requireObject(modRaw);
|
||||
ATLauncher::VersionMod mod;
|
||||
loadVersionMod(mod, modObj);
|
||||
v.mods.append(mod);
|
||||
|
||||
if(obj.contains("mods")) {
|
||||
auto mods = Json::requireArray(obj, "mods");
|
||||
for (const auto modRaw : mods)
|
||||
{
|
||||
auto modObj = Json::requireObject(modRaw);
|
||||
ATLauncher::VersionMod mod;
|
||||
loadVersionMod(mod, modObj);
|
||||
v.mods.append(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ struct VersionMod
|
||||
QString decompFile;
|
||||
|
||||
bool optional;
|
||||
bool client;
|
||||
};
|
||||
|
||||
struct PackVersion
|
||||
|
||||
Reference in New Issue
Block a user