wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
InstallRelativePaths.cpp
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
5
6#include <QCoreApplication>
7#include <QDir>
8
9QStringList InstallRelativePaths::candidates(const QString &category)
10{
11 const QString appDir = QCoreApplication::applicationDirPath();
12
13 QStringList result = {
14 appDir + QLatin1Char('/') + category, // Windows / dev builds
15 };
16#ifdef Q_OS_MACOS
17 result << appDir + QStringLiteral("/../Resources/") + category; // macOS app bundle
18#endif
19#ifdef Q_OS_LINUX
20 result << qEnvironmentVariable("APPDIR") + QStringLiteral("/usr/share/wiredpanda/") + category; // AppImage
21 result << appDir + QStringLiteral("/../share/wiredpanda/") + category; // native FHS install (bin/ -> share/wiredpanda/<category>)
22#endif
23#ifdef Q_OS_WASM
24 result << QStringLiteral("/") + category; // WASM virtual filesystem
25#endif
26 result << category; // CWD fallback (development)
27
28 return result;
29}
30
31bool InstallRelativePaths::isCandidate(const QString &category, const QString &directory)
32{
33 // canonicalPath() resolves "..", symlinks and CWD-relative entries to one comparable
34 // form, and returns "" for a path that doesn't exist -- which is also the right answer
35 // here, since a directory that isn't there can't be the bundled content directory.
36 const QString target = QDir(directory).canonicalPath();
37 if (target.isEmpty()) {
38 return false;
39 }
40
41 const auto candidateDirs = candidates(category);
42 for (const QString &candidate : candidateDirs) {
43 if (candidate.isEmpty()) {
44 continue;
45 }
46 if (QDir(candidate).canonicalPath() == target) {
47 return true;
48 }
49 }
50 return false;
51}
52
53QString InstallRelativePaths::resolve(const QString &category)
54{
55 for (const QString &candidate : candidates(category)) {
56 if (!candidate.isEmpty() && QDir(candidate).exists()) {
57 return candidate;
58 }
59 }
60 return {};
61}
Per-platform resolution of install-relative content directories.
static bool isCandidate(const QString &category, const QString &directory)
static QString resolve(const QString &category)
static QStringList candidates(const QString &category)