diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-09-30 22:52:55 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-09-30 22:52:55 +0200 |
commit | 477a1a88c6b7f5e5a78a2bbc4a6fe7781b2a0525 (patch) | |
tree | 8afd9d2359717b77c9c842b27598543af9069471 /depends/util | |
parent | cf0308c970aba7e282e4e98782187bc636f8ce26 (diff) | |
download | MultiMC-477a1a88c6b7f5e5a78a2bbc4a6fe7781b2a0525.tar MultiMC-477a1a88c6b7f5e5a78a2bbc4a6fe7781b2a0525.tar.gz MultiMC-477a1a88c6b7f5e5a78a2bbc4a6fe7781b2a0525.tar.lz MultiMC-477a1a88c6b7f5e5a78a2bbc4a6fe7781b2a0525.tar.xz MultiMC-477a1a88c6b7f5e5a78a2bbc4a6fe7781b2a0525.zip |
GH-1262 fix relative paths for java binaries
Diffstat (limited to 'depends/util')
-rw-r--r-- | depends/util/include/pathutils.h | 14 | ||||
-rw-r--r-- | depends/util/src/pathutils.cpp | 18 |
2 files changed, 31 insertions, 1 deletions
diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h index 6d52097f..ff23fa5d 100644 --- a/depends/util/include/pathutils.h +++ b/depends/util/include/pathutils.h @@ -26,6 +26,18 @@ MULTIMC_UTIL_EXPORT QString PathCombine(QString path1, QString path2, QString pa MULTIMC_UTIL_EXPORT QString AbsolutePath(QString path); /** + * Resolve an executable + * + * Will resolve: + * single executable (by name) + * relative path + * absolute path + * + * @return absolute path to executable or null string + */ +MULTIMC_UTIL_EXPORT QString ResolveExecutable(QString path); + +/** * Normalize path * * Any paths inside the current directory will be normalized to relative paths (to current) @@ -33,7 +45,7 @@ MULTIMC_UTIL_EXPORT QString AbsolutePath(QString path); * * Returns false if the path logic somehow filed (and normalizedPath in invalid) */ -QString NormalizePath(QString path); +MULTIMC_UTIL_EXPORT QString NormalizePath(QString path); MULTIMC_UTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-'); diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp index 35c7f901..af1843ba 100644 --- a/depends/util/src/pathutils.cpp +++ b/depends/util/src/pathutils.cpp @@ -40,6 +40,24 @@ QString AbsolutePath(QString path) return QFileInfo(path).absolutePath(); } +QString ResolveExecutable(QString path) +{ + if (path.isEmpty()) + { + return QString(); + } + if(!path.contains('/')) + { + path = QStandardPaths::findExecutable(path); + } + QFileInfo pathInfo(path); + if(!pathInfo.exists() || !pathInfo.isExecutable()) + { + return QString(); + } + return pathInfo.absoluteFilePath(); +} + /** * Normalize path * |