QuasarAppLib/qaplatformutils_linux.cpp

100 lines
2.6 KiB
C++
Raw Normal View History

2024-01-21 10:42:50 +01:00
/*
2024-12-30 22:39:49 +01:00
* Copyright (C) 2024-2025 QuasarApp.
2024-01-21 10:42:50 +01:00
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
#include "qaplatformutils.h"
2024-01-21 10:58:07 +01:00
#if defined(Q_OS_LINUX)
2024-01-21 10:42:50 +01:00
#include <QDir>
#include <QFileInfo>
#include <QProcessEnvironment>
2024-01-21 10:58:07 +01:00
#elif defined(Q_OS_ANDROID)
#elif defined(Q_OS_WIN32)
#elif defined(Q_OS_MACOS)
#elif defined(Q_OS_IOS)
2024-01-21 10:42:50 +01:00
#endif
namespace QuasarAppUtils {
2024-01-21 10:58:07 +01:00
#if defined(Q_OS_LINUX)
2024-01-21 10:42:50 +01:00
bool PlatformUtils::isSnap() {
return QProcessEnvironment::systemEnvironment().value("SNAP").size();
}
QString PlatformUtils::snapRootFS() {
return "/var/lib/snapd/hostfs";
}
QString PlatformUtils::transportPathToSnapRoot(const QString &path) {
if (isSnap() && checkSystemBakupSnapInterface()) {
if(QFileInfo(path).isWritable()) {
return path;
}
if (path.size() && path[0] != QString("/")) {
auto absalutPath = QProcessEnvironment::systemEnvironment().value("PWD") + "/" + path;
if (!absalutPath.contains(snapRootFS())) {
return snapRootFS() + "/" + absalutPath;
}
}
if (!path.contains(snapRootFS())) {
return snapRootFS() + "/" + path;
}
}
return path;
}
bool PlatformUtils::checkSystemBakupSnapInterface() {
return QDir(snapRootFS()).entryList(QDir::AllEntries | QDir::NoDotAndDotDot).size();
}
2024-01-21 10:58:07 +01:00
#elif defined(Q_OS_ANDROID)
2024-01-21 10:47:50 +01:00
bool PlatformUtils::isSnap() { return false;}
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
QString PlatformUtils::snapRootFS() { return "";}
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
QString PlatformUtils::transportPathToSnapRoot(const QString &path) { return path; }
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
bool PlatformUtils::checkSystemBakupSnapInterface() { return false; }
2024-01-21 10:58:07 +01:00
#elif defined(Q_OS_WIN32)
2024-01-21 10:47:50 +01:00
bool PlatformUtils::isSnap() { return false;}
QString PlatformUtils::snapRootFS() { return "";}
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
QString PlatformUtils::transportPathToSnapRoot(const QString &path) { return path; }
bool PlatformUtils::checkSystemBakupSnapInterface() { return false; }
2024-01-21 10:58:07 +01:00
#elif defined(Q_OS_MACOS)
2024-01-21 10:47:50 +01:00
bool PlatformUtils::isSnap() { return false;}
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
QString PlatformUtils::snapRootFS() { return "";}
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
QString PlatformUtils::transportPathToSnapRoot(const QString &path) { return path; }
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
bool PlatformUtils::checkSystemBakupSnapInterface() { return false; }
2024-01-21 10:58:07 +01:00
#elif defined(Q_OS_IOS)
2024-01-21 10:47:50 +01:00
bool PlatformUtils::isSnap() { return false;}
QString PlatformUtils::snapRootFS() { return "";}
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
QString PlatformUtils::transportPathToSnapRoot(const QString &path) { return path; }
2024-01-21 10:42:50 +01:00
2024-01-21 10:47:50 +01:00
bool PlatformUtils::checkSystemBakupSnapInterface() { return false; }
2024-01-21 10:58:07 +01:00
2024-01-21 10:42:50 +01:00
#endif
}