// // PathUtils.cpp // libraries/shared/src // // Created by Brad Hefta-Gaub on 12/15/14. // Copyright 2014 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include #include #include #include #include #include #include #include "PathUtils.h" const QString& PathUtils::resourcesPath() { #ifdef Q_OS_MAC static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/"; #else static QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/"; #endif return staticResourcePath; } QString fileNameWithoutExtension(const QString& fileName, const QVector possibleExtensions) { QString fileNameLowered = fileName.toLower(); foreach (const QString possibleExtension, possibleExtensions) { if (fileNameLowered.endsWith(possibleExtension.toLower())) { return fileName.left(fileName.count() - possibleExtension.count() - 1); } } return fileName; } QString findMostRecentFileExtension(const QString& originalFileName, QVector possibleExtensions) { QString sansExt = fileNameWithoutExtension(originalFileName, possibleExtensions); QString newestFileName = originalFileName; QDateTime newestTime = QDateTime::fromMSecsSinceEpoch(0); foreach (QString possibleExtension, possibleExtensions) { QString fileName = sansExt + "." + possibleExtension; QFileInfo fileInfo(fileName); if (fileInfo.exists() && fileInfo.lastModified() > newestTime) { newestFileName = fileName; newestTime = fileInfo.lastModified(); } } return newestFileName; } QUrl defaultScriptsLocation() { #ifdef Q_OS_WIN return QUrl(("file:///" + QCoreApplication::applicationDirPath()).toLower() + "/scripts"); #elif defined(Q_OS_OSX) return QUrl(("file://" + QCoreApplication::applicationDirPath() + "/../Resources/scripts").toLower()); #else // return "http://s3.amazonaws.com/hifi-public"; return QUrl("file://" + QCoreApplication::applicationDirPath() + "/scripts"); #endif }