diff options
-rw-r--r-- | launcher/minecraft/Library.cpp | 3 | ||||
-rw-r--r-- | launcher/minecraft/MinecraftInstance.cpp | 5 | ||||
-rw-r--r-- | launcher/minecraft/launch/LauncherPartLaunch.cpp | 25 | ||||
-rw-r--r-- | launcher/minecraft/update/FMLLibrariesTask.cpp | 3 | ||||
-rw-r--r-- | launcher/net/Download.cpp | 2 | ||||
-rw-r--r-- | launcher/net/Download.h | 2 | ||||
-rw-r--r-- | launcher/net/HttpMetaCache.cpp | 17 | ||||
-rw-r--r-- | launcher/net/HttpMetaCache.h | 9 | ||||
-rw-r--r-- | launcher/net/MetaCacheSink.cpp | 9 | ||||
-rw-r--r-- | launcher/net/MetaCacheSink.h | 3 | ||||
-rw-r--r-- | libraries/launcher/org/polymc/impl/OneSixLauncher.java | 86 |
11 files changed, 112 insertions, 52 deletions
diff --git a/launcher/minecraft/Library.cpp b/launcher/minecraft/Library.cpp index c7982705..ba7aed4b 100644 --- a/launcher/minecraft/Library.cpp +++ b/launcher/minecraft/Library.cpp @@ -88,6 +88,9 @@ QList<NetAction::Ptr> Library::getDownloads( options |= Net::Download::Option::AcceptLocalFiles; } + // Don't add a time limit for the libraries cache entry validity + options |= Net::Download::Option::MakeEternal; + if(sha1.size()) { auto rawSha1 = QByteArray::fromHex(sha1.toLatin1()); diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 94b4776e..cf127525 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -570,6 +570,11 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftS if(!profile) return QString(); + for (auto cp : getClassPath()) + { + launchScript += "classPath " + cp + "\n"; + } + auto mainClass = getMainClass(); if (!mainClass.isEmpty()) { diff --git a/launcher/minecraft/launch/LauncherPartLaunch.cpp b/launcher/minecraft/launch/LauncherPartLaunch.cpp index 63e4d90f..3b905bf5 100644 --- a/launcher/minecraft/launch/LauncherPartLaunch.cpp +++ b/launcher/minecraft/launch/LauncherPartLaunch.cpp @@ -95,8 +95,8 @@ bool fitsInLocal8bit(const QString & string) void LauncherPartLaunch::executeTask() { - QString jarPath = APPLICATION->getJarPath("NewLaunch.jar"); - if (jarPath.isEmpty()) + QString newLaunchJar = APPLICATION->getJarPath("NewLaunch.jar"); + if (newLaunchJar.isEmpty()) { const char *reason = QT_TR_NOOP("Launcher library could not be found. Please check your installation."); emit logLine(tr(reason), MessageLevel::Fatal); @@ -119,9 +119,6 @@ void LauncherPartLaunch::executeTask() // make detachable - this will keep the process running even if the object is destroyed m_process.setDetachable(true); - auto classPath = minecraftInstance->getClassPath(); - classPath.prepend(jarPath); - auto natPath = minecraftInstance->getNativePath(); #ifdef Q_OS_WIN if (!fitsInLocal8bit(natPath)) @@ -137,23 +134,7 @@ void LauncherPartLaunch::executeTask() #endif args << "-cp"; -#ifdef Q_OS_WIN - QStringList processed; - for(auto & item: classPath) - { - if (!fitsInLocal8bit(item)) - { - processed << shortPathName(item); - } - else - { - processed << item; - } - } - args << processed.join(';'); -#else - args << classPath.join(':'); -#endif + args << newLaunchJar; args << "org.polymc.EntryPoint"; qDebug() << args.join(' '); diff --git a/launcher/minecraft/update/FMLLibrariesTask.cpp b/launcher/minecraft/update/FMLLibrariesTask.cpp index b6238ce9..7a0bd2f3 100644 --- a/launcher/minecraft/update/FMLLibrariesTask.cpp +++ b/launcher/minecraft/update/FMLLibrariesTask.cpp @@ -63,11 +63,12 @@ void FMLLibrariesTask::executeTask() setStatus(tr("Downloading FML libraries...")); auto dljob = new NetJob("FML libraries", APPLICATION->network()); auto metacache = APPLICATION->metacache(); + Net::Download::Options options = Net::Download::Option::MakeEternal; for (auto &lib : fmlLibsToProcess) { auto entry = metacache->resolveEntry("fmllibs", lib.filename); QString urlString = BuildConfig.FMLLIBS_BASE_URL + lib.filename; - dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry)); + dljob->addNetAction(Net::Download::makeCached(QUrl(urlString), entry, options)); } connect(dljob, &NetJob::succeeded, this, &FMLLibrariesTask::fmllibsFinished); diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp index e6a6adcc..3778b939 100644 --- a/launcher/net/Download.cpp +++ b/launcher/net/Download.cpp @@ -60,7 +60,7 @@ auto Download::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Down dl->m_url = url; dl->m_options = options; auto md5Node = new ChecksumValidator(QCryptographicHash::Md5); - auto cachedNode = new MetaCacheSink(entry, md5Node); + auto cachedNode = new MetaCacheSink(entry, md5Node, options.testFlag(Option::MakeEternal)); dl->m_sink.reset(cachedNode); return dl; } diff --git a/launcher/net/Download.h b/launcher/net/Download.h index 1d264381..3faa5db5 100644 --- a/launcher/net/Download.h +++ b/launcher/net/Download.h @@ -49,7 +49,7 @@ class Download : public NetAction { public: using Ptr = shared_qobject_ptr<class Download>; - enum class Option { NoOptions = 0, AcceptLocalFiles = 1 }; + enum class Option { NoOptions = 0, AcceptLocalFiles = 1, MakeEternal = 2 }; Q_DECLARE_FLAGS(Options, Option) protected: diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp index deb2780b..9606ddb6 100644 --- a/launcher/net/HttpMetaCache.cpp +++ b/launcher/net/HttpMetaCache.cpp @@ -229,8 +229,13 @@ void HttpMetaCache::Load() foo->etag = Json::ensureString(element_obj, "etag"); foo->local_changed_timestamp = Json::ensureDouble(element_obj, "last_changed_timestamp"); foo->remote_changed_timestamp = Json::ensureString(element_obj, "remote_changed_timestamp"); - foo->current_age = Json::ensureDouble(element_obj, "current_age"); - foo->max_age = Json::ensureDouble(element_obj, "max_age"); + + foo->makeEternal(Json::ensureBoolean(element_obj, "eternal", false)); + if (!foo->isEternal()) { + foo->current_age = Json::ensureDouble(element_obj, "current_age"); + foo->max_age = Json::ensureDouble(element_obj, "max_age"); + } + // presumed innocent until closer examination foo->stale = false; @@ -271,8 +276,12 @@ void HttpMetaCache::SaveNow() entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->local_changed_timestamp))); if (!entry->remote_changed_timestamp.isEmpty()) entryObj.insert("remote_changed_timestamp", QJsonValue(entry->remote_changed_timestamp)); - entryObj.insert("current_age", QJsonValue(double(entry->current_age))); - entryObj.insert("max_age", QJsonValue(double(entry->max_age))); + if (entry->isEternal()) { + entryObj.insert("eternal", true); + } else { + entryObj.insert("current_age", QJsonValue(double(entry->current_age))); + entryObj.insert("max_age", QJsonValue(double(entry->max_age))); + } entriesArr.append(entryObj); } } diff --git a/launcher/net/HttpMetaCache.h b/launcher/net/HttpMetaCache.h index df3549e8..c0b12318 100644 --- a/launcher/net/HttpMetaCache.h +++ b/launcher/net/HttpMetaCache.h @@ -64,13 +64,17 @@ class MetaEntry { auto getMD5Sum() -> QString { return md5sum; } void setMD5Sum(QString md5sum) { this->md5sum = md5sum; } + /* Whether the entry expires after some time (false) or not (true). */ + void makeEternal(bool eternal) { is_eternal = eternal; } + [[nodiscard]] bool isEternal() const { return is_eternal; } + auto getCurrentAge() -> qint64 { return current_age; } void setCurrentAge(qint64 age) { current_age = age; } auto getMaximumAge() -> qint64 { return max_age; } void setMaximumAge(qint64 age) { max_age = age; } - bool isExpired(qint64 offset) { return current_age >= max_age - offset; }; + bool isExpired(qint64 offset) { return !is_eternal && (current_age >= max_age - offset); }; protected: QString baseId; @@ -78,10 +82,13 @@ class MetaEntry { QString relativePath; QString md5sum; QString etag; + qint64 local_changed_timestamp = 0; QString remote_changed_timestamp; // QString for now, RFC 2822 encoded time qint64 current_age = 0; qint64 max_age = 0; + bool is_eternal = false; + bool stale = true; }; diff --git a/launcher/net/MetaCacheSink.cpp b/launcher/net/MetaCacheSink.cpp index ab0c9fcb..5ae53c1c 100644 --- a/launcher/net/MetaCacheSink.cpp +++ b/launcher/net/MetaCacheSink.cpp @@ -46,8 +46,8 @@ namespace Net { #define MAX_TIME_TO_EXPIRE 1*7*24*60*60 -MetaCacheSink::MetaCacheSink(MetaEntryPtr entry, ChecksumValidator * md5sum) - :Net::FileSink(entry->getFullPath()), m_entry(entry), m_md5Node(md5sum) +MetaCacheSink::MetaCacheSink(MetaEntryPtr entry, ChecksumValidator * md5sum, bool is_eternal) + :Net::FileSink(entry->getFullPath()), m_entry(entry), m_md5Node(md5sum), m_is_eternal(is_eternal) { addValidator(md5sum); } @@ -95,7 +95,10 @@ Task::State MetaCacheSink::finalizeCache(QNetworkReply & reply) m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch()); { // Cache lifetime - if (reply.hasRawHeader("Cache-Control")) { + if (m_is_eternal) { + qDebug() << "[MetaCache] Adding eternal cache entry:" << m_entry->getFullPath(); + m_entry->makeEternal(true); + } else if (reply.hasRawHeader("Cache-Control")) { auto cache_control_header = reply.rawHeader("Cache-Control"); // qDebug() << "[MetaCache] Parsing 'Cache-Control' header with" << cache_control_header; diff --git a/launcher/net/MetaCacheSink.h b/launcher/net/MetaCacheSink.h index c9f7edfe..f5948085 100644 --- a/launcher/net/MetaCacheSink.h +++ b/launcher/net/MetaCacheSink.h @@ -42,7 +42,7 @@ namespace Net { class MetaCacheSink : public FileSink { public: - MetaCacheSink(MetaEntryPtr entry, ChecksumValidator* md5sum); + MetaCacheSink(MetaEntryPtr entry, ChecksumValidator* md5sum, bool is_eternal = false); virtual ~MetaCacheSink() = default; auto hasLocalData() -> bool override; @@ -54,5 +54,6 @@ class MetaCacheSink : public FileSink { private: MetaEntryPtr m_entry; ChecksumValidator* m_md5Node; + bool m_is_eternal; }; } // namespace Net diff --git a/libraries/launcher/org/polymc/impl/OneSixLauncher.java b/libraries/launcher/org/polymc/impl/OneSixLauncher.java index 362ff8d6..250fe0f2 100644 --- a/libraries/launcher/org/polymc/impl/OneSixLauncher.java +++ b/libraries/launcher/org/polymc/impl/OneSixLauncher.java @@ -1,16 +1,53 @@ -/* Copyright 2012-2021 MultiMC Contributors +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * - * 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 + * 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. * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. * - * 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. + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give + * you permission to link this library with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also meet, + * for each linked independent module, the terms and conditions of the + * license of that module. An independent module is a module which is + * not derived from or based on this library. If you modify this + * library, you may extend this exception to your version of the + * library, but you are not obliged to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * 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. */ package org.polymc.impl; @@ -24,6 +61,9 @@ import java.applet.Applet; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -37,6 +77,7 @@ public final class OneSixLauncher implements Launcher { private static final Logger LOGGER = Logger.getLogger("OneSixLauncher"); // parameters, separated from ParamBucket + private final List<String> classPath; private final List<String> mcParams; private final List<String> traits; private final String appletClass; @@ -53,11 +94,8 @@ public final class OneSixLauncher implements Launcher { private final String serverAddress; private final String serverPort; - private final ClassLoader classLoader; - public OneSixLauncher(Parameters params) { - classLoader = ClassLoader.getSystemClassLoader(); - + classPath = params.allSafe("classPath", Collections.<String>emptyList()); mcParams = params.allSafe("param", Collections.<String>emptyList()); mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft"); appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet"); @@ -104,7 +142,7 @@ public final class OneSixLauncher implements Launcher { method.invoke(null, (Object) mcParams.toArray(new String[0])); } - private void legacyLaunch() throws Exception { + private void legacyLaunch(ClassLoader classLoader) throws Exception { // Get the Minecraft Class and set the base folder Class<?> minecraftClass = classLoader.loadClass(mainClass); @@ -151,7 +189,7 @@ public final class OneSixLauncher implements Launcher { invokeMain(minecraftClass); } - private void launchWithMainClass() throws Exception { + private void launchWithMainClass(ClassLoader classLoader) throws Exception { // window size, title and state, onesix // FIXME: there is no good way to maximize the minecraft window in onesix. @@ -177,12 +215,24 @@ public final class OneSixLauncher implements Launcher { @Override public void launch() throws Exception { + URL[] classPathURLs = new URL[classPath.size()]; + for (int i = 0; i < classPath.size(); i++) { + File f = new File(classPath.get(i)); + classPathURLs[i] = f.toURI().toURL(); + } + // Some mod loaders (Fabric) read this property to determine the classpath. + String systemClassPath = System.getProperty("java.class.path"); + systemClassPath += File.pathSeparator + String.join(File.pathSeparator, classPath); + System.setProperty("java.class.path", systemClassPath); + + ClassLoader classLoader = new URLClassLoader(classPathURLs, getClass().getClassLoader()); + if (traits.contains("legacyLaunch") || traits.contains("alphaLaunch")) { // legacy launch uses the applet wrapper - legacyLaunch(); + legacyLaunch(classLoader); } else { // normal launch just calls main() - launchWithMainClass(); + launchWithMainClass(classLoader); } } |