Skip to content

Commit

Permalink
Check write access to conf dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 15, 2024
1 parent 16e45d7 commit 3fd83da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br><br>- %1").arg(perms.first.join("<br>- ")));
return -1;
}

eFilterSettings filterSettings;

eWidgetsImpl widImpl;
Expand Down
23 changes: 23 additions & 0 deletions src/core/appsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,26 @@ const QString AppSupport::filterTextAZW(const QString &text)
QString output = text;
return output.replace(regex, "");
}

const QPair<QStringList, bool> AppSupport::hasWriteAccess()
{
QPair<QStringList,bool> 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;
}
1 change: 1 addition & 0 deletions src/core/appsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class CORE_EXPORT AppSupport : public QObject
static bool removeResolutionPreset(const int w, const int h);
static QPair<bool, bool> getResolutionPresetStatus();
static const QString filterTextAZW(const QString &text);
static const QPair<QStringList,bool> hasWriteAccess();
};

#endif // APPSUPPORT_H

0 comments on commit 3fd83da

Please sign in to comment.