Use the Path class to lookup ModeSeven.ttf

This commit is contained in:
Cameron Gutman 2019-02-15 18:13:36 -08:00
parent f8e693a060
commit b1799009b3
4 changed files with 19 additions and 11 deletions

View file

@ -8,7 +8,6 @@
QString Path::s_LogDir;
QString Path::s_BoxArtCacheDir;
const QString Path::k_GameControllerMappingFile("gamecontrollerdb.txt");
QString Path::getLogDir()
{
@ -22,24 +21,24 @@ QString Path::getBoxArtCacheDir()
return s_BoxArtCacheDir;
}
QString Path::getGamepadMappingFile()
QString Path::getDataFilePath(QString fileName)
{
QString candidatePath;
// Check the current directory first
candidatePath = QDir(QDir::currentPath()).absoluteFilePath(k_GameControllerMappingFile);
candidatePath = QDir(QDir::currentPath()).absoluteFilePath(fileName);
if (QFile::exists(candidatePath)) {
return candidatePath;
}
// Now check the data directories (for Linux, in particular)
candidatePath = QStandardPaths::locate(QStandardPaths::DataLocation, k_GameControllerMappingFile);
candidatePath = QStandardPaths::locate(QStandardPaths::DataLocation, fileName);
if (!candidatePath.isEmpty() && QFile::exists(candidatePath)) {
return candidatePath;
}
// Now try the directory of our app installation (for Windows, if current dir doesn't find it)
candidatePath = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(k_GameControllerMappingFile);
candidatePath = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(fileName);
if (QFile::exists(candidatePath)) {
return candidatePath;
}
@ -48,8 +47,8 @@ QString Path::getGamepadMappingFile()
QDir dir = QDir(QCoreApplication::applicationDirPath());
dir.cdUp();
dir.cd("Resources");
dir.filePath(k_GameControllerMappingFile);
candidatePath = dir.absoluteFilePath(k_GameControllerMappingFile);
dir.filePath(fileName);
candidatePath = dir.absoluteFilePath(fileName);
if (QFile::exists(candidatePath)) {
return candidatePath;
}

View file

@ -9,12 +9,11 @@ public:
static QString getBoxArtCacheDir();
static QString getGamepadMappingFile();
static QString getDataFilePath(QString fileName);
static void initialize(bool portable);
private:
static QString s_LogDir;
static QString s_BoxArtCacheDir;
static const QString k_GameControllerMappingFile;
};

View file

@ -54,7 +54,7 @@ void MappingManager::save()
void MappingManager::applyMappings()
{
QString mappingFile = Path::getGamepadMappingFile();
QString mappingFile = Path::getDataFilePath("gamecontrollerdb.txt");
if (!mappingFile.isEmpty()) {
std::string mappingFileNative = QDir::toNativeSeparators(mappingFile).toStdString();

View file

@ -1,6 +1,9 @@
#include "sdlvid.h"
#include "streaming/session.h"
#include "path.h"
#include <QDir>
#include <Limelight.h>
@ -78,7 +81,14 @@ void SdlRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
{
if (type == Overlay::OverlayDebug) {
if (m_DebugOverlayFont == nullptr) {
m_DebugOverlayFont = TTF_OpenFont("ModeSeven.ttf",
QByteArray fontPath = QDir::toNativeSeparators(Path::getDataFilePath("ModeSeven.ttf")).toUtf8();
if (fontPath.isEmpty()) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to locate SDL overlay font");
return;
}
m_DebugOverlayFont = TTF_OpenFont(fontPath.data(),
Session::get()->getOverlayManager().getOverlayFontSize(Overlay::OverlayDebug));
if (m_DebugOverlayFont == nullptr) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,