diff --git a/app/app.pro b/app/app.pro
index 4173f2a2..85d231f6 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -302,18 +302,6 @@ DEPENDPATH += $$PWD/../h264bitstream/h264bitstream
DEPENDPATH += $$PWD/../AntiHooking
}
-defineTest(copyToDestDir) {
- files = $$1
-
- for(FILE, files) {
- !equals(PWD, $$OUT_PWD) {
- QMAKE_POST_LINK += $$QMAKE_COPY $$shell_quote($$shell_path($$PWD/$$FILE)) $$shell_quote($$shell_path($$OUT_PWD)) $$escape_expand(\\n\\t)
- }
- }
-
- export(QMAKE_POST_LINK)
-}
-
unix:!macx: {
isEmpty(PREFIX) {
PREFIX = /usr/local
@@ -339,12 +327,6 @@ unix:!macx: {
appdata.files = SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf
appdata.path = "$$PREFIX/$$DATADIR/Moonlight Game Streaming Project/Moonlight/"
- CONFIG(debug, debug|release) {
- # Copy the required data files into the application directory only for debug builds.
- # Release builds will use the INSTALLS variable to place these in the correct folders.
- copyToDestDir(SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf)
- }
-
INSTALLS += target appdata desktop icons appstream
}
win32 {
@@ -353,9 +335,6 @@ win32 {
QMAKE_TARGET_DESCRIPTION = Moonlight Game Streaming Client
QMAKE_TARGET_PRODUCT = Moonlight
- # Copy the required data files into the application directory
- copyToDestDir(SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf)
-
CONFIG -= embed_manifest_exe
QMAKE_LFLAGS += /MANIFEST:embed /MANIFESTINPUT:$${PWD}/Moonlight.exe.manifest
}
@@ -366,7 +345,7 @@ macx {
QMAKE_INFO_PLIST = $$OUT_PWD/Info.plist
- APP_BUNDLE_RESOURCES.files = moonlight.icns SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf
+ APP_BUNDLE_RESOURCES.files = moonlight.icns
APP_BUNDLE_RESOURCES.path = Contents/Resources
APP_BUNDLE_FRAMEWORKS.files = $$files(../libs/mac/Frameworks/*.framework, true)
diff --git a/app/path.cpp b/app/path.cpp
index 71502961..69d9a4b1 100644
--- a/app/path.cpp
+++ b/app/path.cpp
@@ -21,6 +21,13 @@ QString Path::getBoxArtCacheDir()
return s_BoxArtCacheDir;
}
+QByteArray Path::readDataFile(QString fileName)
+{
+ QFile dataFile(getDataFilePath(fileName));
+ dataFile.open(QIODevice::ReadOnly);
+ return dataFile.readAll();
+}
+
QString Path::getDataFilePath(QString fileName)
{
QString candidatePath;
@@ -28,33 +35,28 @@ QString Path::getDataFilePath(QString fileName)
// Check the current directory first
candidatePath = QDir(QDir::currentPath()).absoluteFilePath(fileName);
if (QFile::exists(candidatePath)) {
+ qInfo() << "Found" << fileName << "at" << candidatePath;
return candidatePath;
}
// Now check the data directories (for Linux, in particular)
candidatePath = QStandardPaths::locate(QStandardPaths::DataLocation, fileName);
if (!candidatePath.isEmpty() && QFile::exists(candidatePath)) {
+ qInfo() << "Found" << fileName << "at" << 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(fileName);
if (QFile::exists(candidatePath)) {
+ qInfo() << "Found" << fileName << "at" << candidatePath;
return candidatePath;
}
- // Now try the Resources folder in our app bundle for macOS
- QDir dir = QDir(QCoreApplication::applicationDirPath());
- dir.cdUp();
- dir.cd("Resources");
- dir.filePath(fileName);
- candidatePath = dir.absoluteFilePath(fileName);
- if (QFile::exists(candidatePath)) {
- return candidatePath;
- }
-
- // Couldn't find it
- return QString();
+ // Return the QRC embedded copy
+ candidatePath = ":/data/" + fileName;
+ qInfo() << "Found" << fileName << "at" << candidatePath;
+ return QString(candidatePath);
}
void Path::initialize(bool portable)
diff --git a/app/path.h b/app/path.h
index ab17e720..cb4aa90e 100644
--- a/app/path.h
+++ b/app/path.h
@@ -9,6 +9,9 @@ public:
static QString getBoxArtCacheDir();
+ static QByteArray readDataFile(QString fileName);
+
+ // Only safe to use directly for Qt classes
static QString getDataFilePath(QString fileName);
static void initialize(bool portable);
diff --git a/app/resources.qrc b/app/resources.qrc
index f57cb7ed..31c1cfae 100644
--- a/app/resources.qrc
+++ b/app/resources.qrc
@@ -16,4 +16,8 @@
res/moonlight.svg
res/update.svg
+
+ SDL_GameControllerDB/gamecontrollerdb.txt
+ ModeSeven.ttf
+
diff --git a/app/settings/mappingmanager.cpp b/app/settings/mappingmanager.cpp
index 0fc2efee..8aed4f2d 100644
--- a/app/settings/mappingmanager.cpp
+++ b/app/settings/mappingmanager.cpp
@@ -54,15 +54,10 @@ void MappingManager::save()
void MappingManager::applyMappings()
{
- QString mappingFile = Path::getDataFilePath("gamecontrollerdb.txt");
- if (!mappingFile.isEmpty()) {
- std::string mappingFileNative = QDir::toNativeSeparators(mappingFile).toStdString();
-
- SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
- "Loading gamepad mappings from: %s",
- mappingFileNative.c_str());
-
- int newMappings = SDL_GameControllerAddMappingsFromFile(mappingFileNative.c_str());
+ QByteArray mappingData = Path::readDataFile("gamecontrollerdb.txt");
+ if (!mappingData.isEmpty()) {
+ int newMappings = SDL_GameControllerAddMappingsFromRW(
+ SDL_RWFromConstMem(mappingData.constData(), mappingData.size()), 1);
if (newMappings < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Error loading gamepad mappings: %s",
@@ -75,8 +70,8 @@ void MappingManager::applyMappings()
}
}
else {
- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
- "No gamepad mapping file found");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Unable to load gamepad mapping file");
}
QList mappings = m_Mappings.values();
diff --git a/app/streaming/video/ffmpeg-renderers/sdlvid.cpp b/app/streaming/video/ffmpeg-renderers/sdlvid.cpp
index 458f1104..885a53fd 100644
--- a/app/streaming/video/ffmpeg-renderers/sdlvid.cpp
+++ b/app/streaming/video/ffmpeg-renderers/sdlvid.cpp
@@ -88,15 +88,16 @@ void SdlRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
{
// Construct the required font to render the overlay
if (m_OverlayFonts[type] == nullptr) {
- QByteArray fontPath = QDir::toNativeSeparators(Path::getDataFilePath("ModeSeven.ttf")).toUtf8();
- if (fontPath.isEmpty()) {
- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
- "Unable to locate SDL overlay font");
+ QByteArray fontData = Path::readDataFile("ModeSeven.ttf");
+ if (fontData.isEmpty()) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+ "Unable to load SDL overlay font");
return;
}
- m_OverlayFonts[type] = TTF_OpenFont(fontPath.data(),
- Session::get()->getOverlayManager().getOverlayFontSize(type));
+ m_OverlayFonts[type] = TTF_OpenFontRW(SDL_RWFromConstMem(fontData.constData(), fontData.size()),
+ 1,
+ Session::get()->getOverlayManager().getOverlayFontSize(type));
if (m_OverlayFonts[type] == nullptr) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"TTF_OpenFont() failed: %s",
diff --git a/scripts/generate-installers.bat b/scripts/generate-installers.bat
index a6ef5205..a14793f9 100644
--- a/scripts/generate-installers.bat
+++ b/scripts/generate-installers.bat
@@ -123,10 +123,6 @@ echo Copying GC mapping list
copy %SOURCE_ROOT%\app\SDL_GameControllerDB\gamecontrollerdb.txt %DEPLOY_FOLDER%
if !ERRORLEVEL! NEQ 0 goto Error
-echo Copying SDL overlay font
-copy %SOURCE_ROOT%\app\ModeSeven.ttf %DEPLOY_FOLDER%
-if !ERRORLEVEL! NEQ 0 goto Error
-
echo Deploying Qt dependencies
windeployqt.exe --dir %DEPLOY_FOLDER% --%BUILD_CONFIG% --qmldir %SOURCE_ROOT%\app\gui --no-opengl-sw --no-compiler-runtime %BUILD_FOLDER%\app\%BUILD_CONFIG%\Moonlight.exe
if !ERRORLEVEL! NEQ 0 goto Error