mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-07-10 13:29:52 -04:00
rbutilqt: Simplify Utils::findExecutable() using QStandardPaths
Co-authored-by: Qwen3.7-Plus Change-Id: I8f6f4003ebc7b9a4a8139f5dd4dfca3ae6cff273
This commit is contained in:
parent
f9504df7bd
commit
f62e29f311
1 changed files with 5 additions and 20 deletions
|
|
@ -30,6 +30,7 @@
|
|||
#include <QtCore>
|
||||
#include <QDebug>
|
||||
#include <QStorageInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <QDirIterator>
|
||||
#include <cstdlib>
|
||||
#include <stdio.h>
|
||||
|
|
@ -259,27 +260,11 @@ qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
|
|||
//! \brief searches for a Executable in the Environement Path
|
||||
QString Utils::findExecutable(QString name)
|
||||
{
|
||||
//try autodetect tts
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) || defined(Q_OS_OPENBSD)
|
||||
QStringList path = QString(getenv("PATH")).split(":", Qt::SkipEmptyParts);
|
||||
#elif defined(Q_OS_WIN)
|
||||
QStringList path = QString(getenv("PATH")).split(";", Qt::SkipEmptyParts);
|
||||
#endif
|
||||
LOG_INFO() << "system path:" << path;
|
||||
for(int i = 0; i < path.size(); i++)
|
||||
{
|
||||
QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + name;
|
||||
#if defined(Q_OS_WIN)
|
||||
executable += ".exe";
|
||||
QStringList ex = executable.split("\"", Qt::SkipEmptyParts);
|
||||
executable = ex.join("");
|
||||
#endif
|
||||
if(QFileInfo(executable).isExecutable())
|
||||
{
|
||||
QString executable = QStandardPaths::findExecutable(name);
|
||||
if (!executable.isEmpty()) {
|
||||
LOG_INFO() << "findExecutable: found" << executable;
|
||||
return QDir::toNativeSeparators(executable);
|
||||
}
|
||||
}
|
||||
LOG_INFO() << "findExecutable: could not find" << name;
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue