From 867e480410be4c90ee2ae4acbd05e8fb1532a4c1 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 00:40:20 +0000 Subject: [PATCH 01/10] Adds support for .AppImage and implements parsing for .desktop --- src/main.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d65bfea..9a219a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include /* * This tool handles four types of applications: @@ -138,8 +139,21 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList candidates.append(AppCand); } } + else if (file.fileName() == firstArg + ".AppImage") { + QString AppCand = filename; + candidates.append(AppCand); + } else if (file.fileName() == firstArg + ".desktop") { - // .desktop file + // load the .desktop file for parsing - QSettings::IniFormat returns values as strings by default + // see https://doc.qt.io/qt-5/qsettings.html + QSettings desktopFile = QSettings(filename, QSettings::IniFormat) + QString AppCand = desktopFile.value("Desktop Entry/Exec"); + + // null safety check + if (AppCand != null) { + qDebug << "# Found" << AppCand; + candidates.append(AppCand); + } qDebug() << "# Found" << file.fileName() << "TODO: Parse it for Exec="; } else if (locationsContainingApps.contains(filename) == false && file.isDir() && filename.endsWith("/..") == false && filename.endsWith("/.") == false && filename.endsWith(".app") == false && filename.endsWith(".AppDir") == false) { @@ -147,7 +161,7 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList // Shall we descend into it? Only if it contains at least one application, to optimize for speed // by not descending into directory trees that do not contain any applications at all. Can make // a big difference. - QStringList nameFilter({"*.app", "*.AppDir", "*.desktop"}); + QStringList nameFilter({"*.app", "*.AppDir", "*.desktop", ".AppImage"}); QDir directory(filename); int numberOfAppsInDirectory = directory.entryList(nameFilter).length(); if(numberOfAppsInDirectory > 0) { @@ -222,12 +236,16 @@ int main(int argc, char *argv[]) firstArg = args.first(); if (QFile::exists(firstArg)){ QFileInfo info = QFileInfo(firstArg); - if ( firstArg.endsWith(".AppDir") || firstArg.endsWith(".app") ){ + if ( firstArg.endsWith(".AppDir") || firstArg.endsWith(".app") || firstArg.endsWith(".AppImage") ){ qDebug() << "# Found" << firstArg; QString candidate; if(firstArg.endsWith(".AppDir")) { candidate = firstArg + "/AppRun"; } + else if (firstArg.endsWith(".AppImage")) { + // this is a .AppImage file, we have nothing else to do here, so just make it a candidate + candidate = firstArg; + } else { // The .app could be a symlink, so we need to determine the nameWithoutSuffix from its target QFileInfo fileInfo = QFileInfo(QDir(firstArg).canonicalPath()); @@ -273,7 +291,7 @@ int main(int argc, char *argv[]) // Iterate recursively through locationsContainingApps searching for AppRun files in matchingly named AppDirs QFileInfoList candidates; - QString firstArgWithoutWellKnownSuffix = firstArg.replace(".AppDir", "").replace(".app", "").replace(".desktop" ,""); + QString firstArgWithoutWellKnownSuffix = firstArg.replace(".AppDir", "").replace(".app", "").replace(".desktop" ,"").replace(".AppImage", ""); candidates = findAppsInside(locationsContainingApps, candidates, firstArgWithoutWellKnownSuffix); From eeeb8caff498a5557ef6511c1ae84d8036a24a69 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 00:45:45 +0000 Subject: [PATCH 02/10] fix qdebug to have paranthesies --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9a219a9..2030678 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -151,7 +151,7 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList // null safety check if (AppCand != null) { - qDebug << "# Found" << AppCand; + qDebug() << "# Found" << AppCand; candidates.append(AppCand); } qDebug() << "# Found" << file.fileName() << "TODO: Parse it for Exec="; From d3f05391e95750213879e28e0bf9bd4361288b16 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 00:47:54 +0000 Subject: [PATCH 03/10] fix code --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2030678..8ae9cdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,7 +146,7 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList else if (file.fileName() == firstArg + ".desktop") { // load the .desktop file for parsing - QSettings::IniFormat returns values as strings by default // see https://doc.qt.io/qt-5/qsettings.html - QSettings desktopFile = QSettings(filename, QSettings::IniFormat) + QSettings desktopFile = QSettings(filename, QSettings::IniFormat); QString AppCand = desktopFile.value("Desktop Entry/Exec"); // null safety check From 9567998e9733718d0352aaff1bd3102c997a9376 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 00:49:26 +0000 Subject: [PATCH 04/10] fix null check --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8ae9cdc..2c087b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,7 +150,7 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList QString AppCand = desktopFile.value("Desktop Entry/Exec"); // null safety check - if (AppCand != null) { + if (AppCand != NULL) { qDebug() << "# Found" << AppCand; candidates.append(AppCand); } From b475dd065b71d73b7423b19179d256831ccc0ed9 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 00:55:26 +0000 Subject: [PATCH 05/10] fix parsing of .desktop files --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2c087b9..f425256 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,8 +146,8 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList else if (file.fileName() == firstArg + ".desktop") { // load the .desktop file for parsing - QSettings::IniFormat returns values as strings by default // see https://doc.qt.io/qt-5/qsettings.html - QSettings desktopFile = QSettings(filename, QSettings::IniFormat); - QString AppCand = desktopFile.value("Desktop Entry/Exec"); + QSettings desktopFile(filename, QSettings::IniFormat); + QString AppCand = desktopFile.value("Desktop Entry/Exec").toString(); // null safety check if (AppCand != NULL) { From 99e23dad1d320b9fbc689531d187b15ac72db381 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 00:57:14 +0000 Subject: [PATCH 06/10] ignore build directory --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f147edf..b61296e 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ compile_commands.json # QtCreator local machine specific files for imported projects *creator.user* + +# ignore build directory +build \ No newline at end of file From c77b0b193b076307be69717c93be74509a8d9184 Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Sun, 14 Mar 2021 17:03:36 +0000 Subject: [PATCH 07/10] fix last if statement --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7f4bee2..22ef52b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,12 +169,12 @@ QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList } qDebug() << "# Found" << file.fileName() << "TODO: Parse it for Exec="; } - else if (locationsContainingApps.contains(filename) == false && file.isDir() && filename.endsWith("/..") == false && filename.endsWith("/.") == false && filename.endsWith(".app") == false && filename.endsWith(".AppDir") == false) { + else if (locationsContainingApps.contains(filename) == false && file.isDir() && filename.endsWith("/..") == false && filename.endsWith("/.") == false && filename.endsWith(".app") == false && filename.endsWith(".AppDir") == false && filename.endsWith(".AppImage") == false) { // Now we have a directory that is not an .app bundle nor an .AppDir // Shall we descend into it? Only if it contains at least one application, to optimize for speed // by not descending into directory trees that do not contain any applications at all. Can make // a big difference. - QStringList nameFilter({"*.app", "*.AppDir", "*.desktop", ".AppImage"}); + QStringList nameFilter({"*.app", "*.AppDir", "*.desktop", "*.AppImage"}); QDir directory(filename); int numberOfAppsInDirectory = directory.entryList(nameFilter).length(); if(numberOfAppsInDirectory > 0) { From 9aef13e5981de29c073f3550f1960288c98afa4e Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 14 Mar 2021 19:26:52 -0400 Subject: [PATCH 08/10] Detect newer version if more than one file Detects new version if more than one file exists --- .gitignore | 5 +- CMakeLists.txt | 2 + src/main.cpp | 144 ++++++++++++------------------------------- src/utils/finder.cpp | 123 ++++++++++++++++++++++++++++++++++++ src/utils/finder.h | 13 ++++ 5 files changed, 182 insertions(+), 105 deletions(-) create mode 100644 src/utils/finder.cpp create mode 100644 src/utils/finder.h diff --git a/.gitignore b/.gitignore index b61296e..9b6fe97 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,7 @@ compile_commands.json *creator.user* # ignore build directory -build \ No newline at end of file +build +.kdev4/ + +launch.kdev4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 41dcab3..651e179 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ find_package(Qt5 COMPONENTS Widgets REQUIRED) add_executable(launch src/main.cpp + src/utils/finder.h + src/utils//finder.cpp ) target_link_libraries(launch PRIVATE Qt5::Widgets) diff --git a/src/main.cpp b/src/main.cpp index 22ef52b..e6f70b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include "utils/finder.h" /* * This tool handles four types of applications: @@ -126,68 +128,6 @@ void handleError(QDetachableProcess *p, QString errorString){ } } - -QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList candidates, QString firstArg) -{ - foreach (QString directory, locationsContainingApps) { - QDirIterator it(directory, QDirIterator::NoIteratorFlags); - while (it.hasNext()) { - QString filename = it.next(); - // qDebug() << "probono: Processing" << filename; - QString nameWithoutSuffix = QFileInfo(QDir(filename).canonicalPath()).baseName(); - QFileInfo file(filename); - if (file.fileName() == firstArg + ".app"){ - QString AppCand = filename + "/" + nameWithoutSuffix; - qDebug() << "################### Checking" << AppCand; - if(QFileInfo(AppCand).exists() == true){ - qDebug() << "# Found" << AppCand; - candidates.append(AppCand); - } - } - else if (file.fileName() == firstArg + ".AppDir"){ - QString AppCand = filename + "/" + "AppRun"; - qDebug() << "################### Checking" << AppCand; - if(QFileInfo(AppCand).exists() == true){ - qDebug() << "# Found" << AppCand; - candidates.append(AppCand); - } - } - else if (file.fileName() == firstArg + ".AppImage") { - QString AppCand = filename; - candidates.append(AppCand); - } - else if (file.fileName() == firstArg + ".desktop") { - // load the .desktop file for parsing - QSettings::IniFormat returns values as strings by default - // see https://doc.qt.io/qt-5/qsettings.html - QSettings desktopFile(filename, QSettings::IniFormat); - QString AppCand = desktopFile.value("Desktop Entry/Exec").toString(); - - // null safety check - if (AppCand != NULL) { - qDebug() << "# Found" << AppCand; - candidates.append(AppCand); - } - qDebug() << "# Found" << file.fileName() << "TODO: Parse it for Exec="; - } - else if (locationsContainingApps.contains(filename) == false && file.isDir() && filename.endsWith("/..") == false && filename.endsWith("/.") == false && filename.endsWith(".app") == false && filename.endsWith(".AppDir") == false && filename.endsWith(".AppImage") == false) { - // Now we have a directory that is not an .app bundle nor an .AppDir - // Shall we descend into it? Only if it contains at least one application, to optimize for speed - // by not descending into directory trees that do not contain any applications at all. Can make - // a big difference. - QStringList nameFilter({"*.app", "*.AppDir", "*.desktop", "*.AppImage"}); - QDir directory(filename); - int numberOfAppsInDirectory = directory.entryList(nameFilter).length(); - if(numberOfAppsInDirectory > 0) { - qDebug() << "# Descending into" << filename; - QStringList locationsToBeChecked = {filename}; - candidates = findAppsInside(locationsToBeChecked, candidates, firstArg); - } - } - } - } - return candidates; -} - int main(int argc, char *argv[]) { @@ -238,7 +178,8 @@ int main(int argc, char *argv[]) } QDetachableProcess p; - + Finder finder; + // Check whether the first argument exists or is on the $PATH QString executable = nullptr; @@ -247,39 +188,11 @@ int main(int argc, char *argv[]) // First, try to find something we can launch at the path, // either an executable or an .AppDir or an .app bundle firstArg = args.first(); - if (QFile::exists(firstArg)){ - QFileInfo info = QFileInfo(firstArg); - if ( firstArg.endsWith(".AppDir") || firstArg.endsWith(".app") || firstArg.endsWith(".AppImage") ){ - qDebug() << "# Found" << firstArg; - QString candidate; - if(firstArg.endsWith(".AppDir")) { - candidate = firstArg + "/AppRun"; - } - else if (firstArg.endsWith(".AppImage")) { - // this is a .AppImage file, we have nothing else to do here, so just make it a candidate - candidate = firstArg; - } - else { - // The .app could be a symlink, so we need to determine the nameWithoutSuffix from its target - QFileInfo fileInfo = QFileInfo(QDir(firstArg).canonicalPath()); - QString nameWithoutSuffix = QFileInfo(fileInfo.completeBaseName()).fileName(); - candidate = firstArg + "/" + nameWithoutSuffix; - } - - QFileInfo candinfo = QFileInfo(candidate); - if(candinfo.isExecutable()) { - executable = candidate; - } - - } - else if (info.isExecutable()){ - qDebug() << "# Found executable" << firstArg; - executable = args.first(); - } - } - + + executable = finder.getExecutable(firstArg); + // Second, try to find an executable file on the $PATH - if(executable == nullptr){ + if(executable == nullptr) { QString candidate = QStandardPaths::findExecutable(firstArg); if (candidate != "") { qDebug() << "Found" << candidate << "on the $PATH"; @@ -306,19 +219,42 @@ int main(int argc, char *argv[]) QFileInfoList candidates; QString firstArgWithoutWellKnownSuffix = firstArg.replace(".AppDir", "").replace(".app", "").replace(".desktop" ,"").replace(".AppImage", ""); - candidates = findAppsInside(locationsContainingApps, candidates, firstArgWithoutWellKnownSuffix); + candidates = finder.findAppsInside(locationsContainingApps, candidates, firstArgWithoutWellKnownSuffix); qDebug() << "Took" << timer.elapsed() << "milliseconds to find candidates via the filesystem"; qDebug() << "Candidates:" << candidates; - - foreach (QFileInfo candidate, candidates) { - // Now that we may have collected different candidates, decide on which one to use - // e.g., the one with the highest self-declared version number. Again, a database might come in handy here - // For now, just use the first one - qDebug() << "Selected candidate:" << candidate.absoluteFilePath(); - executable = candidate.absoluteFilePath(); - break; + + QFileInfo candidate; + QFileInfoList::iterator it; + + // Attempt version detection + if (candidates.size() > 1) { + + // todo: loop through and compare versions + candidate = candidates.first().absoluteFilePath(); + for (int i = 0; i < candidates.size(); i++) + { + QStringList previousVersion = candidate.fileName().split("-"); + QStringList curVersion = candidates[i].fileName().split("-"); + + QVersionNumber previousVer = QVersionNumber::fromString(previousVersion[1]); + QVersionNumber newVer = QVersionNumber::fromString(curVersion[1]); + + int compare = QVersionNumber::compare(previousVer, newVer); + qDebug() << compare; + if (compare == -1) { + // previous one is older, use newer one + candidate = candidates[i].absoluteFilePath(); + } + } + + } else { + candidate = candidates.first().absoluteFilePath(); } + + qDebug() << "Selected candidate:" << candidate.absoluteFilePath(); + executable = candidate.absoluteFilePath(); + } p.setProgram(executable); diff --git a/src/utils/finder.cpp b/src/utils/finder.cpp new file mode 100644 index 0000000..760d010 --- /dev/null +++ b/src/utils/finder.cpp @@ -0,0 +1,123 @@ +#include "finder.h" + +#include +#include +#include +#include +#include +#include + +QFileInfoList Finder::findAppsInside(QStringList locationsContainingApps, QFileInfoList candidates, QString firstArg) +{ + foreach (QString directory, locationsContainingApps) { + QDirIterator it(directory, QDirIterator::NoIteratorFlags); + while (it.hasNext()) { + QString filename = it.next(); + // qDebug() << "probono: Processing" << filename; + QString nameWithoutSuffix = QFileInfo(QDir(filename).canonicalPath()).baseName(); + QFileInfo file(filename); + + if (file.fileName() == firstArg + ".app"){ + QString AppCand = filename + "/" + nameWithoutSuffix; + qDebug() << "################### Checking" << AppCand; + if(QFileInfo(AppCand).exists() == true){ + qDebug() << "# Found" << AppCand; + candidates.append(AppCand); + } + } + else if (file.fileName() == firstArg + ".AppDir"){ + QString AppCand = filename + "/" + "AppRun"; + + qDebug() << "################### Checking" << AppCand; + if(QFileInfo(AppCand).exists() == true){ + qDebug() << "# Found" << AppCand; + candidates.append(AppCand); + } + } + else if (file.fileName() == firstArg + ".AppImage" || file.fileName() == firstArg.replace(" ", "_") + ".AppImage" || file.fileName().endsWith(".AppName") & file.fileName().startsWith(firstArg + "-") || file.fileName().startsWith(firstArg.replace(" ", "_") + "-")) { + QString AppCand = getExecutable(filename); + candidates.append(AppCand); + } + else if (file.fileName() == firstArg + ".desktop") { + // load the .desktop file for parsing - QSettings::IniFormat returns values as strings by default + // see https://doc.qt.io/qt-5/qsettings.html + QSettings desktopFile(filename, QSettings::IniFormat); + QString AppCand = desktopFile.value("Desktop Entry/Exec").toString(); + + // null safety check + if (AppCand != NULL) { + qDebug() << "# Found" << AppCand; + candidates.append(AppCand); + } + } + else if (locationsContainingApps.contains(filename) == false && file.isDir() && filename.endsWith("/..") == false && filename.endsWith("/.") == false && filename.endsWith(".app") == false && filename.endsWith(".AppDir") == false && filename.endsWith(".AppImage") == false) { + // Now we have a directory that is not an .app bundle nor an .AppDir + // Shall we descend into it? Only if it contains at least one application, to optimize for speed + // by not descending into directory trees that do not contain any applications at all. Can make + // a big difference. + QStringList nameFilter({"*.app", "*.AppDir", "*.desktop", "*.AppImage"}); + QDir directory(filename); + int numberOfAppsInDirectory = directory.entryList(nameFilter).length(); + if(numberOfAppsInDirectory > 0) { + qDebug() << "# Descending into" << filename; + QStringList locationsToBeChecked = {filename}; + candidates = findAppsInside(locationsToBeChecked, candidates, firstArg); + } + } + } + } + return candidates; +} + +QString Finder::getExecutable(QString &firstArg) +{ + + QString executable = nullptr; + + // check if the file exists + /*if (!QFile::exists(firstArg)) { + // try replacing space with _ + firstArg = firstArg.replace(" ", "_"); + }*/ + + if (QFile::exists(firstArg)) { + // get the file info + QFileInfo info = QFileInfo(firstArg); + + if (firstArg.endsWith(".AppDir") || firstArg.endsWith(".app") || firstArg.endsWith(".AppImage")) { + qDebug() << "# Found" << firstArg; + + // The potential candidate + QString candidate; + + if(firstArg.endsWith(".AppDir")) { + candidate = firstArg + "/AppRun"; + } + else if (firstArg.endsWith(".AppImage")) { + // this is a .AppImage file, we have nothing else to do here, so just make it a candidate + candidate = firstArg; + } + else { + // The .app could be a symlink, so we need to determine the nameWithoutSuffix from its target + QFileInfo fileInfo = QFileInfo(QDir(firstArg).canonicalPath()); + QString nameWithoutSuffix = QFileInfo(fileInfo.completeBaseName()).fileName(); + candidate = firstArg + "/" + nameWithoutSuffix; + } + + QFileInfo candinfo = QFileInfo(candidate); + if (candinfo.isExecutable()) { + executable = candidate; + } + + } + else if (info.isExecutable()){ + qDebug() << "# Found executable" << firstArg; + executable = firstArg; + } + } + + return executable; +} + + + diff --git a/src/utils/finder.h b/src/utils/finder.h new file mode 100644 index 0000000..e04ec8d --- /dev/null +++ b/src/utils/finder.h @@ -0,0 +1,13 @@ +#ifndef FINDER_H +#define FINDER_H + +#include + +class Finder +{ +public: + QFileInfoList findAppsInside(QStringList locationsContainingApps, QFileInfoList candidates, QString firstArg); + QString getExecutable(QString &firstArg); +}; + +#endif From 371d3a5bd1155c2eb4646f83c06450ac36717891 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 2 Apr 2021 14:31:40 -0400 Subject: [PATCH 09/10] resolves issue with not being able to compare versions --- src/main.cpp | 40 ++++++++++++++++++++++++---------------- src/utils/finder.cpp | 10 ++++++---- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e6f70b9..2cdbeda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -224,37 +224,45 @@ int main(int argc, char *argv[]) qDebug() << "Took" << timer.elapsed() << "milliseconds to find candidates via the filesystem"; qDebug() << "Candidates:" << candidates; - QFileInfo candidate; + QFileInfo candidate = candidates.first().absoluteFilePath(); QFileInfoList::iterator it; + qDebug() << candidate; + // Attempt version detection if (candidates.size() > 1) { // todo: loop through and compare versions - candidate = candidates.first().absoluteFilePath(); + for (int i = 0; i < candidates.size(); i++) { - QStringList previousVersion = candidate.fileName().split("-"); - QStringList curVersion = candidates[i].fileName().split("-"); + if (!candidate.fileName().contains("-")) { + candidate = candidates[i].absoluteFilePath(); + continue; + } + + try { + QStringList previousVersion = candidate.fileName().split("-"); + QStringList curVersion = candidates[i].fileName().split("-"); - QVersionNumber previousVer = QVersionNumber::fromString(previousVersion[1]); - QVersionNumber newVer = QVersionNumber::fromString(curVersion[1]); + QVersionNumber previousVer = QVersionNumber::fromString(previousVersion[1]); + QVersionNumber newVer = QVersionNumber::fromString(curVersion[1]); - int compare = QVersionNumber::compare(previousVer, newVer); - qDebug() << compare; - if (compare == -1) { - // previous one is older, use newer one - candidate = candidates[i].absoluteFilePath(); + int compare = QVersionNumber::compare(previousVer, newVer); + qDebug() << compare; + if (compare == -1) { + // previous one is older, use newer one + candidate = candidates[i].absoluteFilePath(); + } + } catch(std::exception &e) { + // catch any exeption that may occure + qDebug() << "Failed to compare application versions"; } } - - } else { - candidate = candidates.first().absoluteFilePath(); - } + } qDebug() << "Selected candidate:" << candidate.absoluteFilePath(); executable = candidate.absoluteFilePath(); - } p.setProgram(executable); diff --git a/src/utils/finder.cpp b/src/utils/finder.cpp index 760d010..32f7908 100644 --- a/src/utils/finder.cpp +++ b/src/utils/finder.cpp @@ -16,8 +16,9 @@ QFileInfoList Finder::findAppsInside(QStringList locationsContainingApps, QFileI // qDebug() << "probono: Processing" << filename; QString nameWithoutSuffix = QFileInfo(QDir(filename).canonicalPath()).baseName(); QFileInfo file(filename); - - if (file.fileName() == firstArg + ".app"){ + + if (file.fileName() == firstArg + ".app") { + qDebug() << filename; QString AppCand = filename + "/" + nameWithoutSuffix; qDebug() << "################### Checking" << AppCand; if(QFileInfo(AppCand).exists() == true){ @@ -25,7 +26,7 @@ QFileInfoList Finder::findAppsInside(QStringList locationsContainingApps, QFileI candidates.append(AppCand); } } - else if (file.fileName() == firstArg + ".AppDir"){ + else if (file.fileName() == firstArg + ".AppDir") { QString AppCand = filename + "/" + "AppRun"; qDebug() << "################### Checking" << AppCand; @@ -34,7 +35,7 @@ QFileInfoList Finder::findAppsInside(QStringList locationsContainingApps, QFileI candidates.append(AppCand); } } - else if (file.fileName() == firstArg + ".AppImage" || file.fileName() == firstArg.replace(" ", "_") + ".AppImage" || file.fileName().endsWith(".AppName") & file.fileName().startsWith(firstArg + "-") || file.fileName().startsWith(firstArg.replace(" ", "_") + "-")) { + else if (file.fileName().endsWith(".AppImage") && (file.fileName().contains(firstArg) || file.fileName().contains(firstArg.replace(" ", "_")))) { QString AppCand = getExecutable(filename); candidates.append(AppCand); } @@ -66,6 +67,7 @@ QFileInfoList Finder::findAppsInside(QStringList locationsContainingApps, QFileI } } } + return candidates; } From 325d0e3deb27e508d091f5c8d968bf4d9fb277cb Mon Sep 17 00:00:00 2001 From: Eric Hocking Date: Mon, 19 Apr 2021 14:21:08 +0000 Subject: [PATCH 10/10] fixes finding .AppImage files --- src/utils/finder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/finder.cpp b/src/utils/finder.cpp index 32f7908..349b27a 100644 --- a/src/utils/finder.cpp +++ b/src/utils/finder.cpp @@ -35,7 +35,7 @@ QFileInfoList Finder::findAppsInside(QStringList locationsContainingApps, QFileI candidates.append(AppCand); } } - else if (file.fileName().endsWith(".AppImage") && (file.fileName().contains(firstArg) || file.fileName().contains(firstArg.replace(" ", "_")))) { + else if (file.fileName() == firstArg + ".AppImage" || file.fileName() == firstArg.replace(" ", "_") + ".AppImage" || file.fileName().endsWith(".AppName") & file.fileName().startsWith(firstArg + "-") || file.fileName().startsWith(firstArg.replace(" ", "_") + "-")) { QString AppCand = getExecutable(filename); candidates.append(AppCand); }