From 3fd83da4aeda234a644a06b740b0e1275b82487c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Thu, 15 Aug 2024 15:26:13 +0200 Subject: [PATCH] Check write access to conf dirs --- src/app/main.cpp | 9 +++++++++ src/core/appsupport.cpp | 23 +++++++++++++++++++++++ src/core/appsupport.h | 1 + 3 files changed, 33 insertions(+) diff --git a/src/app/main.cpp b/src/app/main.cpp index 8c2bd6bbd..208bfaa5f 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -217,6 +217,15 @@ int main(int argc, char *argv[]) gPrintExceptionCritical(e); } + // check permissions + const auto perms = AppSupport::hasWriteAccess(); + if (!perms.second) { + QMessageBox::warning(nullptr, + QObject::tr("Permission issue"), + QObject::tr("Friction needs read/write access to:

- %1").arg(perms.first.join("
- "))); + return -1; + } + eFilterSettings filterSettings; eWidgetsImpl widImpl; diff --git a/src/core/appsupport.cpp b/src/core/appsupport.cpp index c5c538830..ab50cda95 100644 --- a/src/core/appsupport.cpp +++ b/src/core/appsupport.cpp @@ -579,3 +579,26 @@ const QString AppSupport::filterTextAZW(const QString &text) QString output = text; return output.replace(regex, ""); } + +const QPair AppSupport::hasWriteAccess() +{ + QPair result(QStringList(), true); + + QStringList dirs; + dirs << getAppConfigPath(); + dirs << getAppOutputProfilesPath(); + dirs << getAppShaderEffectsPath(); + for (const auto &dir : dirs) { + if (dir.isEmpty()) { continue; } + QFileInfo info(dir); + if (!info.isDir() || + !info.exists() || + !info.isReadable() || + !info.isWritable()) { + result.second = false; + result.first << info.absoluteFilePath(); + } + } + + return result; +} diff --git a/src/core/appsupport.h b/src/core/appsupport.h index a6c2dafed..9d949e56e 100644 --- a/src/core/appsupport.h +++ b/src/core/appsupport.h @@ -104,6 +104,7 @@ class CORE_EXPORT AppSupport : public QObject static bool removeResolutionPreset(const int w, const int h); static QPair getResolutionPresetStatus(); static const QString filterTextAZW(const QString &text); + static const QPair hasWriteAccess(); }; #endif // APPSUPPORT_H