mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-16 17:20:30 +02:00
55 lines
1.8 KiB
C++
55 lines
1.8 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 "PathUtils.h"
|
|
|
|
|
|
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) {
|
|
foreach (const QString possibleExtension, possibleExtensions) {
|
|
if (fileName.endsWith(possibleExtension) ||
|
|
fileName.endsWith(possibleExtension.toUpper()) ||
|
|
fileName.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;
|
|
}
|