2015-02-02 22:25:30 +00:00
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2013-02-22 15:17:31 +00:00
|
|
|
*
|
|
|
|
* Authors: Orochimarufan <orochimarufan.x3@gmail.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2013-03-22 13:40:55 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-22 15:17:31 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2013-07-28 23:59:35 +01:00
|
|
|
#pragma once
|
2013-02-22 15:17:31 +00:00
|
|
|
#include <QProcess>
|
2013-07-28 23:59:35 +01:00
|
|
|
#include "BaseInstance.h"
|
2015-05-11 21:21:37 +01:00
|
|
|
#include "MessageLevel.h"
|
|
|
|
#include "LoggedProcess.h"
|
2015-06-16 08:19:55 +01:00
|
|
|
/* HACK: MINECRAFT: split! */
|
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2015-07-04 19:02:43 +01:00
|
|
|
#include "java/JavaChecker.h"
|
|
|
|
#include "QObjectPtr.h"
|
|
|
|
#include "tasks/Task.h"
|
2013-02-22 15:17:31 +00:00
|
|
|
|
2015-07-05 00:54:30 +01:00
|
|
|
class ProcessTask
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-07-04 19:02:43 +01:00
|
|
|
class BaseProfilerFactory;
|
2015-07-05 00:54:30 +01:00
|
|
|
class BaseLauncher: public Task
|
2013-02-22 15:17:31 +00:00
|
|
|
{
|
2013-03-22 13:40:55 +00:00
|
|
|
Q_OBJECT
|
2015-01-27 21:31:07 +00:00
|
|
|
protected:
|
2015-05-11 21:21:37 +01:00
|
|
|
explicit BaseLauncher(InstancePtr instance);
|
2015-01-27 21:31:07 +00:00
|
|
|
void init();
|
2013-03-22 13:40:55 +00:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
public: /* methods */
|
2015-07-04 19:02:43 +01:00
|
|
|
static std::shared_ptr<BaseLauncher> create(MinecraftInstancePtr inst);
|
2015-05-11 21:21:37 +01:00
|
|
|
virtual ~BaseLauncher() {};
|
2014-02-15 23:10:45 +00:00
|
|
|
|
2014-05-18 18:07:01 +01:00
|
|
|
InstancePtr instance()
|
2013-11-23 00:41:28 +00:00
|
|
|
{
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
2015-02-08 16:56:14 +00:00
|
|
|
/// Set the text printed on top of the log
|
|
|
|
void setHeader(QString header)
|
|
|
|
{
|
|
|
|
m_header = header;
|
|
|
|
}
|
|
|
|
|
2013-11-24 05:36:16 +00:00
|
|
|
void setWorkdir(QString path);
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2015-07-04 19:02:43 +01:00
|
|
|
BaseProfilerFactory * getProfiler()
|
|
|
|
{
|
|
|
|
return m_profiler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setProfiler(BaseProfilerFactory * profiler)
|
|
|
|
{
|
|
|
|
m_profiler = profiler;
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
void killProcess();
|
2014-01-09 00:22:34 +00:00
|
|
|
|
2015-05-11 21:21:37 +01:00
|
|
|
qint64 pid();
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
/**
|
|
|
|
* @brief prepare the process for launch (for multi-stage launch)
|
|
|
|
*/
|
2015-07-04 19:02:43 +01:00
|
|
|
virtual void executeTask() override;
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
/**
|
|
|
|
* @brief launch the armed instance
|
|
|
|
*/
|
2015-06-16 08:19:55 +01:00
|
|
|
virtual void launch();
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
/**
|
|
|
|
* @brief abort launch
|
|
|
|
*/
|
2015-06-16 08:19:55 +01:00
|
|
|
virtual void abort();
|
|
|
|
|
|
|
|
public: /* HACK: MINECRAFT: split! */
|
|
|
|
void setLaunchScript(QString script)
|
|
|
|
{
|
|
|
|
launchScript = script;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setNativeFolder(QString natives)
|
|
|
|
{
|
|
|
|
m_nativeFolder = natives;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setLogin(AuthSessionPtr session)
|
|
|
|
{
|
|
|
|
m_session = session;
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
|
|
|
|
protected: /* methods */
|
2015-05-11 21:21:37 +01:00
|
|
|
void preLaunch();
|
2015-07-04 19:02:43 +01:00
|
|
|
void updateInstance();
|
|
|
|
void makeReady();
|
2015-05-11 21:21:37 +01:00
|
|
|
void postLaunch();
|
2015-07-05 00:54:30 +01:00
|
|
|
virtual void emitFailed(QString reason);
|
|
|
|
virtual void emitSucceeded();
|
2015-01-27 21:31:07 +00:00
|
|
|
QString substituteVariables(const QString &cmd) const;
|
2015-05-11 21:21:37 +01:00
|
|
|
void initializeEnvironment();
|
2015-01-27 21:31:07 +00:00
|
|
|
|
2015-02-08 16:56:14 +00:00
|
|
|
void printHeader();
|
|
|
|
|
2015-06-16 08:19:55 +01:00
|
|
|
virtual QMap<QString, QString> getVariables() const;
|
|
|
|
virtual QString censorPrivateInfo(QString in);
|
|
|
|
virtual MessageLevel::Enum guessLevel(const QString &message, MessageLevel::Enum defaultLevel);
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2013-02-22 15:17:31 +00:00
|
|
|
signals:
|
2015-07-04 19:02:43 +01:00
|
|
|
/**
|
|
|
|
* @brief emitted when the launch preparations are done
|
|
|
|
*/
|
2015-07-05 00:54:30 +01:00
|
|
|
void readyForLaunch();
|
2015-07-04 19:02:43 +01:00
|
|
|
|
2013-03-22 13:40:55 +00:00
|
|
|
/**
|
|
|
|
* @brief emitted when we want to log something
|
|
|
|
* @param text the text to log
|
|
|
|
* @param level the level to log at
|
|
|
|
*/
|
2013-11-04 01:53:05 +00:00
|
|
|
void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC);
|
2013-02-22 15:17:31 +00:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
protected slots:
|
2015-05-11 21:21:37 +01:00
|
|
|
void on_log(QStringList lines, MessageLevel::Enum level);
|
|
|
|
void logOutput(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::Message);
|
|
|
|
void logOutput(QString line, MessageLevel::Enum defaultLevel = MessageLevel::Message);
|
|
|
|
|
|
|
|
void on_pre_state(LoggedProcess::State state);
|
|
|
|
void on_state(LoggedProcess::State state);
|
|
|
|
void on_post_state(LoggedProcess::State state);
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2015-07-04 19:02:43 +01:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
protected:
|
|
|
|
InstancePtr m_instance;
|
2015-05-11 21:21:37 +01:00
|
|
|
|
|
|
|
LoggedProcess m_prelaunchprocess;
|
|
|
|
LoggedProcess m_postlaunchprocess;
|
|
|
|
LoggedProcess m_process;
|
|
|
|
QProcessEnvironment m_env;
|
2015-07-04 19:02:43 +01:00
|
|
|
BaseProfilerFactory * m_profiler = nullptr;
|
2015-05-11 21:21:37 +01:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
bool killed = false;
|
2015-02-08 16:56:14 +00:00
|
|
|
QString m_header;
|
2015-06-16 08:19:55 +01:00
|
|
|
|
2015-07-05 00:54:30 +01:00
|
|
|
/**
|
|
|
|
* java check step
|
|
|
|
*/
|
|
|
|
protected slots:
|
|
|
|
void checkJavaFinished(JavaCheckResult result);
|
|
|
|
|
|
|
|
protected:
|
2015-07-04 19:02:43 +01:00
|
|
|
// for java checker and launch
|
|
|
|
QString m_javaPath;
|
|
|
|
qlonglong m_javaUnixTime;
|
2015-07-05 00:54:30 +01:00
|
|
|
std::shared_ptr<JavaChecker> m_JavaChecker;
|
2015-07-04 19:02:43 +01:00
|
|
|
|
2015-06-16 08:19:55 +01:00
|
|
|
protected: /* HACK: MINECRAFT: split! */
|
|
|
|
AuthSessionPtr m_session;
|
|
|
|
QString launchScript;
|
|
|
|
QString m_nativeFolder;
|
2015-07-04 19:02:43 +01:00
|
|
|
std::shared_ptr<Task> m_updateTask;
|
2015-06-16 08:19:55 +01:00
|
|
|
|
|
|
|
protected: /* HACK: MINECRAFT: split! */
|
2015-07-04 19:02:43 +01:00
|
|
|
void checkJava();
|
2015-06-16 08:19:55 +01:00
|
|
|
QStringList javaArguments() const;
|
2015-07-04 19:02:43 +01:00
|
|
|
private slots:
|
|
|
|
void updateFinished();
|
2013-02-22 15:17:31 +00:00
|
|
|
};
|
2015-07-04 19:02:43 +01:00
|
|
|
|
|
|
|
class BaseProfilerFactory;
|