mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Hide ProcessNameByPID and RealExecutablePath into a private namespace
This commit is contained in:
parent
e081ed4b4a
commit
256e976167
2 changed files with 27 additions and 30 deletions
|
@ -132,6 +132,33 @@ uint FileChooserPortalVersion() {
|
||||||
}
|
}
|
||||||
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
|
QString ProcessNameByPID(const QString &pid) {
|
||||||
|
constexpr auto kMaxPath = 1024;
|
||||||
|
char result[kMaxPath] = { 0 };
|
||||||
|
auto count = readlink("/proc/" + pid.toLatin1() + "/exe", result, kMaxPath);
|
||||||
|
if (count > 0) {
|
||||||
|
auto filename = QFile::decodeName(result);
|
||||||
|
auto deletedPostfix = qstr(" (deleted)");
|
||||||
|
if (filename.endsWith(deletedPostfix) && !QFileInfo(filename).exists()) {
|
||||||
|
filename.chop(deletedPostfix.size());
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RealExecutablePath(int argc, char *argv[]) {
|
||||||
|
const auto processName = ProcessNameByPID(qsl("self"));
|
||||||
|
|
||||||
|
// Fallback to the first command line argument.
|
||||||
|
return !processName.isEmpty()
|
||||||
|
? processName
|
||||||
|
: argc
|
||||||
|
? QFile::decodeName(argv[0])
|
||||||
|
: QString();
|
||||||
|
}
|
||||||
|
|
||||||
bool RunShellCommand(const QByteArray &command) {
|
bool RunShellCommand(const QByteArray &command) {
|
||||||
auto result = system(command.constData());
|
auto result = system(command.constData());
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -642,33 +669,6 @@ bool CanOpenDirectoryWithPortal() {
|
||||||
#endif // (Qt < 5.15 && !DESKTOP_APP_QT_PATCHED) || TDESKTOP_DISABLE_DBUS_INTEGRATION
|
#endif // (Qt < 5.15 && !DESKTOP_APP_QT_PATCHED) || TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProcessNameByPID(const QString &pid) {
|
|
||||||
constexpr auto kMaxPath = 1024;
|
|
||||||
char result[kMaxPath] = { 0 };
|
|
||||||
auto count = readlink("/proc/" + pid.toLatin1() + "/exe", result, kMaxPath);
|
|
||||||
if (count > 0) {
|
|
||||||
auto filename = QFile::decodeName(result);
|
|
||||||
auto deletedPostfix = qstr(" (deleted)");
|
|
||||||
if (filename.endsWith(deletedPostfix) && !QFileInfo(filename).exists()) {
|
|
||||||
filename.chop(deletedPostfix.size());
|
|
||||||
}
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RealExecutablePath(int argc, char *argv[]) {
|
|
||||||
const auto processName = ProcessNameByPID(qsl("self"));
|
|
||||||
|
|
||||||
// Fallback to the first command line argument.
|
|
||||||
return !processName.isEmpty()
|
|
||||||
? processName
|
|
||||||
: argc
|
|
||||||
? QFile::decodeName(argv[0])
|
|
||||||
: QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||||
if (InAppImage()) {
|
if (InAppImage()) {
|
||||||
const auto appimagePath = QString::fromUtf8(qgetenv("APPIMAGE"));
|
const auto appimagePath = QString::fromUtf8(qgetenv("APPIMAGE"));
|
||||||
|
|
|
@ -33,9 +33,6 @@ bool IsXDGDesktopPortalPresent();
|
||||||
bool UseXDGDesktopPortal();
|
bool UseXDGDesktopPortal();
|
||||||
bool CanOpenDirectoryWithPortal();
|
bool CanOpenDirectoryWithPortal();
|
||||||
|
|
||||||
QString ProcessNameByPID(const QString &pid);
|
|
||||||
QString RealExecutablePath(int argc, char *argv[]);
|
|
||||||
|
|
||||||
QString AppRuntimeDirectory();
|
QString AppRuntimeDirectory();
|
||||||
|
|
||||||
QString GetLauncherBasename();
|
QString GetLauncherBasename();
|
||||||
|
|
Loading…
Add table
Reference in a new issue