From dfce4278910141d6ac78ccfbb2c6ab5748413e49 Mon Sep 17 00:00:00 2001 From: uniartisan Date: Thu, 21 Sep 2023 19:55:28 +0800 Subject: [PATCH] =?UTF-8?q?enhance:=20=E6=9B=B4=E8=AF=A6=E7=BB=86=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 541e3ab..a9f3f39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,21 @@ DWIDGET_USE_NAMESPACE static QString buildDateTime; +void gatherInfo(FILE *fp, std::ofstream& logFile, const char* description) { + if (fp) { + char buffer[512]; + logFile << description << ":\n"; + while (fgets(buffer, sizeof(buffer), fp) != NULL) { + buffer[strcspn(buffer, "\n")] = 0; + logFile << buffer << "\n"; + } + pclose(fp); + } else { + logFile << "Failed to gather " << description << " info.\n"; + } +} + + void crashHandler(int sig) { void *array[50]; size_t size = backtrace(array, 50); @@ -42,40 +58,24 @@ void crashHandler(int sig) { tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); std::ofstream logFile(filename, std::ios::out); + if (!logFile.is_open()) { perror("ofstream"); exit(1); } logFile << "Please send this log to the developer. QQ Group: 872690351\n"; + logFile << "Gitee: https://gitee.com/deepin-community-store/spark-store/issues\n"; + logFile << "Gihub: https://github.com/spark-store-project/spark-store/issues\n"; logFile << "Build Date and Time: " << buildDateTime.toStdString() << "\n"; + gatherInfo(popen("cat ~/.config/spark-union/spark-store/config.ini", "r"), logFile, "User Config File"); - FILE *fp = popen("uname -m", "r"); - if (fp) { - char buffer[256]; - if (fgets(buffer, sizeof(buffer), fp) != NULL) { - // 移除换行符 - buffer[strcspn(buffer, "\n")] = 0; - logFile << "CPU Architecture: " << buffer << "\n"; - } - pclose(fp); - } else { - logFile << "Failed to gather CPU architecture info.\n"; - } - - - - - FILE *fp2 = popen("lsb_release -a", "r"); - if (fp2) { - char buffer[256]; - while (fgets(buffer, sizeof(buffer), fp2) != NULL) { - logFile << buffer; - } - pclose(fp2); - } else { - logFile << "Failed to gather distribution info.\n"; - } + // Collecting System Information + gatherInfo(popen("uname -m", "r"), logFile, "CPU Architecture"); + gatherInfo(popen("lsb_release -a", "r"), logFile, "Distribution info"); + gatherInfo(popen("LANG=C lscpu", "r"), logFile, "All CPU Info"); + gatherInfo(popen("free -h | grep Mem | awk '{print $2}'", "r"), logFile, "Memory Size"); + logFile << "Error: signal " << sig << ":\n";