Browse Source

Refine logic to search the binary from the Exec= entry

master
probonopd 8 years ago
parent
commit
50ac681433
  1. 38
      linuxdeployqt/main.cpp

38
linuxdeployqt/main.cpp

@ -59,32 +59,46 @@ int main(int argc, char **argv)
desktopFile = firstArgument; desktopFile = firstArgument;
desktopIconEntry = settings->value("Desktop Entry/Icon", "r").toString().split(' ').first().trimmed(); desktopIconEntry = settings->value("Desktop Entry/Icon", "r").toString().split(' ').first().trimmed();
qDebug() << "desktopIconEntry:" << desktopIconEntry; qDebug() << "desktopIconEntry:" << desktopIconEntry;
// QString candidateBin1 = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../../bin/" + desktopExecEntry); // FHS-like
QString candidateBin2 = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + desktopExecEntry); // Not FHS-like QString candidateBin = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + desktopExecEntry); // Not FHS-like
/* Search directory for an executable with the name in the Exec= key */ /* Search directory for an executable with the name in the Exec= key */
QString directoryToBeSearched; QString directoryToBeSearched;
if(QFileInfo(QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/" + desktopExecEntry)).exists()){
directoryToBeSearched = QDir::cleanPath(QFileInfo(firstArgument).absolutePath()); directoryToBeSearched = QDir::cleanPath(QFileInfo(firstArgument).absolutePath());
} else if(QFileInfo(QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../../bin/" + desktopExecEntry)).exists()){
directoryToBeSearched = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../../");
} else {
directoryToBeSearched = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../");
}
QDirIterator it(directoryToBeSearched, QDirIterator::Subdirectories); QDirIterator it(directoryToBeSearched, QDirIterator::Subdirectories);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
if((it.fileName() == desktopExecEntry) && (it.fileInfo().isExecutable())){ if((it.fileName() == desktopExecEntry) && (it.fileInfo().isExecutable())){
qDebug() << "Found binary from desktop file:" << it.fileInfo().canonicalFilePath(); qDebug() << "Found binary from desktop file:" << it.fileInfo().canonicalFilePath();
appBinaryPath = it.fileInfo().canonicalFilePath(); appBinaryPath = it.fileInfo().absoluteFilePath();
break; break;
} }
} }
/* Only if we could not find it below the directory in which the desktop file resides, search above */
if(appBinaryPath == ""){
if(QFileInfo(QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../../bin/" + desktopExecEntry)).exists()){
directoryToBeSearched = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../../");
} else {
directoryToBeSearched = QDir::cleanPath(QFileInfo(firstArgument).absolutePath() + "/../");
}
QDirIterator it2(directoryToBeSearched, QDirIterator::Subdirectories);
while (it2.hasNext()) {
it2.next();
if((it2.fileName() == desktopExecEntry) && (it2.fileInfo().isExecutable())){
qDebug() << "Found binary from desktop file:" << it2.fileInfo().canonicalFilePath();
appBinaryPath = it2.fileInfo().absoluteFilePath();
break;
}
}
}
if(appBinaryPath == ""){ if(appBinaryPath == ""){
if(QFileInfo(candidateBin2).isExecutable()) { if(QFileInfo(candidateBin).isExecutable()) {
appBinaryPath = candidateBin2; appBinaryPath = QFileInfo(candidateBin).absoluteFilePath();
} else { } else {
LogError() << "Could not determine the path to the executable based on the desktop file\n"; LogError() << "Could not determine the path to the executable based on the desktop file\n";
return 1; return 1;
@ -93,7 +107,7 @@ int main(int argc, char **argv)
} else { } else {
appBinaryPath = firstArgument; appBinaryPath = firstArgument;
appBinaryPath = QDir::cleanPath(appBinaryPath); appBinaryPath = QFileInfo(QDir::cleanPath(appBinaryPath)).absoluteFilePath();
} }
} }

Loading…
Cancel
Save