Merge branch 'feature_better_launch' into develop
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include "overridesetting.h"
|
||||
|
||||
#include "pathutils.h"
|
||||
#include <cmdutils.h>
|
||||
#include "lists/MinecraftVersionList.h"
|
||||
#include "logic/icons/IconList.h"
|
||||
|
||||
@ -248,8 +249,14 @@ void BaseInstance::setName(QString val)
|
||||
d->m_settings->set("name", val);
|
||||
emit propertiesChanged(this);
|
||||
}
|
||||
|
||||
QString BaseInstance::name() const
|
||||
{
|
||||
I_D(BaseInstance);
|
||||
return d->m_settings->get("name").toString();
|
||||
}
|
||||
|
||||
QStringList BaseInstance::extraArguments() const
|
||||
{
|
||||
return Util::Commandline::splitArgs(settings().get("JvmArgs").toString());
|
||||
}
|
||||
|
@ -81,6 +81,8 @@ public:
|
||||
void setGroupInitial(QString val);
|
||||
void setGroupPost(QString val);
|
||||
|
||||
QStringList extraArguments() const;
|
||||
|
||||
virtual QString intendedVersionId() const = 0;
|
||||
virtual bool setIntendedVersionId(QString version) = 0;
|
||||
|
||||
|
@ -47,7 +47,7 @@ std::shared_ptr<Task> LegacyInstance::doUpdate(bool only_prepare)
|
||||
// make sure the jar mods list is initialized by asking for it.
|
||||
auto list = jarModList();
|
||||
// create an update task
|
||||
return std::shared_ptr<Task> (new LegacyUpdate(this, only_prepare , this));
|
||||
return std::shared_ptr<Task>(new LegacyUpdate(this, only_prepare, this));
|
||||
}
|
||||
|
||||
MinecraftProcess *LegacyInstance::prepareForLaunch(MojangAccountPtr account)
|
||||
@ -58,58 +58,27 @@ MinecraftProcess *LegacyInstance::prepareForLaunch(MojangAccountPtr account)
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG");
|
||||
|
||||
// extract the legacy launcher
|
||||
QString launcherJar = PathCombine(MMC->bin(), "jars", "MultiMCLauncher.jar");
|
||||
|
||||
// set the process arguments
|
||||
// create the launch script
|
||||
QString launchScript;
|
||||
{
|
||||
QStringList args;
|
||||
|
||||
// window size
|
||||
QString windowSize;
|
||||
QString windowParams;
|
||||
if (settings().get("LaunchMaximized").toBool())
|
||||
windowSize = "max";
|
||||
windowParams = "max";
|
||||
else
|
||||
windowSize = QString("%1x%2").arg(settings().get("MinecraftWinWidth").toInt()).arg(
|
||||
windowParams = QString("%1x%2").arg(settings().get("MinecraftWinWidth").toInt()).arg(
|
||||
settings().get("MinecraftWinHeight").toInt());
|
||||
|
||||
// window title
|
||||
QString windowTitle;
|
||||
windowTitle.append("MultiMC: ").append(name());
|
||||
|
||||
// Java arguments
|
||||
args.append(Util::Commandline::splitArgs(settings().get("JvmArgs").toString()));
|
||||
|
||||
#ifdef OSX
|
||||
// OSX dock icon and name
|
||||
args << "-Xdock:icon=icon.png";
|
||||
args << QString("-Xdock:name=\"%1\"").arg(windowTitle);
|
||||
#endif
|
||||
|
||||
QString lwjgl = QDir(MMC->settings()->get("LWJGLDir").toString() + "/" + lwjglVersion())
|
||||
.absolutePath();
|
||||
|
||||
// launcher arguments
|
||||
args << QString("-Xms%1m").arg(settings().get("MinMemAlloc").toInt());
|
||||
args << QString("-Xmx%1m").arg(settings().get("MaxMemAlloc").toInt());
|
||||
args << QString("-XX:PermSize=%1m").arg(settings().get("PermGen").toInt());
|
||||
/**
|
||||
* HACK: Stupid hack for Intel drivers.
|
||||
* See: https://mojang.atlassian.net/browse/MCL-767
|
||||
*/
|
||||
#ifdef Q_OS_WIN32
|
||||
args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_"
|
||||
"minecraft.exe.heapdump");
|
||||
#endif
|
||||
|
||||
args << "-jar" << launcherJar;
|
||||
args << account->currentProfile()->name;
|
||||
args << account->sessionId();
|
||||
args << windowTitle;
|
||||
args << windowSize;
|
||||
args << lwjgl;
|
||||
proc->setArguments(args);
|
||||
launchScript += "userName " + account->currentProfile()->name + "\n";
|
||||
launchScript += "sessionId " + account->sessionId() + "\n";
|
||||
launchScript += "windowTitle MultiMC: " + name() + "\n";
|
||||
launchScript += "windowParams " + windowParams + "\n";
|
||||
launchScript += "lwjgl " + lwjgl + "\n";
|
||||
launchScript += "launch legacy\n";
|
||||
}
|
||||
proc->setLaunchScript(launchScript);
|
||||
|
||||
// set the process work path
|
||||
proc->setWorkdir(minecraftRoot());
|
||||
|
@ -14,13 +14,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include "MinecraftProcess.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
//#include <QImage>
|
||||
#include <QProcessEnvironment>
|
||||
|
||||
#include "BaseInstance.h"
|
||||
@ -59,11 +59,6 @@ MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst)
|
||||
connect(this, SIGNAL(readyReadStandardOutput()), SLOT(on_stdOut()));
|
||||
}
|
||||
|
||||
void MinecraftProcess::setArguments(QStringList args)
|
||||
{
|
||||
m_args = args;
|
||||
}
|
||||
|
||||
void MinecraftProcess::setWorkdir(QString path)
|
||||
{
|
||||
QDir mcDir(path);
|
||||
@ -197,13 +192,43 @@ void MinecraftProcess::launch()
|
||||
}
|
||||
|
||||
m_instance->setLastLaunch();
|
||||
auto &settings = m_instance->settings();
|
||||
|
||||
//////////// java arguments ////////////
|
||||
QStringList args;
|
||||
{
|
||||
// custom args go first. we want to override them if we have our own here.
|
||||
args.append(m_instance->extraArguments());
|
||||
|
||||
// OSX dock icon and name
|
||||
#ifdef OSX
|
||||
args << "-Xdock:icon=icon.png";
|
||||
args << QString("-Xdock:name=\"%1\"").arg(windowTitle);
|
||||
#endif
|
||||
|
||||
// HACK: Stupid hack for Intel drivers. See: https://mojang.atlassian.net/browse/MCL-767
|
||||
#ifdef Q_OS_WIN32
|
||||
args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_"
|
||||
"minecraft.exe.heapdump");
|
||||
#endif
|
||||
|
||||
args << QString("-Xms%1m").arg(settings.get("MinMemAlloc").toInt());
|
||||
args << QString("-Xmx%1m").arg(settings.get("MaxMemAlloc").toInt());
|
||||
args << QString("-XX:PermSize=%1m").arg(settings.get("PermGen").toInt());
|
||||
if(!m_nativeFolder.isEmpty())
|
||||
args << QString("-Djava.library.path=%1").arg(m_nativeFolder);
|
||||
args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar");
|
||||
}
|
||||
|
||||
emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory()));
|
||||
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
||||
emit log(QString("Java path: '%1'").arg(JavaPath));
|
||||
QString allArgs = m_args.join("' '");
|
||||
emit log(QString("Arguments: '%1'").arg(censorPrivateInfo(allArgs)));
|
||||
start(JavaPath, m_args);
|
||||
emit log("MultiMC version: " + MMC->version().toString() + "\n\n");
|
||||
emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n");
|
||||
emit log("Java path is:\n" + JavaPath + "\n\n");
|
||||
QString allArgs = args.join(", ");
|
||||
emit log("Java Arguments:\n[" + censorPrivateInfo(allArgs) + "]\n\n");
|
||||
|
||||
// instantiate the launcher part
|
||||
start(JavaPath, args);
|
||||
if (!waitForStarted())
|
||||
{
|
||||
//: Error message displayed if instace can't start
|
||||
@ -212,11 +237,13 @@ void MinecraftProcess::launch()
|
||||
emit launch_failed(m_instance);
|
||||
return;
|
||||
}
|
||||
// send the launch script to the launcher part
|
||||
QByteArray bytes = launchScript.toUtf8();
|
||||
writeData(bytes.constData(), bytes.length());
|
||||
}
|
||||
|
||||
MessageLevel::Enum MinecraftProcess::getLevel(const QString &line, MessageLevel::Enum level)
|
||||
{
|
||||
|
||||
if (line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") ||
|
||||
line.contains("[FINER]") || line.contains("[FINEST]"))
|
||||
level = MessageLevel::Message;
|
||||
|
@ -18,7 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
#include <QString>
|
||||
#include "BaseInstance.h"
|
||||
|
||||
/**
|
||||
@ -65,7 +65,15 @@ public:
|
||||
|
||||
void setWorkdir(QString path);
|
||||
|
||||
void setArguments(QStringList args);
|
||||
void setLaunchScript(QString script)
|
||||
{
|
||||
launchScript = script;
|
||||
}
|
||||
|
||||
void setNativeFolder(QString natives)
|
||||
{
|
||||
m_nativeFolder = natives;
|
||||
}
|
||||
|
||||
void killMinecraft();
|
||||
|
||||
@ -104,12 +112,13 @@ signals:
|
||||
|
||||
protected:
|
||||
BaseInstance *m_instance = nullptr;
|
||||
QStringList m_args;
|
||||
QString m_err_leftover;
|
||||
QString m_out_leftover;
|
||||
QProcess m_prepostlaunchprocess;
|
||||
bool killed = false;
|
||||
MojangAccountPtr m_account;
|
||||
QString launchScript;
|
||||
QString m_nativeFolder;
|
||||
|
||||
protected
|
||||
slots:
|
||||
|
@ -13,12 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "OneSixInstance.h"
|
||||
#include "OneSixInstance_p.h"
|
||||
#include "OneSixUpdate.h"
|
||||
#include "MinecraftProcess.h"
|
||||
#include "OneSixVersion.h"
|
||||
#include "JavaChecker.h"
|
||||
#include "logic/icons/IconList.h"
|
||||
|
||||
#include <setting.h>
|
||||
#include <pathutils.h>
|
||||
@ -27,6 +29,7 @@
|
||||
#include "gui/dialogs/OneSixModEditDialog.h"
|
||||
#include "logger/QsLog.h"
|
||||
#include "logic/assets/AssetsUtils.h"
|
||||
#include <QIcon>
|
||||
|
||||
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj,
|
||||
QObject *parent)
|
||||
@ -40,7 +43,7 @@ OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_o
|
||||
|
||||
std::shared_ptr<Task> OneSixInstance::doUpdate(bool only_prepare)
|
||||
{
|
||||
return std::shared_ptr<Task> (new OneSixUpdate(this, only_prepare));
|
||||
return std::shared_ptr<Task>(new OneSixUpdate(this, only_prepare));
|
||||
}
|
||||
|
||||
QString replaceTokensIn(QString text, QMap<QString, QString> with)
|
||||
@ -78,24 +81,25 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<OneSixVersion> version)
|
||||
QFile indexFile(indexPath);
|
||||
QDir virtualRoot(PathCombine(virtualDir.path(), version->assets));
|
||||
|
||||
if(!indexFile.exists())
|
||||
if (!indexFile.exists())
|
||||
{
|
||||
QLOG_ERROR() << "No assets index file" << indexPath << "; can't reconstruct assets";
|
||||
return virtualRoot;
|
||||
}
|
||||
|
||||
QLOG_DEBUG() << "reconstructAssets" << assetsDir.path() << indexDir.path() << objectDir.path() << virtualDir.path() << virtualRoot.path();
|
||||
QLOG_DEBUG() << "reconstructAssets" << assetsDir.path() << indexDir.path()
|
||||
<< objectDir.path() << virtualDir.path() << virtualRoot.path();
|
||||
|
||||
AssetsIndex index;
|
||||
bool loadAssetsIndex = AssetsUtils::loadAssetsIndexJson(indexPath, &index);
|
||||
|
||||
if(loadAssetsIndex)
|
||||
if (loadAssetsIndex)
|
||||
{
|
||||
if(index.isVirtual)
|
||||
if (index.isVirtual)
|
||||
{
|
||||
QLOG_INFO() << "Reconstructing virtual assets folder at" << virtualRoot.path();
|
||||
|
||||
for(QString map : index.objects.keys())
|
||||
for (QString map : index.objects.keys())
|
||||
{
|
||||
AssetObject asset_object = index.objects.value(map);
|
||||
QString target_path = PathCombine(virtualRoot.path(), map);
|
||||
@ -103,17 +107,20 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<OneSixVersion> version)
|
||||
|
||||
QString tlk = asset_object.hash.left(2);
|
||||
|
||||
QString original_path = PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
|
||||
QString original_path =
|
||||
PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
|
||||
QFile original(original_path);
|
||||
if(!target.exists())
|
||||
if (!target.exists())
|
||||
{
|
||||
QFileInfo info(target_path);
|
||||
QDir target_dir = info.dir();
|
||||
//QLOG_DEBUG() << target_dir;
|
||||
if(!target_dir.exists()) QDir("").mkpath(target_dir.path());
|
||||
// QLOG_DEBUG() << target_dir;
|
||||
if (!target_dir.exists())
|
||||
QDir("").mkpath(target_dir.path());
|
||||
|
||||
bool couldCopy = original.copy(target_path);
|
||||
QLOG_DEBUG() << " Copying" << original_path << "to" << target_path << QString::number(couldCopy);// << original.errorString();
|
||||
QLOG_DEBUG() << " Copying" << original_path << "to" << target_path
|
||||
<< QString::number(couldCopy); // << original.errorString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +162,7 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account)
|
||||
|
||||
auto user = account->user();
|
||||
QJsonObject userAttrs;
|
||||
for(auto key: user.properties.keys())
|
||||
for (auto key : user.properties.keys())
|
||||
{
|
||||
auto array = QJsonArray::fromStringList(user.properties.values(key));
|
||||
userAttrs.insert(key, array);
|
||||
@ -180,71 +187,56 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account)
|
||||
{
|
||||
I_D(OneSixInstance);
|
||||
|
||||
QString natives_dir_raw = PathCombine(instanceRoot(), "natives/");
|
||||
QIcon icon = MMC->icons()->getIcon(iconKey());
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG");
|
||||
|
||||
auto version = d->version;
|
||||
if (!version)
|
||||
return nullptr;
|
||||
|
||||
QStringList args;
|
||||
args.append(Util::Commandline::splitArgs(settings().get("JvmArgs").toString()));
|
||||
args << QString("-Xms%1m").arg(settings().get("MinMemAlloc").toInt());
|
||||
args << QString("-Xmx%1m").arg(settings().get("MaxMemAlloc").toInt());
|
||||
args << QString("-XX:PermSize=%1m").arg(settings().get("PermGen").toInt());
|
||||
|
||||
/**
|
||||
* HACK: Stupid hack for Intel drivers.
|
||||
* See: https://mojang.atlassian.net/browse/MCL-767
|
||||
*/
|
||||
#ifdef Q_OS_WIN32
|
||||
args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_"
|
||||
"minecraft.exe.heapdump");
|
||||
#endif
|
||||
|
||||
QDir natives_dir(natives_dir_raw);
|
||||
args << QString("-Djava.library.path=%1").arg(natives_dir.absolutePath());
|
||||
QString classPath;
|
||||
QString launchScript;
|
||||
{
|
||||
auto libs = version->getActiveNormalLibs();
|
||||
for (auto lib : libs)
|
||||
{
|
||||
QFileInfo fi(QString("libraries/") + lib->storagePath());
|
||||
classPath.append(fi.absoluteFilePath());
|
||||
#ifdef Q_OS_WIN32
|
||||
classPath.append(';');
|
||||
#else
|
||||
classPath.append(':');
|
||||
#endif
|
||||
launchScript += "cp " + fi.absoluteFilePath() + "\n";
|
||||
}
|
||||
QString targetstr = "versions/" + version->id + "/" + version->id + ".jar";
|
||||
QFileInfo fi(targetstr);
|
||||
classPath.append(fi.absoluteFilePath());
|
||||
launchScript += "cp " + fi.absoluteFilePath() + "\n";
|
||||
}
|
||||
if (classPath.size())
|
||||
launchScript += "mainClass " + version->mainClass + "\n";
|
||||
|
||||
for (auto param : processMinecraftArgs(account))
|
||||
{
|
||||
args << "-cp";
|
||||
args << classPath;
|
||||
launchScript += "param " + param + "\n";
|
||||
}
|
||||
args << version->mainClass;
|
||||
args.append(processMinecraftArgs(account));
|
||||
|
||||
// Set the width and height for 1.6 instances
|
||||
bool maximize = settings().get("LaunchMaximized").toBool();
|
||||
if (maximize)
|
||||
{
|
||||
// this is probably a BAD idea
|
||||
// args << QString("--fullscreen");
|
||||
// launchScript += "param --fullscreen\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
args << QString("--width") << settings().get("MinecraftWinWidth").toString();
|
||||
args << QString("--height") << settings().get("MinecraftWinHeight").toString();
|
||||
launchScript +=
|
||||
"param --width\nparam " + settings().get("MinecraftWinWidth").toString() + "\n";
|
||||
launchScript +=
|
||||
"param --height\nparam " + settings().get("MinecraftWinHeight").toString() + "\n";
|
||||
}
|
||||
QDir natives_dir(PathCombine(instanceRoot(), "natives/"));
|
||||
launchScript += "windowTitle MultiMC: " + name() + "\n";
|
||||
launchScript += "natives " + natives_dir.absolutePath() + "\n";
|
||||
launchScript += "launch onesix\n";
|
||||
|
||||
// create the process and set its parameters
|
||||
MinecraftProcess *proc = new MinecraftProcess(this);
|
||||
proc->setArguments(args);
|
||||
proc->setWorkdir(minecraftRoot());
|
||||
proc->setLaunchScript(launchScript);
|
||||
// proc->setNativeFolder(natives_dir.absolutePath());
|
||||
return proc;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user