From 45d611a9d7f36002106f7408c07d5225292fd460 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Thu, 28 Nov 2024 17:32:55 +0800 Subject: [PATCH] fix: Fixed the default path issue Fixed the default path issue Bug: https://pms.uniontech.com/bug-view-272475.html Log: Fixed the default path issue --- src/main/main.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/main.cpp b/src/main/main.cpp index a0f9d0b8b..b0d0362a1 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -28,8 +29,39 @@ DCORE_USE_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(mainprocess) +bool checkImmutableMode() { + QProcess process; + QStringList arguments; + arguments << "-s"; // 命令参数 + + // 启动进程并等待其完成 + process.start("deepin-immutable-ctl", arguments); + if (!process.waitForStarted()) { + qWarning() << "Failed to start deepin-immutable-ctl:" << process.errorString(); + return false; + } + + if (!process.waitForFinished()) { + qWarning() << "deepin-immutable-ctl did not finish successfully:" << process.errorString(); + return false; + } + + // 获取命令输出 + QByteArray output = process.readAllStandardOutput(); + QString result = QString::fromUtf8(output.trimmed()); + if (result.split(":").at(1) == "true") { + qInfo() << "System is in immutable mode."; + return true; + } else { + qInfo() << "System is not in immutable mode. Output was:" << result; + return false; + } +} + int main(int argc, char *argv[]) { + if (checkImmutableMode()) + setenv("PWD", getenv("HOME"), 1); if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) { setenv("XDG_CURRENT_DESKTOP", "Deepin", 1); }