From 44bf32e729294d8ede069f9fd952b9104b34b695 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 21 Mar 2023 18:28:32 +0100 Subject: [PATCH 1/3] fix: handle partial lines in LoggedProcess Fixes PrismLauncher/PrismLauncher#930 Co-authored-by: flow Signed-off-by: Sefa Eyeoglu --- launcher/LoggedProcess.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/launcher/LoggedProcess.cpp b/launcher/LoggedProcess.cpp index 6447f5c6..43a9c4f6 100644 --- a/launcher/LoggedProcess.cpp +++ b/launcher/LoggedProcess.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 Sefa Eyeoglu + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022,2023 Sefa Eyeoglu + * Copyright (c) 2023 flowln * * 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 @@ -60,14 +61,26 @@ LoggedProcess::~LoggedProcess() } } +static QString m_leftover_line; + QStringList reprocess(const QByteArray& data, QTextDecoder& decoder) { auto str = decoder.toUnicode(data); + + // FIXME: Flush this out when process exits + if (!m_leftover_line.isEmpty()) { + str.prepend(m_leftover_line); + m_leftover_line = ""; + } + #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) auto lines = str.remove(QChar::CarriageReturn).split(QChar::LineFeed, QString::SkipEmptyParts); #else auto lines = str.remove(QChar::CarriageReturn).split(QChar::LineFeed, Qt::SkipEmptyParts); #endif + + if (!str.endsWith(QChar::LineFeed)) + m_leftover_line = lines.takeLast(); return lines; } From 77932061bc244b301a9697281880ed2a8bae9e31 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 21 Mar 2023 18:33:41 +0100 Subject: [PATCH 2/3] chore: update ignores for Nix Signed-off-by: Sefa Eyeoglu --- .gitignore | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 3340670b..5c589a5f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,10 +24,6 @@ Debug build /build-* -# direnv / Nix -.direnv/ -.pre-commit-config.yaml - # Install dirs install /install-* @@ -48,7 +44,9 @@ run/ .cache/ # Nix/NixOS -result/ +.direnv/ +.pre-commit-config.yaml +result # Flatpak .flatpak-builder From 9418c62d95d8a9e829b087386cba2e2b6137daf1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 22 Mar 2023 10:32:17 +0100 Subject: [PATCH 3/3] refactor: reprocess log lines per instance Signed-off-by: Sefa Eyeoglu --- launcher/LoggedProcess.cpp | 5 +---- launcher/LoggedProcess.h | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/launcher/LoggedProcess.cpp b/launcher/LoggedProcess.cpp index 43a9c4f6..c8d5c34e 100644 --- a/launcher/LoggedProcess.cpp +++ b/launcher/LoggedProcess.cpp @@ -61,13 +61,10 @@ LoggedProcess::~LoggedProcess() } } -static QString m_leftover_line; - -QStringList reprocess(const QByteArray& data, QTextDecoder& decoder) +QStringList LoggedProcess::reprocess(const QByteArray& data, QTextDecoder& decoder) { auto str = decoder.toUnicode(data); - // FIXME: Flush this out when process exits if (!m_leftover_line.isEmpty()) { str.prepend(m_leftover_line); m_leftover_line = ""; diff --git a/launcher/LoggedProcess.h b/launcher/LoggedProcess.h index 2360d1ea..af3ed79f 100644 --- a/launcher/LoggedProcess.h +++ b/launcher/LoggedProcess.h @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher - * Copyright (C) 2022 Sefa Eyeoglu + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022,2023 Sefa Eyeoglu * * 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 @@ -88,9 +88,12 @@ private slots: private: void changeState(LoggedProcess::State state); + QStringList reprocess(const QByteArray& data, QTextDecoder& decoder); + private: QTextDecoder m_err_decoder = QTextDecoder(QTextCodec::codecForLocale()); QTextDecoder m_out_decoder = QTextDecoder(QTextCodec::codecForLocale()); + QString m_leftover_line; bool m_killed = false; State m_state = NotRunning; int m_exit_code = 0;