mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 08:15:21 +02:00
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
//
|
|
// 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 <QCoreApplication>
|
|
#include <QString>
|
|
#include <QVector>
|
|
#include <QDateTime>
|
|
#include <QFileInfo>
|
|
#include <QDir>
|
|
#include <QUrl>
|
|
#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<QString> 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<QString> 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
|
|
}
|