From 8bbaab334c5116be4c180c3eac93c4acc844f4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 8 Feb 2017 20:01:42 +0100 Subject: NOISSUE set line limit and overflow behaviour even for hidden console --- api/logic/BaseInstance.cpp | 21 +++++++++++++++++++++ api/logic/BaseInstance.h | 3 +++ api/logic/launch/LaunchTask.cpp | 6 ++++++ api/logic/launch/LogModel.cpp | 5 +++++ api/logic/launch/LogModel.h | 1 + api/logic/settings/PassthroughSetting.cpp | 5 ++++- application/pages/LogPage.cpp | 13 ------------- 7 files changed, 40 insertions(+), 14 deletions(-) diff --git a/api/logic/BaseInstance.cpp b/api/logic/BaseInstance.cpp index 335ef392..6d719c32 100644 --- a/api/logic/BaseInstance.cpp +++ b/api/logic/BaseInstance.cpp @@ -51,6 +51,9 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting); m_settings->registerOverride(globalSettings->getSetting("ShowConsoleOnError"), consoleSetting); m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting); + + m_settings->registerPassthrough(globalSettings->getSetting("ConsoleMaxLines"), nullptr); + m_settings->registerPassthrough(globalSettings->getSetting("ConsoleOverflowStop"), nullptr); } QString BaseInstance::getPreLaunchCommand() @@ -68,6 +71,24 @@ QString BaseInstance::getPostExitCommand() return settings()->get("PostExitCommand").toString(); } +int BaseInstance::getConsoleMaxLines() const +{ + auto lineSetting = settings()->getSetting("ConsoleMaxLines"); + bool conversionOk = false; + int maxLines = lineSetting->get().toInt(&conversionOk); + if(!conversionOk) + { + maxLines = lineSetting->defValue().toInt(); + qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines; + } + return maxLines; +} + +bool BaseInstance::shouldStopOnConsoleOverflow() const +{ + return settings()->get("ConsoleOverflowStop").toBool(); +} + void BaseInstance::iconUpdated(QString key) { if(iconKey() == key) diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h index 462b7c66..27b167a6 100644 --- a/api/logic/BaseInstance.h +++ b/api/logic/BaseInstance.h @@ -263,6 +263,9 @@ public: Status currentStatus() const; + int getConsoleMaxLines() const; + bool shouldStopOnConsoleOverflow() const; + protected: void changeStatus(Status newStatus); diff --git a/api/logic/launch/LaunchTask.cpp b/api/logic/launch/LaunchTask.cpp index 9df5f85a..23c28f50 100644 --- a/api/logic/launch/LaunchTask.cpp +++ b/api/logic/launch/LaunchTask.cpp @@ -209,6 +209,12 @@ shared_qobject_ptr LaunchTask::getLogModel() if(!m_logModel) { m_logModel.reset(new LogModel()); + m_logModel->setMaxLines(m_instance->getConsoleMaxLines()); + m_logModel->setStopOnOverflow(m_instance->shouldStopOnConsoleOverflow()); + // FIXME: should this really be here? + m_logModel->setOverflowMessage(tr("MultiMC stopped watching the game log because the log length surpassed %1 lines.\n" + "You may have to fix your mods because the game is still logging to files and" + " likely wasting harddrive space at an alarming rate!").arg(m_logModel->getMaxLines())); } return m_logModel; } diff --git a/api/logic/launch/LogModel.cpp b/api/logic/launch/LogModel.cpp index 579aa654..042feeab 100644 --- a/api/logic/launch/LogModel.cpp +++ b/api/logic/launch/LogModel.cpp @@ -133,6 +133,11 @@ void LogModel::setMaxLines(int maxLines) m_maxLines = maxLines; } +int LogModel::getMaxLines() +{ + return m_maxLines; +} + void LogModel::setStopOnOverflow(bool stop) { m_stopOnOverflow = stop; diff --git a/api/logic/launch/LogModel.h b/api/logic/launch/LogModel.h index 558242d8..57cd23b0 100644 --- a/api/logic/launch/LogModel.h +++ b/api/logic/launch/LogModel.h @@ -21,6 +21,7 @@ public: QString toPlainText(); + int getMaxLines(); void setMaxLines(int maxLines); void setStopOnOverflow(bool stop); void setOverflowMessage(const QString & overflowMessage); diff --git a/api/logic/settings/PassthroughSetting.cpp b/api/logic/settings/PassthroughSetting.cpp index 3839361c..2a407260 100644 --- a/api/logic/settings/PassthroughSetting.cpp +++ b/api/logic/settings/PassthroughSetting.cpp @@ -19,13 +19,16 @@ PassthroughSetting::PassthroughSetting(std::shared_ptr other, std::shar : Setting(other->configKeys(), QVariant()) { Q_ASSERT(other); - Q_ASSERT(gate); m_other = other; m_gate = gate; } bool PassthroughSetting::isOverriding() const { + if(!m_gate) + { + return false; + } return m_gate->get().toBool(); } diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp index 31cf9ecd..75e1df7d 100644 --- a/application/pages/LogPage.cpp +++ b/application/pages/LogPage.cpp @@ -168,19 +168,6 @@ void LogPage::on_InstanceLaunchTask_changed(std::shared_ptr proc) if(m_process) { m_model = proc->getLogModel(); - auto lineSetting = MMC->settings()->getSetting("ConsoleMaxLines"); - bool conversionOk = false; - int maxLines = lineSetting->get().toInt(&conversionOk); - if(!conversionOk) - { - maxLines = lineSetting->defValue().toInt(); - qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines; - } - m_model->setMaxLines(maxLines); - m_model->setStopOnOverflow(MMC->settings()->get("ConsoleOverflowStop").toBool()); - m_model->setOverflowMessage(tr("MultiMC stopped watching the game log because the log length surpassed %1 lines.\n" - "You may have to fix your mods because the game is still logging to files and" - " likely wasting harddrive space at an alarming rate!").arg(maxLines)); m_proxy->setSourceModel(m_model.get()); } else -- cgit v1.2.3