From 15887c2d923d11268fb2a8ede877dbc4f4f39c38 Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Tue, 20 Aug 2024 21:53:05 +0300 Subject: [PATCH 01/11] truncate logs for mclo.gs upload to fit 25k line limit Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit 014fc142915ec4a0f96b3082f76d4d32ce7596aa) --- launcher/net/PasteUpload.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index c67d3b23c..5e8c5a8cd 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -49,6 +49,27 @@ #include "net/Logging.h" +constexpr int MaxMclogsLines = 25000; +constexpr int InitialMclogsLines = 10000; +constexpr int FinalMclogsLines = 14900; + +QString truncateLogForMclogs(const QString &logContent) { + QStringList lines = logContent.split("\n"); + if (lines.size() > MaxMclogsLines) { + QString truncatedLog = lines.mid(0, InitialMclogsLines).join("\n"); + truncatedLog += "\n\n\n\n\n\n\n\n\n\n" + "------------------------------------------------------------\n" + "--------------------- Log truncated by ---------------------\n" + "---------------------- Prism Launcher ----------------------\n" + "----- Middle portion omitted to fit mclo.gs size limits ----\n" + "------------------------------------------------------------\n" + "\n\n\n\n\n\n\n\n\n\n"; + truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n"); + return truncatedLog; + } + return logContent; +} + std::array PasteUpload::PasteTypes = { { { "0x0.st", "https://0x0.st", "" }, { "hastebin", "https://hst.sh", "/documents" }, { "paste.gg", "https://paste.gg", "/api/v1/pastes" }, @@ -98,6 +119,7 @@ void PasteUpload::executeTask() } case Mclogs: { QUrlQuery postData; + m_text = truncateLogForMclogs(m_text).toUtf8(); postData.addQueryItem("content", m_text); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); rep = APPLICATION->network()->post(request, postData.toString().toUtf8()); From cf8a82e78a8578bd04b50893eb5b921ddaf166f3 Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:14:40 +0300 Subject: [PATCH 02/11] fix formatting Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit e6f30c0ebe0ddd43b493f27156d6c0765105ded5) --- launcher/net/PasteUpload.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 5e8c5a8cd..92a44d5ed 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -53,17 +53,19 @@ constexpr int MaxMclogsLines = 25000; constexpr int InitialMclogsLines = 10000; constexpr int FinalMclogsLines = 14900; -QString truncateLogForMclogs(const QString &logContent) { +QString truncateLogForMclogs(const QString &logContent) +{ QStringList lines = logContent.split("\n"); if (lines.size() > MaxMclogsLines) { QString truncatedLog = lines.mid(0, InitialMclogsLines).join("\n"); - truncatedLog += "\n\n\n\n\n\n\n\n\n\n" - "------------------------------------------------------------\n" - "--------------------- Log truncated by ---------------------\n" - "---------------------- Prism Launcher ----------------------\n" - "----- Middle portion omitted to fit mclo.gs size limits ----\n" - "------------------------------------------------------------\n" - "\n\n\n\n\n\n\n\n\n\n"; + truncatedLog += + "\n\n\n\n\n\n\n\n\n\n" + "------------------------------------------------------------\n" + "--------------------- Log truncated by ---------------------\n" + "---------------------- Prism Launcher ----------------------\n" + "----- Middle portion omitted to fit mclo.gs size limits ----\n" + "------------------------------------------------------------\n" + "\n\n\n\n\n\n\n\n\n\n"; truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n"); return truncatedLog; } From db35f471057f7bd48a96453bc8352f88d50d4a64 Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:16:40 +0300 Subject: [PATCH 03/11] fix formatting Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit 858f6aa9b8adcb5d2ac9eadd2702a21a88f9e4c4) --- launcher/net/PasteUpload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 92a44d5ed..953a0d722 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -53,7 +53,7 @@ constexpr int MaxMclogsLines = 25000; constexpr int InitialMclogsLines = 10000; constexpr int FinalMclogsLines = 14900; -QString truncateLogForMclogs(const QString &logContent) +QString truncateLogForMclogs(const QString& logContent) { QStringList lines = logContent.split("\n"); if (lines.size() > MaxMclogsLines) { From 0cb5ac7a060f07beb324fe396a676b382f8ac128 Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:59:51 +0300 Subject: [PATCH 04/11] add a warning about the log being too large Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit cf914526bf5330600f3cadb9f4baddb5144af21f) --- launcher/net/PasteUpload.cpp | 24 ----------------- launcher/ui/GuiUtil.cpp | 51 +++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 953a0d722..c67d3b23c 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -49,29 +49,6 @@ #include "net/Logging.h" -constexpr int MaxMclogsLines = 25000; -constexpr int InitialMclogsLines = 10000; -constexpr int FinalMclogsLines = 14900; - -QString truncateLogForMclogs(const QString& logContent) -{ - QStringList lines = logContent.split("\n"); - if (lines.size() > MaxMclogsLines) { - QString truncatedLog = lines.mid(0, InitialMclogsLines).join("\n"); - truncatedLog += - "\n\n\n\n\n\n\n\n\n\n" - "------------------------------------------------------------\n" - "--------------------- Log truncated by ---------------------\n" - "---------------------- Prism Launcher ----------------------\n" - "----- Middle portion omitted to fit mclo.gs size limits ----\n" - "------------------------------------------------------------\n" - "\n\n\n\n\n\n\n\n\n\n"; - truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n"); - return truncatedLog; - } - return logContent; -} - std::array PasteUpload::PasteTypes = { { { "0x0.st", "https://0x0.st", "" }, { "hastebin", "https://hst.sh", "/documents" }, { "paste.gg", "https://paste.gg", "/api/v1/pastes" }, @@ -121,7 +98,6 @@ void PasteUpload::executeTask() } case Mclogs: { QUrlQuery postData; - m_text = truncateLogForMclogs(m_text).toUtf8(); postData.addQueryItem("content", m_text); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); rep = APPLICATION->network()->post(request, postData.toString().toUtf8()); diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 584a34710..3b0eccd02 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -51,11 +51,35 @@ #include #include "Application.h" +constexpr int MaxMclogsLines = 25000; +constexpr int InitialMclogsLines = 10000; +constexpr int FinalMclogsLines = 14900; + +QString truncateLogForMclogs(const QString& logContent) +{ + QStringList lines = logContent.split("\n"); + if (lines.size() > MaxMclogsLines) { + QString truncatedLog = lines.mid(0, InitialMclogsLines).join("\n"); + truncatedLog += + "\n\n\n\n\n\n\n\n\n\n" + "------------------------------------------------------------\n" + "--------------------- Log truncated by ---------------------\n" + "---------------------- Prism Launcher ----------------------\n" + "----- Middle portion omitted to fit mclo.gs size limits ----\n" + "------------------------------------------------------------\n" + "\n\n\n\n\n\n\n\n\n\n"; + truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n"); + return truncatedLog; + } + return logContent; +} + std::optional GuiUtil::uploadPaste(const QString& name, const QString& text, QWidget* parentWidget) { ProgressDialog dialog(parentWidget); auto pasteTypeSetting = static_cast(APPLICATION->settings()->get("PastebinType").toInt()); auto pasteCustomAPIBaseSetting = APPLICATION->settings()->get("PastebinCustomAPIBase").toString(); + bool shouldTruncate = false; { QUrl baseUrl; @@ -75,10 +99,35 @@ std::optional GuiUtil::uploadPaste(const QString& name, const QString& if (response != QMessageBox::Yes) return {}; + + if (baseUrl.toString() == "https://api.mclo.gs" && text.count("\n") > MaxMclogsLines) { + auto truncateResponse = + CustomMessageBox::selectable(parentWidget, QObject::tr("Confirm Truncate"), + QObject::tr("The log exceeds mclo.gs' limit: %1 lines (max %2).\n" + "Prism can keep the first %3 and last %4 lines, trimming the middle.\n\n" + "If you choose 'No', mclo.gs will only keep the first %2 lines, cutting off " + "potentially useful info like crashes at the end.\n\n" + "Proceed with Prism's truncation?") + .arg(text.count("\n")) + .arg(MaxMclogsLines) + .arg(InitialMclogsLines) + .arg(FinalMclogsLines), + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) + ->exec(); + + if (truncateResponse == QMessageBox::Yes) + shouldTruncate = true; + } } } - std::unique_ptr paste(new PasteUpload(parentWidget, text, pasteCustomAPIBaseSetting, pasteTypeSetting)); + QString textToUpload; + if (shouldTruncate) + textToUpload = truncateLogForMclogs(text); + else + textToUpload = text; + + std::unique_ptr paste(new PasteUpload(parentWidget, textToUpload, pasteCustomAPIBaseSetting, pasteTypeSetting)); dialog.execWithTask(paste.get()); if (!paste->wasSuccessful()) { From 589ee73bfd78818f46de505501c09b8e2db65994 Mon Sep 17 00:00:00 2001 From: maskers <97827489+maskersss@users.noreply.github.com> Date: Wed, 21 Aug 2024 19:42:35 +0300 Subject: [PATCH 05/11] Apply suggestions from code review Co-authored-by: Alexandru Ionut Tripon Signed-off-by: maskers <97827489+maskersss@users.noreply.github.com> (cherry picked from commit 99bd4a89373416cea641f1421d1082ff823eba2e) --- launcher/ui/GuiUtil.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 3b0eccd02..de72a7d5d 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -115,17 +115,15 @@ std::optional GuiUtil::uploadPaste(const QString& name, const QString& QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ->exec(); - if (truncateResponse == QMessageBox::Yes) - shouldTruncate = true; + shouldTruncate = truncateResponse == QMessageBox::Yes; } } } - QString textToUpload; - if (shouldTruncate) + QString textToUpload = text; + if (shouldTruncate) { textToUpload = truncateLogForMclogs(text); - else - textToUpload = text; + } std::unique_ptr paste(new PasteUpload(parentWidget, textToUpload, pasteCustomAPIBaseSetting, pasteTypeSetting)); From e234c6681844bff8fedc2dbeff15c33391ec0c23 Mon Sep 17 00:00:00 2001 From: maskers <97827489+maskersss@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:14:11 +0300 Subject: [PATCH 06/11] add a `Cancel` option Co-authored-by: Rachel Powers <508861+Ryex@users.noreply.github.com> Signed-off-by: maskers <97827489+maskersss@users.noreply.github.com> (cherry picked from commit 65f852615247f6c1ba3cd81cf9e51ebc0220341b) --- launcher/ui/GuiUtil.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index de72a7d5d..cfc1715fc 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -112,9 +112,10 @@ std::optional GuiUtil::uploadPaste(const QString& name, const QString& .arg(MaxMclogsLines) .arg(InitialMclogsLines) .arg(FinalMclogsLines), - QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No) ->exec(); + if (truncateResponse == QMessageBox::Cancel) { return {} ; } shouldTruncate = truncateResponse == QMessageBox::Yes; } } From 417bb2fce689fdb80173fafdb2ca0a2f95551b57 Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:39:27 +0300 Subject: [PATCH 07/11] fix formatting Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit 6d017b5f0b9fd878d387bf33585221ea079e305b) --- launcher/ui/GuiUtil.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index cfc1715fc..5cdd30e17 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -101,21 +101,23 @@ std::optional GuiUtil::uploadPaste(const QString& name, const QString& return {}; if (baseUrl.toString() == "https://api.mclo.gs" && text.count("\n") > MaxMclogsLines) { - auto truncateResponse = - CustomMessageBox::selectable(parentWidget, QObject::tr("Confirm Truncate"), - QObject::tr("The log exceeds mclo.gs' limit: %1 lines (max %2).\n" - "Prism can keep the first %3 and last %4 lines, trimming the middle.\n\n" - "If you choose 'No', mclo.gs will only keep the first %2 lines, cutting off " - "potentially useful info like crashes at the end.\n\n" - "Proceed with Prism's truncation?") - .arg(text.count("\n")) - .arg(MaxMclogsLines) - .arg(InitialMclogsLines) - .arg(FinalMclogsLines), - QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No) - ->exec(); + auto truncateResponse = CustomMessageBox::selectable( + parentWidget, QObject::tr("Confirm Truncate"), + QObject::tr("The log exceeds mclo.gs' limit: %1 lines (max %2).\n" + "Prism can keep the first %3 and last %4 lines, trimming the middle.\n\n" + "If you choose 'No', mclo.gs will only keep the first %2 lines, cutting off " + "potentially useful info like crashes at the end.\n\n" + "Proceed with Prism's truncation?") + .arg(text.count("\n")) + .arg(MaxMclogsLines) + .arg(InitialMclogsLines) + .arg(FinalMclogsLines), + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No) + ->exec(); - if (truncateResponse == QMessageBox::Cancel) { return {} ; } + if (truncateResponse == QMessageBox::Cancel) { + return {}; + } shouldTruncate = truncateResponse == QMessageBox::Yes; } } From 3048e4390027b4d05db1ff9ef14794c7e4ddd497 Mon Sep 17 00:00:00 2001 From: maskers <97827489+maskersss@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:42:05 +0300 Subject: [PATCH 08/11] apply suggestion from code review Co-authored-by: TheKodeToad Signed-off-by: maskers <97827489+maskersss@users.noreply.github.com> (cherry picked from commit a910337e9d148937fc6a7339a7bcdd9a2db1ec03) --- launcher/ui/GuiUtil.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 5cdd30e17..4d2e64af4 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -103,11 +103,11 @@ std::optional GuiUtil::uploadPaste(const QString& name, const QString& if (baseUrl.toString() == "https://api.mclo.gs" && text.count("\n") > MaxMclogsLines) { auto truncateResponse = CustomMessageBox::selectable( parentWidget, QObject::tr("Confirm Truncate"), - QObject::tr("The log exceeds mclo.gs' limit: %1 lines (max %2).\n" - "Prism can keep the first %3 and last %4 lines, trimming the middle.\n\n" + QObject::tr("The log has %1 lines, exceeding mclo.gs' limit of %2.\n" + "The launcher can keep the first %3 and last %4 lines, trimming the middle.\n\n" "If you choose 'No', mclo.gs will only keep the first %2 lines, cutting off " "potentially useful info like crashes at the end.\n\n" - "Proceed with Prism's truncation?") + "Proceed with truncation?") .arg(text.count("\n")) .arg(MaxMclogsLines) .arg(InitialMclogsLines) From 01397896eb06fbe13a892fde913152c565b5e029 Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:44:53 +0300 Subject: [PATCH 09/11] don't mention prism in the middle of the log Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit 762d24bd02ae6a0c0f241626c9c06deeaae86574) --- launcher/ui/GuiUtil.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 4d2e64af4..77d4a98e2 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -63,8 +63,8 @@ QString truncateLogForMclogs(const QString& logContent) truncatedLog += "\n\n\n\n\n\n\n\n\n\n" "------------------------------------------------------------\n" - "--------------------- Log truncated by ---------------------\n" - "---------------------- Prism Launcher ----------------------\n" + "----------------------- Log truncated ----------------------\n" + "------------------------------------------------------------\n" "----- Middle portion omitted to fit mclo.gs size limits ----\n" "------------------------------------------------------------\n" "\n\n\n\n\n\n\n\n\n\n"; From cffa9a2da0000b0b2a5dbb87bd5885d161c98e2a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 25 Aug 2024 13:05:08 +0100 Subject: [PATCH 10/11] Confirm Truncate -> Truncation Signed-off-by: TheKodeToad (cherry picked from commit 43fc9ba932ec65d274b60bafb4d3c3f1d5bf55f0) --- launcher/ui/GuiUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 77d4a98e2..ccb4e48b5 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -102,7 +102,7 @@ std::optional GuiUtil::uploadPaste(const QString& name, const QString& if (baseUrl.toString() == "https://api.mclo.gs" && text.count("\n") > MaxMclogsLines) { auto truncateResponse = CustomMessageBox::selectable( - parentWidget, QObject::tr("Confirm Truncate"), + parentWidget, QObject::tr("Confirm Truncation"), QObject::tr("The log has %1 lines, exceeding mclo.gs' limit of %2.\n" "The launcher can keep the first %3 and last %4 lines, trimming the middle.\n\n" "If you choose 'No', mclo.gs will only keep the first %2 lines, cutting off " From c8c3370d36aa1df3e7262ef7eaf4b2e624b36d4e Mon Sep 17 00:00:00 2001 From: maskers <97827489+mskrss@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:02:32 +0300 Subject: [PATCH 11/11] fix off by one error Signed-off-by: maskers <97827489+mskrss@users.noreply.github.com> (cherry picked from commit 6a12c43c787db4a64748d6c3d03b34981948d7ce) --- launcher/ui/GuiUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index ccb4e48b5..94dd01169 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -68,7 +68,7 @@ QString truncateLogForMclogs(const QString& logContent) "----- Middle portion omitted to fit mclo.gs size limits ----\n" "------------------------------------------------------------\n" "\n\n\n\n\n\n\n\n\n\n"; - truncatedLog += lines.mid(lines.size() - FinalMclogsLines, FinalMclogsLines).join("\n"); + truncatedLog += lines.mid(lines.size() - FinalMclogsLines - 1).join("\n"); return truncatedLog; } return logContent;